Ian Campbell
2012-Jul-26 16:25 UTC
[PATCH] libxl: make libxl_device_pci_{add, remove, destroy} interfaces asynchronous
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1343319067 -3600 # Node ID 006588b1bbb609186df45770a3c16d3028b54778 # Parent 728ac7499eaf362c1a5151cef1c1bf51593a2d36 libxl: make libxl_device_pci_{add,remove,destroy} interfaces asynchronous This does not make the implementation fully asynchronous but just updates the API to support asynchrony in the future. Currently although these functions do not call hotplug scripts etc and therefore are not "slow" (per the comment about ao machinery in libxl_internal.h) they do interact with the device model and so are not quite "fast" either. We can live with this for now. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 728ac7499eaf -r 006588b1bbb6 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Jul 26 16:51:36 2012 +0100 +++ b/tools/libxl/libxl.h Thu Jul 26 17:11:07 2012 +0100 @@ -731,10 +731,18 @@ int libxl_device_vfb_destroy(libxl_ctx * const libxl_asyncop_how *ao_how); /* PCI Passthrough */ -int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); -int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); -int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); -libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num); +int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_pci *pcidev, + const libxl_asyncop_how *ao_how); +int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_pci *pcidev, + const libxl_asyncop_how *ao_how); +int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_pci *pcidev, + const libxl_asyncop_how *ao_how); + +libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, + int *num); /* * Functions related to making devices assignable -- that is, bound to diff -r 728ac7499eaf -r 006588b1bbb6 tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Thu Jul 26 16:51:36 2012 +0100 +++ b/tools/libxl/libxl_pci.c Thu Jul 26 17:11:07 2012 +0100 @@ -1010,13 +1010,15 @@ int libxl__device_pci_setdefault(libxl__ return 0; } -int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev) +int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_pci *pcidev, + const libxl_asyncop_how *ao_how) { - GC_INIT(ctx); + AO_CREATE(ctx, domid, ao_how); int rc; rc = libxl__device_pci_add(gc, domid, pcidev, 0); - GC_FREE; - return rc; + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; } static int libxl_pcidev_assignable(libxl_ctx *ctx, libxl_device_pci *pcidev) @@ -1150,6 +1152,9 @@ static int qemu_pci_remove_xenstore(libx return 0; } +static int libxl__device_pci_remove_common(libxl__gc *gc, uint32_t domid, + libxl_device_pci *pcidev, int force); + static int do_pci_remove(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int force) { @@ -1263,10 +1268,7 @@ out: stubdomid = libxl_get_stubdom_id(ctx, domid); if (stubdomid != 0) { libxl_device_pci pcidev_s = *pcidev; - if (force) - libxl_device_pci_destroy(ctx, stubdomid, &pcidev_s); - else - libxl_device_pci_remove(ctx, stubdomid, &pcidev_s); + libxl__device_pci_remove_common(gc, stubdomid, &pcidev_s, force); } libxl__device_pci_remove_xenstore(gc, domid, pcidev); @@ -1313,27 +1315,31 @@ out: return rc; } -int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev) +int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_pci *pcidev, + const libxl_asyncop_how *ao_how) + { - GC_INIT(ctx); + AO_CREATE(ctx, domid, ao_how); int rc; rc = libxl__device_pci_remove_common(gc, domid, pcidev, 0); - GC_FREE; - return rc; + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; } int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, - libxl_device_pci *pcidev) + libxl_device_pci *pcidev, + const libxl_asyncop_how *ao_how) { - GC_INIT(ctx); + AO_CREATE(ctx, domid, ao_how); int rc; rc = libxl__device_pci_remove_common(gc, domid, pcidev, 1); - GC_FREE; - return rc; + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; } static void libxl__device_pci_from_xs_be(libxl__gc *gc, @@ -1415,7 +1421,7 @@ int libxl__device_pci_destroy_all(libxl_ * respond to SCI interrupt because the guest kernel has shut down the * devices by the time we even get here! */ - if (libxl_device_pci_destroy(ctx, domid, pcidevs + i) < 0) + if (libxl__device_pci_remove_common(gc, domid, pcidevs + i, 1) < 0) rc = ERROR_FAIL; } diff -r 728ac7499eaf -r 006588b1bbb6 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Jul 26 16:51:36 2012 +0100 +++ b/tools/libxl/xl_cmdimpl.c Thu Jul 26 17:11:07 2012 +0100 @@ -2389,9 +2389,9 @@ static void pcidetach(const char *dom, c exit(2); } if (force) - libxl_device_pci_destroy(ctx, domid, &pcidev); + libxl_device_pci_destroy(ctx, domid, &pcidev, 0); else - libxl_device_pci_remove(ctx, domid, &pcidev); + libxl_device_pci_remove(ctx, domid, &pcidev, 0); libxl_device_pci_dispose(&pcidev); xlu_cfg_destroy(config); @@ -2435,7 +2435,7 @@ static void pciattach(const char *dom, c fprintf(stderr, "pci-attach: malformed BDF specification \"%s\"\n", bdf); exit(2); } - libxl_device_pci_add(ctx, domid, &pcidev); + libxl_device_pci_add(ctx, domid, &pcidev, 0); libxl_device_pci_dispose(&pcidev); xlu_cfg_destroy(config); diff -r 728ac7499eaf -r 006588b1bbb6 tools/ocaml/libs/xl/xenlight_stubs.c --- a/tools/ocaml/libs/xl/xenlight_stubs.c Thu Jul 26 16:51:36 2012 +0100 +++ b/tools/ocaml/libs/xl/xenlight_stubs.c Thu Jul 26 17:11:07 2012 +0100 @@ -423,7 +423,7 @@ value stub_xl_device_pci_add(value info, device_pci_val(&gc, &lg, &c_info, info); INIT_CTX(); - ret = libxl_device_pci_add(ctx, Int_val(domid), &c_info); + ret = libxl_device_pci_add(ctx, Int_val(domid), &c_info, 0); if (ret != 0) failwith_xl("pci_add", &lg); FREE_CTX(); @@ -441,7 +441,7 @@ value stub_xl_device_pci_remove(value in device_pci_val(&gc, &lg, &c_info, info); INIT_CTX(); - ret = libxl_device_pci_remove(ctx, Int_val(domid), &c_info); + ret = libxl_device_pci_remove(ctx, Int_val(domid), &c_info, 0); if (ret != 0) failwith_xl("pci_remove", &lg); FREE_CTX(); diff -r 728ac7499eaf -r 006588b1bbb6 tools/python/xen/lowlevel/xl/xl.c --- a/tools/python/xen/lowlevel/xl/xl.c Thu Jul 26 16:51:36 2012 +0100 +++ b/tools/python/xen/lowlevel/xl/xl.c Thu Jul 26 17:11:07 2012 +0100 @@ -497,7 +497,7 @@ static PyObject *pyxl_pci_add(XlObject * return NULL; } pci = (Py_device_pci *)obj; - if ( libxl_device_pci_add(self->ctx, domid, &pci->obj) ) { + if ( libxl_device_pci_add(self->ctx, domid, &pci->obj, 0) ) { PyErr_SetString(xl_error_obj, "cannot add pci device"); return NULL; } @@ -519,12 +519,12 @@ static PyObject *pyxl_pci_del(XlObject * } pci = (Py_device_pci *)obj; if ( force ) { - if ( libxl_device_pci_destroy(self->ctx, domid, &pci->obj) ) { + if ( libxl_device_pci_destroy(self->ctx, domid, &pci->obj, 0) ) { PyErr_SetString(xl_error_obj, "cannot remove pci device"); return NULL; } } else { - if ( libxl_device_pci_remove(self->ctx, domid, &pci->obj) ) { + if ( libxl_device_pci_remove(self->ctx, domid, &pci->obj, 0) ) { PyErr_SetString(xl_error_obj, "cannot remove pci device"); return NULL; }