diff options
author | swapnili <swapnil.ingle@nutanix.com> | 2020-11-30 16:45:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 16:45:35 +0100 |
commit | 9d0224ae1c4c6c43e7dee048b71a499c857bc85f (patch) | |
tree | af82f3c83a6ca80da30fc8d18274f7a178d61a26 /samples/server.c | |
parent | a3ba81765daeffaaa2e9e59d49d49ae4438b1b59 (diff) | |
download | libvfio-user-9d0224ae1c4c6c43e7dee048b71a499c857bc85f.zip libvfio-user-9d0224ae1c4c6c43e7dee048b71a499c857bc85f.tar.gz libvfio-user-9d0224ae1c4c6c43e7dee048b71a499c857bc85f.tar.bz2 |
Update API's to accept sparse mmap areas as array and its count (#134)
* Pass region mmap areas as array
* Pass migration sparse mmap areas as array
* Move struct vfu_sparse_mmap_areas to lib/priv.h
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'samples/server.c')
-rw-r--r-- | samples/server.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/samples/server.c b/samples/server.c index dd84f16..7f9eefa 100644 --- a/samples/server.c +++ b/samples/server.c @@ -380,8 +380,6 @@ int main(int argc, char *argv[]) .state = VFU_MIGR_STATE_RUNNING } }; - int nr_sparse_areas = 2, size = 1024, i; - struct vfu_sparse_mmap_areas *sparse_areas; vfu_ctx_t *vfu_ctx; vfu_pci_hdr_id_t id = {.raw = 0xdeadbeef}; vfu_pci_hdr_ss_t ss = {.raw = 0xcafebabe}; @@ -407,16 +405,6 @@ int main(int argc, char *argv[]) err(EXIT_FAILURE, "BAR1"); } - sparse_areas = calloc(1, sizeof(*sparse_areas) + - (nr_sparse_areas * sizeof(struct vfu_mmap_area))); - if (sparse_areas == NULL) { - err(EXIT_FAILURE, "MMAP sparse areas ENOMEM"); - } - sparse_areas->nr_mmap_areas = nr_sparse_areas; - for (i = 0; i < nr_sparse_areas; i++) { - sparse_areas->areas[i].start += size; - sparse_areas->areas[i].size = size; - } sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, NULL) == -1) { err(EXIT_FAILURE, "failed to register signal handler"); @@ -439,14 +427,18 @@ int main(int argc, char *argv[]) } ret = vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX, sizeof(time_t), - &bar0_access, VFU_REG_FLAG_RW, NULL, NULL); + &bar0_access, VFU_REG_FLAG_RW, NULL, 0, NULL); if (ret < 0) { err(EXIT_FAILURE, "failed to setup BAR0 region"); } + struct vfu_mmap_area mmap_areas[] = { + { .start = 1024, .size = 1024 }, + { .start = 8192, .size = 1024 } + }; ret = vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR1_REGION_IDX, sysconf(_SC_PAGESIZE), &bar1_access, - VFU_REG_FLAG_RW, sparse_areas, map_area); + VFU_REG_FLAG_RW, mmap_areas, 2, map_area); if (ret < 0) { err(EXIT_FAILURE, "failed to setup BAR1 region"); } @@ -468,7 +460,8 @@ int main(int argc, char *argv[]) vfu_migration_t migration = { .size = server_data.migration.migr_data_len, - .mmap_areas = sparse_areas, + .mmap_areas = mmap_areas, + .nr_mmap_areas = 2, .callbacks = { .transition = &migration_device_state_transition, .get_pending_bytes = &migration_get_pending_bytes, @@ -515,7 +508,6 @@ int main(int argc, char *argv[]) vfu_ctx_destroy(vfu_ctx); free(server_data.bar1); - free(sparse_areas); return EXIT_SUCCESS; } |