Skip to content

Commit 15d294a

Browse files
samples/client: get BAR1 size from region info (#873)
Retrieve the BAR1 size from VFIO_USER_DEVICE_GET_REGION_INFO instead of relying on a hardcoded value. This removes the existing FIXME and allows the client to use the size reported by the server. Signed-off-by: Siddharth C <siddharthcibi@icloud.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
1 parent 49f1276 commit 15d294a

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

samples/client.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ mmap_sparse_areas(int fd, struct vfio_region_info *region_info,
301301
}
302302

303303
static void
304-
get_device_region_info(int sock, uint32_t index)
304+
get_device_region_info(int sock, uint32_t index, size_t *region_size)
305305
{
306306
struct vfio_region_info *region_info;
307307
size_t cap_sz;
@@ -353,16 +353,23 @@ get_device_region_info(int sock, uint32_t index)
353353
assert(index != VFU_PCI_DEV_BAR1_REGION_IDX);
354354
}
355355
}
356+
*region_size = region_info->size;
356357
free(region_info);
357358
}
358359

359360
static void
360-
get_device_regions_info(int sock, struct vfio_user_device_info *client_dev_info)
361+
get_device_regions_info(int sock,
362+
struct vfio_user_device_info *client_dev_info,
363+
size_t *bar1_size)
361364
{
362365
unsigned int i;
363366

364367
for (i = 0; i < client_dev_info->num_regions; i++) {
365-
get_device_region_info(sock, i);
368+
size_t region_size;
369+
get_device_region_info(sock, i, &region_size);
370+
if (i == VFU_PCI_DEV_BAR1_REGION_IDX) {
371+
*bar1_size = region_size;
372+
}
366373
}
367374
}
368375

@@ -1182,7 +1189,7 @@ int main(int argc, char *argv[])
11821189
struct iovec *migr_iters;
11831190
size_t nr_iters;
11841191
uint32_t crc;
1185-
size_t bar1_size = 0x4000; /* FIXME get this value from region info */
1192+
size_t bar1_size;
11861193

11871194
struct vfio_user_device_feature *dirty_pages_feature;
11881195
struct vfio_user_device_feature_dma_logging_control *dirty_pages_control;
@@ -1228,7 +1235,7 @@ int main(int argc, char *argv[])
12281235
get_device_info(sock, &client_dev_info);
12291236

12301237
/* VFIO_USER_DEVICE_GET_REGION_INFO */
1231-
get_device_regions_info(sock, &client_dev_info);
1238+
get_device_regions_info(sock, &client_dev_info, &bar1_size);
12321239

12331240
ret = access_region(sock, VFU_PCI_DEV_CFG_REGION_IDX, false, 0, &config_space,
12341241
sizeof(config_space));

0 commit comments

Comments
 (0)