diff options
author | Swapnil Ingle <swapnil.ingle@nutanix.com> | 2020-09-23 11:20:42 -0400 |
---|---|---|
committer | Swapnil Ingle <swapnil.ingle@nutanix.com> | 2020-09-23 11:21:42 -0400 |
commit | 1843c536b01b333db3bf6c4230e26e0dab739bb3 (patch) | |
tree | c89314f06a26b4add1cdb70d7afed3afbcedaa3e | |
parent | 03fbee40c5d7256afdb34e7c0f59964dd859320b (diff) | |
download | libvfio-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>
-rw-r--r-- | lib/libmuser.c | 29 | ||||
-rw-r--r-- | samples/client.c | 47 |
2 files changed, 75 insertions, 1 deletions
diff --git a/lib/libmuser.c b/lib/libmuser.c index 7e5a12d..0b5e67a 100644 --- a/lib/libmuser.c +++ b/lib/libmuser.c @@ -1574,6 +1574,27 @@ out: return ret; } +static int handle_device_get_info(lm_ctx_t *lm_ctx, + struct vfio_user_header *hdr) +{ + struct vfio_device_info dev_info; + int ret; + + dev_info.argsz = sizeof(struct vfio_device_info); + + ret = dev_get_info(&dev_info); + if (ret < 0) { + return ret; + } + + ret = send_vfio_user_msg(lm_ctx->conn_fd, hdr->msg_id, true, + VFIO_USER_DEVICE_GET_INFO, (void *)&dev_info, + dev_info.argsz, NULL, 0); + lm_log(lm_ctx, LM_DBG, "sent devinfo flags %#x, num_regions %d, num_irqs" + " %d", dev_info.flags, dev_info.num_regions, dev_info.num_irqs); + return ret; +} + static int handle_dma_map(lm_ctx_t *lm_ctx, struct vfio_user_header *hdr) { @@ -1653,13 +1674,19 @@ process_request(lm_ctx_t *lm_ctx) case VFIO_USER_DMA_MAP: handle_dma_map(lm_ctx, &hdr); break; + case VFIO_USER_DEVICE_GET_INFO: + ret = handle_device_get_info(lm_ctx, &hdr); + goto out; + break; default: - lm_log(lm_ctx, LM_ERR, "bad command %d", hdr.cmd); + lm_log(lm_ctx, LM_ERR, "bad command %d", hdr.cmd); return -EINVAL; } ret = send_vfio_user_msg(lm_ctx->conn_fd, hdr.msg_id, true, 0, NULL, 0, NULL, 0); + +out: if (unlikely(ret < 0)) { lm_log(lm_ctx, LM_ERR, "failed to complete command: %s\n", strerror(-ret)); 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"); |