vhost_user: code cleanup
1. Replace the magic number '-1' with MAP_FAILED
2. On x86 platform, QEMU uses vhostuser required the memory back-end is file based,
the file could be tmpfs(4K page size) or hugetlbfs(2M or 1G page size)
Change-Id: If1818cb6833728d641f68e4d4a3bc645e70f2ee6
Signed-off-by: Haiyang Tan <haiyang.tan.dev@gmail.com>
diff --git a/src/vnet/devices/virtio/vhost-user.c b/src/vnet/devices/virtio/vhost-user.c
index 874a97d..9c93ef4 100644
--- a/src/vnet/devices/virtio/vhost-user.c
+++ b/src/vnet/devices/virtio/vhost-user.c
@@ -306,7 +306,7 @@
int i, r;
for (i = 0; i < vui->nregions; i++)
{
- if (vui->region_mmap_addr[i] != (void *) -1)
+ if (vui->region_mmap_addr[i] != MAP_FAILED)
{
long page_sz = get_huge_page_size (vui->region_mmap_fd[i]);
@@ -323,7 +323,7 @@
("unmap memory region %d addr 0x%lx len 0x%lx page_sz 0x%x", i,
vui->region_mmap_addr[i], map_sz, page_sz);
- vui->region_mmap_addr[i] = (void *) -1;
+ vui->region_mmap_addr[i] = MAP_FAILED;
if (r == -1)
{
@@ -829,7 +829,7 @@
long page_sz = get_huge_page_size (fds[i]);
- /* align size to 2M page */
+ /* align size to page */
ssize_t map_sz = (vui->regions[i].memory_size +
vui->regions[i].mmap_offset +
page_sz - 1) & ~(page_sz - 1);
@@ -1076,7 +1076,7 @@
}
fd = fds[0];
- /* align size to 2M page */
+ /* align size to page */
long page_sz = get_huge_page_size (fd);
ssize_t map_sz =
(msg.log.size + msg.log.offset + page_sz - 1) & ~(page_sz - 1);