aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorswapnili <swapnil.ingle@nutanix.com>2020-12-08 16:01:35 +0100
committerGitHub <noreply@github.com>2020-12-08 16:01:35 +0100
commit2015453378f9d00fe271faf0f4cfa39f5f53536a (patch)
treee655a6837f76e0188cc048c28b4188813ba7ddee /lib
parent486cb8a724e3259220d1da2ad673118eecb5c360 (diff)
downloadlibvfio-user-2015453378f9d00fe271faf0f4cfa39f5f53536a.zip
libvfio-user-2015453378f9d00fe271faf0f4cfa39f5f53536a.tar.gz
libvfio-user-2015453378f9d00fe271faf0f4cfa39f5f53536a.tar.bz2
Misc fixes for vfu_ctx_try_attach() and vfu_realize_ctx() (#175)
Misc changes for vfu_ctx_try_attach() * Rename to vfu_attach_ctx() * Removed call to vfu_realize_ctx(), should be called separately * Now vfu_attach_ctx() must also be called for blocking ctx. Misc changes for vfu_realize_ctx() * Made calling vfu_realize_ctx() mandatory * vfu_ctx_drive() and vfu_poll_ctx() returns EINVAL if the device is not realized. * Renamed vfu_ctx->ready to vfu_ctx->realized Added unit test for vfu_attach_ctx() and vfu_realize_ctx() 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.c44
-rw-r--r--lib/private.h2
2 files changed, 8 insertions, 38 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 007169f..5e04794 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -1085,30 +1085,13 @@ vfu_realize_ctx(vfu_ctx_t *vfu_ctx)
{
vfu_reg_info_t *cfg_reg;
const vfu_reg_info_t zero_reg = { 0 };
- int err;
uint32_t max_ivs = 0, i;
size_t size;
- if (vfu_ctx->ready) {
+ if (vfu_ctx->realized) {
return 0;
}
- /*
- * With LIBVFIO_USER_FLAG_ATTACH_NB caller is always expected to call
- * vfu_ctx_try_attach().
- */
- if ((vfu_ctx->flags & LIBVFIO_USER_FLAG_ATTACH_NB) == 0) {
- vfu_ctx->conn_fd = vfu_ctx->trans->attach(vfu_ctx);
- if (vfu_ctx->conn_fd < 0) {
- err = vfu_ctx->conn_fd;
- if (err != EINTR) {
- vfu_log(vfu_ctx, LOG_ERR, "failed to attach: %s",
- strerror(-err));
- }
- return ERROR(err);
- }
- }
-
cfg_reg = &vfu_ctx->reg_info[VFU_PCI_DEV_CFG_REGION_IDX];
// Set a default config region if none provided.
@@ -1173,7 +1156,7 @@ vfu_realize_ctx(vfu_ctx_t *vfu_ctx)
vfu_ctx->pci.config_space->hdr.sts.cl = 0x1;
vfu_ctx->pci.config_space->hdr.cap = PCI_STD_HEADER_SIZEOF;
}
- vfu_ctx->ready = true;
+ vfu_ctx->realized = true;
return 0;
}
@@ -1183,15 +1166,10 @@ vfu_ctx_drive(vfu_ctx_t *vfu_ctx)
{
int err;
- if (vfu_ctx == NULL) {
+ if (vfu_ctx == NULL || !vfu_ctx->realized) {
return ERROR(EINVAL);
}
- err = vfu_realize_ctx(vfu_ctx);
- if (err == -1) {
- return -1;
- }
-
do {
err = process_request(vfu_ctx);
} while (err >= 0);
@@ -1208,7 +1186,9 @@ vfu_ctx_poll(vfu_ctx_t *vfu_ctx)
return -ENOTSUP;
}
- assert(vfu_ctx->ready);
+ if (!vfu_ctx->realized) {
+ return ERROR(EINVAL);
+ }
err = process_request(vfu_ctx);
return err >= 0 ? 0 : err;
@@ -1269,21 +1249,11 @@ vfu_destroy_ctx(vfu_ctx_t *vfu_ctx)
}
int
-vfu_ctx_try_attach(vfu_ctx_t *vfu_ctx)
+vfu_attach_ctx(vfu_ctx_t *vfu_ctx)
{
- int err;
assert(vfu_ctx != NULL);
- if ((vfu_ctx->flags & LIBVFIO_USER_FLAG_ATTACH_NB) == 0) {
- return ERROR(EINVAL);
- }
-
- err = vfu_realize_ctx(vfu_ctx);
- if (err == -1) {
- return err;
- }
-
return vfu_ctx->trans->attach(vfu_ctx);
}
diff --git a/lib/private.h b/lib/private.h
index 1321b8f..e8afd79 100644
--- a/lib/private.h
+++ b/lib/private.h
@@ -129,7 +129,7 @@ struct vfu_ctx {
uint32_t irq_count[VFU_DEV_NUM_IRQS];
vfu_irqs_t *irqs;
- bool ready;
+ bool realized;
vfu_dev_type_t dev_type;
};