MCPcopy Create free account
hub / github.com/F-Stack/f-stack / inflight_mem_alloc

Function inflight_mem_alloc

dpdk/lib/vhost/vhost_user.c:1545–1586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1543}
1544
1545static void *
1546inflight_mem_alloc(struct virtio_net *dev, const char *name, size_t size, int *fd)
1547{
1548 void *ptr;
1549 int mfd = -1;
1550 uint64_t alignment;
1551 char fname[20] = "/tmp/memfd-XXXXXX";
1552
1553 *fd = -1;
1554#ifdef MEMFD_SUPPORTED
1555 mfd = memfd_create(name, MFD_CLOEXEC);
1556#else
1557 RTE_SET_USED(name);
1558#endif
1559 if (mfd == -1) {
1560 mfd = mkstemp(fname);
1561 if (mfd == -1) {
1562 VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to get inflight buffer fd\n");
1563 return NULL;
1564 }
1565
1566 unlink(fname);
1567 }
1568
1569 if (ftruncate(mfd, size) == -1) {
1570 VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to alloc inflight buffer\n");
1571 close(mfd);
1572 return NULL;
1573 }
1574
1575 ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);
1576 if (ptr == MAP_FAILED) {
1577 VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to mmap inflight buffer\n");
1578 close(mfd);
1579 return NULL;
1580 }
1581
1582 alignment = get_blk_size(mfd);
1583 mem_set_dump(ptr, size, false, alignment);
1584 *fd = mfd;
1585 return ptr;
1586}
1587
1588static uint32_t
1589get_pervq_shm_size_split(uint16_t queue_size)

Callers 1

Calls 4

memfd_createFunction · 0.85
get_blk_sizeFunction · 0.85
mem_set_dumpFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected