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

Function vhost_user_set_log_base

dpdk/lib/vhost/vhost_user.c:2286–2382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2284}
2285
2286static int
2287vhost_user_set_log_base(struct virtio_net **pdev,
2288 struct vhu_msg_context *ctx,
2289 int main_fd __rte_unused)
2290{
2291 struct virtio_net *dev = *pdev;
2292 int fd = ctx->fds[0];
2293 uint64_t size, off;
2294 uint64_t alignment;
2295 void *addr;
2296 uint32_t i;
2297
2298 if (validate_msg_fds(dev, ctx, 1) != 0)
2299 return RTE_VHOST_MSG_RESULT_ERR;
2300
2301 if (fd < 0) {
2302 VHOST_LOG_CONFIG(dev->ifname, ERR, "invalid log fd: %d\n", fd);
2303 return RTE_VHOST_MSG_RESULT_ERR;
2304 }
2305
2306 if (ctx->msg.size != sizeof(VhostUserLog)) {
2307 VHOST_LOG_CONFIG(dev->ifname, ERR,
2308 "invalid log base msg size: %"PRId32" != %d\n",
2309 ctx->msg.size, (int)sizeof(VhostUserLog));
2310 goto close_msg_fds;
2311 }
2312
2313 size = ctx->msg.payload.log.mmap_size;
2314 off = ctx->msg.payload.log.mmap_offset;
2315
2316 /* Check for mmap size and offset overflow. */
2317 if (off >= -size) {
2318 VHOST_LOG_CONFIG(dev->ifname, ERR,
2319 "log offset %#"PRIx64" and log size %#"PRIx64" overflow\n",
2320 off, size);
2321 goto close_msg_fds;
2322 }
2323
2324 VHOST_LOG_CONFIG(dev->ifname, INFO,
2325 "log mmap size: %"PRId64", offset: %"PRId64"\n",
2326 size, off);
2327
2328 /*
2329 * mmap from 0 to workaround a hugepage mmap bug: mmap will
2330 * fail when offset is not page size aligned.
2331 */
2332 addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off);
2333 alignment = get_blk_size(fd);
2334 close(fd);
2335 if (addr == MAP_FAILED) {
2336 VHOST_LOG_CONFIG(dev->ifname, ERR, "mmap log base failed!\n");
2337 return RTE_VHOST_MSG_RESULT_ERR;
2338 }
2339
2340 /*
2341 * Free previously mapped log memory on occasionally
2342 * multiple VHOST_USER_SET_LOG_BASE.
2343 */

Callers

nothing calls this directly

Calls 7

validate_msg_fdsFunction · 0.85
get_blk_sizeFunction · 0.85
mem_set_dumpFunction · 0.85
rte_freeFunction · 0.85
rte_malloc_socketFunction · 0.85
close_msg_fdsFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected