From: Ian Campbell Subject: Re: [PATCH 1 of 6] libxl: helper function to send commands to traditional qemu Date: Tue, 31 Jan 2012 09:46:47 +0000 Message-ID: <1328003207.26983.311.camel@zakaz.uk.xensource.com> References: <20bbc4a754a701ef14c9.1327971906@athos.nss.cs.ubc.ca> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20bbc4a754a701ef14c9.1327971906@athos.nss.cs.ubc.ca> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "rshriram@cs.ubc.ca" Cc: Anthony Perard , "brendan@cs.ubc.ca" , "xen-devel@lists.xensource.com" , Ian Jackson List-Id: xen-devel@lists.xenproject.org On Tue, 2012-01-31 at 01:05 +0000, rshriram@cs.ubc.ca wrote: > # HG changeset patch > # User Shriram Rajagopalan > # Date 1327971493 28800 > # Node ID 20bbc4a754a701ef14c9136a1adffc1c90bc1f4a > # Parent e2722b24dc0962de37215320b05d1bb7c4c42864 > libxl: helper function to send commands to traditional qemu > > Introduce a helper function to send commands to traditional > qemu. qemu_pci_add_xenstore, qemu_pci_remove_xenstore, > libxl__domain_save_device_model and libxl_domain_unpause have > been refactored to use this function. > > Signed-off-by: Shriram Rajagopalan Acked-by: Ian Campbell Every caller to libxl__qemu_traditional_cmd seems to be followed with a call to libxl__wait_for_device_model -- might be worth pushing that down into the function? > > diff -r e2722b24dc09 -r 20bbc4a754a7 tools/libxl/libxl.c > --- a/tools/libxl/libxl.c Thu Jan 26 17:43:31 2012 +0000 > +++ b/tools/libxl/libxl.c Mon Jan 30 16:58:13 2012 -0800 > @@ -517,7 +517,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, > path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid); > state = libxl__xs_read(gc, XBT_NULL, path); > if (state != NULL && !strcmp(state, "paused")) { > - libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/0/device-model/%d/command", domid), "continue"); > + libxl__qemu_traditional_cmd(gc, domid, "continue"); > libxl__wait_for_device_model(gc, domid, "running", > NULL, NULL, NULL); > } > diff -r e2722b24dc09 -r 20bbc4a754a7 tools/libxl/libxl_dom.c > --- a/tools/libxl/libxl_dom.c Thu Jan 26 17:43:31 2012 +0000 > +++ b/tools/libxl/libxl_dom.c Mon Jan 30 16:58:13 2012 -0800 > @@ -349,6 +349,15 @@ out: > return rc; > } > > +int libxl__qemu_traditional_cmd(libxl__gc *gc, uint32_t domid, > + const char *cmd) > +{ > + char *path = NULL; > + path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/command", > + domid); > + return libxl__xs_write(gc, XBT_NULL, path, "%s", cmd); > +} > + > int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid, > libxl_domain_build_info *info, > libxl__domain_build_state *state, > @@ -631,12 +640,9 @@ int libxl__domain_save_device_model(libx > > switch (libxl__device_model_version_running(gc, domid)) { > case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: { > - char *path = NULL; > LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, > "Saving device model state to %s", filename); > - path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/command", > - domid); > - libxl__xs_write(gc, XBT_NULL, path, "save"); > + libxl__qemu_traditional_cmd(gc, domid, "save"); > libxl__wait_for_device_model(gc, domid, "paused", NULL, NULL, NULL); > break; > } > diff -r e2722b24dc09 -r 20bbc4a754a7 tools/libxl/libxl_internal.h > --- a/tools/libxl/libxl_internal.h Thu Jan 26 17:43:31 2012 +0000 > +++ b/tools/libxl/libxl_internal.h Mon Jan 30 16:58:13 2012 -0800 > @@ -263,6 +263,8 @@ _hidden int libxl__build_hvm(libxl__gc * > libxl_device_model_info *dm_info, > libxl__domain_build_state *state); > > +_hidden int libxl__qemu_traditional_cmd(libxl__gc *gc, uint32_t domid, > + const char *cmd); > _hidden int libxl__domain_rename(libxl__gc *gc, uint32_t domid, > const char *old_name, const char *new_name, > xs_transaction_t trans); > diff -r e2722b24dc09 -r 20bbc4a754a7 tools/libxl/libxl_pci.c > --- a/tools/libxl/libxl_pci.c Thu Jan 26 17:43:31 2012 +0000 > +++ b/tools/libxl/libxl_pci.c Mon Jan 30 16:58:13 2012 -0800 > @@ -602,9 +602,8 @@ static int qemu_pci_add_xenstore(libxl__ > 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); > - xs_write(ctx->xsh, XBT_NULL, path, "pci-ins", strlen("pci-ins")); > + > + libxl__qemu_traditional_cmd(gc, domid, "pci-ins"); > rc = libxl__wait_for_device_model(gc, domid, NULL, NULL, > pci_ins_check, state); > path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter", > @@ -857,12 +856,11 @@ static int qemu_pci_remove_xenstore(libx > 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")); > + libxl__qemu_traditional_cmd(gc, domid, "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");