aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorswapnili <swapnil.ingle@nutanix.com>2020-11-30 16:45:35 +0100
committerGitHub <noreply@github.com>2020-11-30 16:45:35 +0100
commit9d0224ae1c4c6c43e7dee048b71a499c857bc85f (patch)
treeaf82f3c83a6ca80da30fc8d18274f7a178d61a26 /lib
parenta3ba81765daeffaaa2e9e59d49d49ae4438b1b59 (diff)
downloadlibvfio-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 'lib')
-rw-r--r--lib/libvfio-user.c27
-rw-r--r--lib/private.h5
2 files changed, 20 insertions, 12 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 51013ef..ab1cde5 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -1393,23 +1393,25 @@ int vfu_pci_setup_caps(vfu_ctx_t *vfu_ctx, vfu_cap_t **caps, int nr_caps)
static int
copy_sparse_mmap_areas(vfu_reg_info_t *reg_info,
- struct vfu_sparse_mmap_areas *mmap_areas)
+ struct vfu_mmap_area *mmap_areas, uint32_t nr_mmap_areas)
{
- int nr_mmap_areas;
- size_t size;
+ struct vfu_sparse_mmap_areas *smmap_areas;
+ size_t areas_sz;
- if (mmap_areas == NULL) {
+ if (mmap_areas == NULL || nr_mmap_areas == 0) {
return 0;
}
- nr_mmap_areas = mmap_areas->nr_mmap_areas;
- size = sizeof(*mmap_areas) + (nr_mmap_areas * sizeof(struct vfu_mmap_area));
- reg_info->mmap_areas = calloc(1, size);
- if (reg_info->mmap_areas == NULL) {
+ areas_sz = nr_mmap_areas * sizeof(struct vfu_mmap_area);
+
+ smmap_areas = calloc(1, sizeof(struct vfu_sparse_mmap_areas) + areas_sz);
+ if (smmap_areas == NULL) {
return -ENOMEM;
}
- memcpy(reg_info->mmap_areas, mmap_areas, size);
+ smmap_areas->nr_mmap_areas = nr_mmap_areas;
+ memcpy(smmap_areas->areas, mmap_areas, areas_sz);
+ reg_info->mmap_areas = smmap_areas;
return 0;
}
@@ -1422,7 +1424,7 @@ static inline bool is_valid_pci_config_space_region(int flags, size_t size)
int vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size,
vfu_region_access_cb_t *region_access, int flags,
- struct vfu_sparse_mmap_areas *mmap_areas,
+ struct vfu_mmap_area *mmap_areas, uint32_t nr_mmap_areas,
vfu_map_region_cb_t *map)
{
int ret;
@@ -1446,7 +1448,7 @@ int vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size,
}
if (mmap_areas) {
ret = copy_sparse_mmap_areas(&vfu_ctx->reg_info[region_idx],
- mmap_areas);
+ mmap_areas, nr_mmap_areas);
if (ret < 0) {
return ERROR(-ret);
}
@@ -1525,7 +1527,8 @@ int vfu_setup_device_migration(vfu_ctx_t *vfu_ctx, vfu_migration_t *migration)
migr_reg = &vfu_ctx->reg_info[(vfu_ctx->nr_regions - 1)];
/* FIXME: Are there sparse areas need to be setup flags accordingly */
- ret = copy_sparse_mmap_areas(migr_reg, migration->mmap_areas);
+ ret = copy_sparse_mmap_areas(migr_reg, migration->mmap_areas,
+ migration->nr_mmap_areas);
if (ret < 0) {
return ERROR(-ret);
}
diff --git a/lib/private.h b/lib/private.h
index 9b13949..7ffe099 100644
--- a/lib/private.h
+++ b/lib/private.h
@@ -67,6 +67,11 @@ typedef struct {
struct migration;
+struct vfu_sparse_mmap_areas {
+ int nr_mmap_areas;
+ struct vfu_mmap_area areas[];
+};
+
typedef struct {
/*