aboutsummaryrefslogtreecommitdiff
path: root/samples/client.c
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2021-02-10 09:08:10 +0000
committerGitHub <noreply@github.com>2021-02-10 09:08:10 +0000
commit365ca96a97740332d3633090d850222d10bc9d70 (patch)
treebd9885cd57351c05ac12d63ef51a4e4e5b3eef7d /samples/client.c
parentc5d11659c95c995acb77a71fe03c38b240ca43d9 (diff)
downloadlibvfio-user-365ca96a97740332d3633090d850222d10bc9d70.zip
libvfio-user-365ca96a97740332d3633090d850222d10bc9d70.tar.gz
libvfio-user-365ca96a97740332d3633090d850222d10bc9d70.tar.bz2
expose migration region (#305)
This patch exposes the fact that live migration is implemented as a special device region. Hiding this from the user doesn't offer much benefit since it only takes just a little bit of extra code for the user to handle it as a region. We do keep the migration callback functionality since this feature substantially simplifies supporting live migration from the device implementation's perspective. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Co-authored-by: John Levon <john.levon@nutanix.com>
Diffstat (limited to 'samples/client.c')
-rw-r--r--samples/client.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/samples/client.c b/samples/client.c
index 92d86e0..d9b6661 100644
--- a/samples/client.c
+++ b/samples/client.c
@@ -209,7 +209,7 @@ send_device_reset(int sock)
/* returns whether a VFIO migration capability is found */
static bool
get_region_vfio_caps(struct vfio_info_cap_header *header,
- struct vfio_region_info_cap_sparse_mmap *sparse)
+ struct vfio_region_info_cap_sparse_mmap **sparse)
{
struct vfio_region_info_cap_type *type;
unsigned int i;
@@ -218,12 +218,13 @@ get_region_vfio_caps(struct vfio_info_cap_header *header,
while (true) {
switch (header->id) {
case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
- sparse = (struct vfio_region_info_cap_sparse_mmap*)header;
+ *sparse = (struct vfio_region_info_cap_sparse_mmap *)header;
printf("%s: Sparse cap nr_mmap_areas %d\n", __func__,
- sparse->nr_areas);
- for (i = 0; i < sparse->nr_areas; i++) {
+ (*sparse)->nr_areas);
+ for (i = 0; i < (*sparse)->nr_areas; i++) {
printf("%s: area %d offset %#llx size %llu\n", __func__,
- i, sparse->areas[i].offset, sparse->areas[i].size);
+ i, (*sparse)->areas[i].offset,
+ (*sparse)->areas[i].size);
}
break;
case VFIO_REGION_INFO_CAP_TYPE:
@@ -261,14 +262,10 @@ do_get_device_region_info(int sock, struct vfio_region_info *region_info,
}
static void
-mmap_sparse_areas(int *fds, size_t nr_fds,
- struct vfio_region_info_cap_sparse_mmap *sparse)
+mmap_sparse_areas(int *fds, struct vfio_region_info_cap_sparse_mmap *sparse)
{
size_t i;
- assert(nr_fds == 2);
- assert(sparse->nr_areas == 2);
-
for (i = 0; i < sparse->nr_areas; i++) {
ssize_t ret;
@@ -318,9 +315,6 @@ get_device_region_info(int sock, uint32_t index)
region_info->index = index;
do_get_device_region_info(sock, region_info, fds, &nr_fds);
assert(region_info->argsz == size);
- assert(nr_fds == 2);
- assert(fds[0] >= 0);
- assert(fds[1] >= 0);
} else {
nr_fds = 0;
}
@@ -332,9 +326,12 @@ get_device_region_info(int sock, uint32_t index)
if (cap_sz) {
struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
if (get_region_vfio_caps((struct vfio_info_cap_header*)(region_info + 1),
- sparse)) {
+ &sparse)) {
if (sparse != NULL) {
- mmap_sparse_areas(fds, nr_fds, sparse);
+ assert((index == VFU_PCI_DEV_BAR1_REGION_IDX && nr_fds == 2) ||
+ (index == VFU_PCI_DEV_MIGR_REGION_IDX && nr_fds == 1));
+ assert(nr_fds == sparse->nr_areas);
+ mmap_sparse_areas(fds, sparse);
}
return true;
}