svm: Use ftruncate to expand svm on FreeBSD

Linux doesn't support the Linux idiom of using lseek and a write to set
the size of a file, instead use ftruncate to accomplish the same effect.

This change is taken from the Nanoteq VPP port commit:
04a1b19b37

Type: improvement
Change-Id: Ie0b83e751b8b8f20b6814e5c9f760035747dfad9
Signed-off-by: Tom Jones <thj@freebsd.org>
This commit is contained in:
Tom Jones
2024-01-31 10:44:14 +00:00
committed by Florin Coras
parent b613d411a4
commit eceef16b5c

View File

@ -551,7 +551,6 @@ svm_map_region (svm_map_region_args_t * a)
int svm_fd;
svm_region_t *rp;
int deadman = 0;
u8 junk = 0;
void *oldheap;
int rv;
int pid_holding_region_lock;
@ -582,6 +581,15 @@ svm_map_region (svm_map_region_args_t * a)
vec_free (shm_name);
#ifdef __FreeBSD__
if (ftruncate (svm_fd, a->size) < 0)
{
clib_warning ("ftruncate region size");
close (svm_fd);
return (0);
}
#else
u8 junk = 0;
if (lseek (svm_fd, a->size, SEEK_SET) == (off_t) - 1)
{
clib_warning ("seek region size");
@ -594,6 +602,7 @@ svm_map_region (svm_map_region_args_t * a)
close (svm_fd);
return (0);
}
#endif /* __FreeBSD__ */
rp = mmap (uword_to_pointer (a->baseva, void *), a->size,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, svm_fd, 0);