From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGsn-0001NO-0U for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLGsl-0004gW-Et for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:12 -0400 Received: from smtp.citrix.com ([66.165.176.89]:28281) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGsl-0004eo-5m for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:11 -0400 From: Anthony PERARD Date: Tue, 1 Nov 2011 16:07:26 +0000 Message-ID: <1320163646-24291-14-git-send-email-anthony.perard@citrix.com> In-Reply-To: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> References: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH V3 13/13] libxl: Remove a passthrough device through QMP. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU-devel , Stefano Stabellini Cc: Anthony PERARD , Xen Devel Signed-off-by: Anthony PERARD --- tools/libxl/libxl_pci.c | 69 ++++++++++++++++++++++++++++++---------------- 1 files changed, 45 insertions(+), 24 deletions(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 207ee33..1f93e67 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -861,13 +861,45 @@ out: return rc; } +static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, + libxl_device_pci *pcidev, int force) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + char *state; + char *path; + + path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid); + state = libxl__xs_read(gc, XBT_NULL, path); + path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter", domid); + libxl__xs_write(gc, XBT_NULL, path, PCI_BDF, pcidev->domain, + pcidev->bus, pcidev->dev, pcidev->func); + path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/command", domid); + + /* Remove all functions at once atomically by only signalling + * device-model for function 0 */ + if ( !force && (pcidev->vdevfn & 0x7) == 0 ) { + xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem")); + if (libxl__wait_for_device_model(gc, domid, "pci-removed", + NULL, NULL, NULL) < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model didn't respond in time"); + /* This depends on guest operating system acknowledging the + * SCI, if it doesn't respond in time then we may wish to + * force the removal. + */ + return ERROR_FAIL; + } + } + path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid); + xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state)); + + return 0; +} + static int do_pci_remove(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int force) { libxl_ctx *ctx = libxl__gc_owner(gc); libxl_device_pci *assigned; - char *path; - char *state; int hvm = 0, rc, num; int stubdomid = 0; @@ -886,29 +918,18 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, NULL, NULL, NULL) < 0) { return ERROR_FAIL; } - path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid); - state = libxl__xs_read(gc, XBT_NULL, path); - path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter", domid); - libxl__xs_write(gc, XBT_NULL, path, PCI_BDF, pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->func); - path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/command", domid); - - /* Remove all functions at once atomically by only signalling - * device-model for function 0 */ - if ( !force && (pcidev->vdevfn & 0x7) == 0 ) { - xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem")); - if (libxl__wait_for_device_model(gc, domid, "pci-removed", - NULL, NULL, NULL) < 0) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model didn't respond in time"); - /* This depends on guest operating system acknowledging the - * SCI, if it doesn't respond in time then we may wish to - * force the removal. - */ - return ERROR_FAIL; - } + switch (libxl__device_model_version_running(gc, domid)) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + rc = qemu_pci_remove_xenstore(gc, domid, pcidev, force); + break; + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + rc = libxl__qmp_pci_del(gc, domid, pcidev); + break; + default: + return ERROR_INVAL; } - path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid); - xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state)); + if (rc) + return ERROR_FAIL; break; case LIBXL_DOMAIN_TYPE_PV: { -- Anthony PERARD