libxl: Multi-device passthrough coldplug: do not wait for unstarted guest

When doing a PCI passthrough, the code checks to see whether there is
an existing backend directory in xenstore with a nonzero "num_devs".
If there isn't, it creates the backend directory with just the
required device.

If there is, it would assume that it was doing hotplug.  If doing
hotplug, it needs to set the "state" node in xenstore to "7"
(reconfiguring) and thus avoid racing with the backend needs to wait
for the backend to be "4" (connected).

However during guest creation, the presence of "num_devs" doesn't
necessarily mean hotplug.  If we are still creating the initial
xenstore setup (ie, adding devices as a subroutine of domain
creation), we can just write the new devices to xenstore.  So do that.

This involves adding a new parameter "starting", indicating that we
are still in domain creation, to libxl_device_pci_add_xenstore (a
misnamed internal function) and its callers.  Its callers include
libxl_device_pci_add which we therefore split into an internal version
with the new parameter, and an external version used only for hotplug
by libxl-using applications.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
This commit is contained in:
Ian Jackson committed 2011-02-25 17:15:20 +00:00
1 parent 67743d23a8
commit 70628d024d
3 files changed
+17 -7

No files matched your search

+1 -1
View File
@@ -538,7 +538,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
}
for (i = 0; i < d_config->num_pcidevs; i++)
libxl_device_pci_add(ctx, domid, &d_config->pcidevs[i]);
libxl__device_pci_add(ctx, domid, &d_config->pcidevs[i], 1);
if ( cb && (d_config->c_info.hvm || d_config->b_info.u.pv.bootloader )) {
if ( (*cb)(ctx, domid, priv) )
+4
View File
@@ -200,6 +200,10 @@ _hidden int libxl__wait_for_device_model(libxl_ctx *ctx,
void *check_callback_userdata);
_hidden int libxl__wait_for_backend(libxl_ctx *ctx, char *be_path, char *state);
/* from libxl_pci */
_hidden int libxl__device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev, int starting);
/* xl_exec */
/* higher-level double-fork and separate detach eg as for device models */
+12 -6
View File
@@ -286,7 +286,7 @@ out:
return 0;
}
static int libxl_device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev)
static int libxl_device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
flexarray_t *back;
@@ -299,7 +299,7 @@ static int libxl_device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_de
if (!num_devs)
return libxl_create_pci_backend(gc, domid, pcidev, 1);
if (!libxl__domain_is_hvm(ctx, domid)) {
if (!starting && !libxl__domain_is_hvm(ctx, domid)) {
if (libxl__wait_for_backend(ctx, be_path, "4") < 0)
return ERROR_FAIL;
}
@@ -312,7 +312,8 @@ static int libxl_device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_de
num = atoi(num_devs);
libxl_create_pci_backend_device(gc, back, num, pcidev);
flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num + 1), NULL);
flexarray_vappend(back, "state", libxl__sprintf(gc, "%d", 7), NULL);
if (!starting)
flexarray_vappend(back, "state", libxl__sprintf(gc, "%d", 7), NULL);
retry_transaction:
t = xs_transaction_start(ctx->xsh);
@@ -616,7 +617,7 @@ static int pci_ins_check(libxl_ctx *ctx, uint32_t domid, const char *state, void
return 1;
}
static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev)
static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
char *path;
@@ -759,6 +760,11 @@ static int libxl_device_pci_reset(libxl__gc *gc, unsigned int domain, unsigned i
}
int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev)
{
return libxl__device_pci_add(ctx, domid, pcidev, 0);
}
int libxl__device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev, int starting)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
unsigned int orig_vdev, pfunc_mask;
@@ -783,7 +789,7 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcide
stubdomid = libxl_get_stubdom_id(ctx, domid);
if (stubdomid != 0) {
libxl_device_pci pcidev_s = *pcidev;
rc = do_pci_add(&gc, stubdomid, &pcidev_s);
rc = do_pci_add(&gc, stubdomid, &pcidev_s, starting);
if ( rc )
goto out;
}
@@ -818,7 +824,7 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcide
*/
pcidev->vdevfn = orig_vdev;
}
if ( do_pci_add(&gc, domid, pcidev) )
if ( do_pci_add(&gc, domid, pcidev, starting) )
rc = ERROR_FAIL;
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.