aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorSwapnil Ingle <swapnil.ingle@nutanix.com>2020-09-23 11:20:42 -0400
committerSwapnil Ingle <swapnil.ingle@nutanix.com>2020-09-23 11:21:42 -0400
commit1843c536b01b333db3bf6c4230e26e0dab739bb3 (patch)
treec89314f06a26b4add1cdb70d7afed3afbcedaa3e /samples
parent03fbee40c5d7256afdb34e7c0f59964dd859320b (diff)
downloadlibvfio-user-1843c536b01b333db3bf6c4230e26e0dab739bb3.zip
libvfio-user-1843c536b01b333db3bf6c4230e26e0dab739bb3.tar.gz
libvfio-user-1843c536b01b333db3bf6c4230e26e0dab739bb3.tar.bz2
Initial implementation of VFIO_USER_DEVICE_GET_INFO
Initial client and server implementation of VFIO_USER_DEVICE_GET_INFO. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/client.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/samples/client.c b/samples/client.c
index d93870c..f44583a 100644
--- a/samples/client.c
+++ b/samples/client.c
@@ -94,6 +94,48 @@ set_version(int sock)
return 0;
}
+static int
+get_device_info(int sock)
+{
+ struct vfio_user_header hdr;
+ struct vfio_device_info dev_info;
+ uint16_t msg_id;
+ int ret;
+
+ msg_id = 1;
+ ret = send_vfio_user_msg(sock, msg_id, false, VFIO_USER_DEVICE_GET_INFO,
+ NULL, 0, NULL,0);
+ if (ret < 0) {
+ fprintf(stderr, "%s: failed to send message: %s\n", __func__,
+ strerror(-ret));
+ return ret;
+ }
+
+ ret = recv_vfio_user_msg(sock, &hdr, true, &msg_id);
+ if (ret < 0) {
+ fprintf(stderr, "%s: failed to receive header: %s\n", __func__,
+ strerror(-ret));
+ return ret;
+ }
+
+ if ((hdr.msg_size - sizeof(hdr)) < sizeof(struct vfio_device_info)) {
+ fprintf(stderr, "%s: bad response data size\n", __func__);
+ return -EINVAL;
+ }
+
+ ret = recv(sock, &dev_info, sizeof(struct vfio_device_info), 0);
+ if (ret < 0) {
+ ret = -errno;
+ fprintf(stderr, "%s: failed to receive data: %s\n", __func__,
+ strerror(-ret));
+ return ret;
+ }
+
+ fprintf(stdout, "devinfo: flags %#x, num_regions %d, num_irqs %d\n",
+ dev_info.flags, dev_info.num_regions, dev_info.num_irqs);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret, sock;
@@ -121,6 +163,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = get_device_info(sock);
+ if (ret < 0) {
+ return ret;
+ }
+
/* Tell the server we have a memory DMA region it can access. */
if ((dma_region_fds[0] = mkstemp(template)) == -1) {
perror("failed to create DMA file");