[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2 of 6] libxl: replace libxl__domain_is_hvm with libxl__domain_type
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1310978325 -3600 # Node ID 8c7190363635ebae729f5cf7f4ca254a0972326e # Parent 3237f9de6c5053543fa13a7303a8c48733c58afd libxl: replace libxl__domain_is_hvm with libxl__domain_type New function returns a libxl_domain_type enum. Add LIBXL__DOMAIN_IS_TYPE helper macro. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> diff -r 3237f9de6c50 -r 8c7190363635 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Mon Jul 18 09:38:45 2011 +0100 +++ b/tools/libxl/libxl.c Mon Jul 18 09:38:45 2011 +0100 @@ -240,7 +240,7 @@ int libxl_domain_resume(libxl_ctx *ctx, libxl__gc gc = LIBXL_INIT_GC(ctx); int rc = 0; - if (libxl__domain_is_hvm(&gc, domid)) { + if (LIBXL__DOMAIN_IS_TYPE(&gc, domid, HVM)) { LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Called domain_resume on " "non-cooperative hvm domain %u", domid); rc = ERROR_NI; @@ -474,7 +474,7 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd) { libxl__gc gc = LIBXL_INIT_GC(ctx); - int hvm = libxl__domain_is_hvm(&gc, domid); + int hvm = LIBXL__DOMAIN_IS_TYPE(&gc, domid, HVM); int live = info != NULL && info->flags & XL_SUSPEND_LIVE; int debug = info != NULL && info->flags & XL_SUSPEND_DEBUG; int rc = 0; @@ -517,7 +517,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, char *state; int ret, rc = 0; - if (libxl__domain_is_hvm(&gc, domid)) { + if (LIBXL__DOMAIN_IS_TYPE(&gc, domid, HVM)) { 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")) { @@ -560,7 +560,7 @@ int libxl_domain_shutdown(libxl_ctx *ctx return ERROR_FAIL; } - if (libxl__domain_is_hvm(&gc, domid)) { + if (LIBXL__DOMAIN_IS_TYPE(&gc, domid, HVM)) { unsigned long pvdriver = 0; int ret; ret = xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver); @@ -722,6 +722,7 @@ int libxl_domain_destroy(libxl_ctx *ctx, libxl_dominfo dominfo; char *dom_path; char *vm_path; + char *pid; int rc, dm_present; rc = libxl_domain_info(ctx, &dominfo, domid); @@ -734,12 +735,16 @@ int libxl_domain_destroy(libxl_ctx *ctx, return rc; } - if (libxl__domain_is_hvm(&gc, domid)) { + switch (libxl__domain_type(&gc, domid)) { + case LIBXL_DOMAIN_TYPE_HVM: dm_present = 1; - } else { - char *pid; + break; + case LIBXL_DOMAIN_TYPE_PV: pid = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "/local/domain/%d/image/device-model-pid", domid)); dm_present = (pid != NULL); + break; + default: + abort(); } dom_path = libxl__xs_get_dompath(&gc, domid); @@ -818,10 +823,16 @@ int libxl_primary_console_exec(libxl_ctx rc = libxl_console_exec(ctx, stubdomid, STUBDOM_CONSOLE_SERIAL, LIBXL_CONSOLE_TYPE_PV); else { - if (libxl__domain_is_hvm(&gc, domid_vm)) + switch (libxl__domain_type(&gc, domid_vm)) { + case LIBXL_DOMAIN_TYPE_HVM: rc = libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSOLE_TYPE_SERIAL); - else + break; + case LIBXL_DOMAIN_TYPE_PV: rc = libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSOLE_TYPE_PV); + break; + default: + abort(); + } } libxl__free_all(&gc); return rc; diff -r 3237f9de6c50 -r 8c7190363635 tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Mon Jul 18 09:38:45 2011 +0100 +++ b/tools/libxl/libxl_dom.c Mon Jul 18 09:38:45 2011 +0100 @@ -35,7 +35,7 @@ #include "libxl.h" #include "libxl_internal.h" -int libxl__domain_is_hvm(libxl__gc *gc, uint32_t domid) +libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid) { libxl_ctx *ctx = libxl__gc_owner(gc); xc_domaininfo_t info; @@ -46,7 +46,10 @@ int libxl__domain_is_hvm(libxl__gc *gc, return -1; if (info.domain != domid) return -1; - return !!(info.flags & XEN_DOMINF_hvm_guest); + if (info.flags & XEN_DOMINF_hvm_guest) + return LIBXL_DOMAIN_TYPE_HVM; + else + return LIBXL_DOMAIN_TYPE_PV; } int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid) diff -r 3237f9de6c50 -r 8c7190363635 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Mon Jul 18 09:38:45 2011 +0100 +++ b/tools/libxl/libxl_internal.h Mon Jul 18 09:38:45 2011 +0100 @@ -167,9 +167,10 @@ _hidden char **libxl__xs_directory(libxl /* On error: returns NULL, sets errno (no logging) */ /* from xl_dom */ -_hidden int libxl__domain_is_hvm(libxl__gc *gc, uint32_t domid); +_hidden libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid); - +#define LIBXL__DOMAIN_IS_TYPE(gc, domid, type) \ + libxl__domain_type((gc), (domid)) == LIBXL_DOMAIN_TYPE_##type typedef struct { uint32_t store_port; unsigned long store_mfn; diff -r 3237f9de6c50 -r 8c7190363635 tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Mon Jul 18 09:38:45 2011 +0100 +++ b/tools/libxl/libxl_pci.c Mon Jul 18 09:38:45 2011 +0100 @@ -286,7 +286,7 @@ static int libxl__device_pci_add_xenstor if (!num_devs) return libxl__create_pci_backend(gc, domid, pcidev, 1); - if (!starting && !libxl__domain_is_hvm(gc, domid)) { + if (!starting && LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) { if (libxl__wait_for_backend(gc, be_path, "4") < 0) return ERROR_FAIL; } @@ -329,7 +329,7 @@ static int libxl__device_pci_remove_xens return ERROR_INVAL; num = atoi(num_devs); - if (!libxl__domain_is_hvm(gc, domid)) { + if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) { if (libxl__wait_for_backend(gc, be_path, "4") < 0) { LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "pci backend at %s is not ready", be_path); return ERROR_FAIL; @@ -357,7 +357,7 @@ retry_transaction: if (errno == EAGAIN) goto retry_transaction; - if (!libxl__domain_is_hvm(gc, domid)) { + if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV)) { if (libxl__wait_for_backend(gc, be_path, "4") < 0) { LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "pci backend at %s is not ready", be_path); return ERROR_FAIL; @@ -604,10 +604,11 @@ static int do_pci_add(libxl__gc *gc, uin libxl_ctx *ctx = libxl__gc_owner(gc); char *path; char *state, *vdevfn; - int rc, hvm; + int rc, hvm = 0; - hvm = libxl__domain_is_hvm(gc, domid); - if (hvm) { + switch (libxl__domain_type(gc, domid)) { + case LIBXL_DOMAIN_TYPE_HVM: + hvm = 1; if (libxl__wait_for_device_model(gc, domid, "running", NULL, NULL, NULL) < 0) { return ERROR_FAIL; @@ -635,7 +636,9 @@ static int do_pci_add(libxl__gc *gc, uin xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state)); if ( rc ) return ERROR_FAIL; - } else { + break; + case LIBXL_DOMAIN_TYPE_PV: + { char *sysfs_path = libxl__sprintf(gc, SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); FILE *f = fopen(sysfs_path, "r"); @@ -694,6 +697,9 @@ static int do_pci_add(libxl__gc *gc, uin } fclose(f); } + default: + abort(); + } out: if (!libxl_is_stubdom(ctx, domid, NULL)) { rc = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev)); @@ -831,7 +837,7 @@ static int do_pci_remove(libxl__gc *gc, libxl_device_pci *assigned; char *path; char *state; - int hvm, rc, num; + int hvm = 0, rc, num; int stubdomid = 0; if ( !libxl_device_pci_list_assigned(ctx, &assigned, domid, &num) ) { @@ -842,8 +848,9 @@ static int do_pci_remove(libxl__gc *gc, } } - hvm = libxl__domain_is_hvm(gc, domid); - if (hvm) { + switch (libxl__domain_type(gc, domid)) { + case LIBXL_DOMAIN_TYPE_HVM: + hvm = 1; if (libxl__wait_for_device_model(gc, domid, "running", NULL, NULL, NULL) < 0) { return ERROR_FAIL; @@ -871,7 +878,9 @@ static int do_pci_remove(libxl__gc *gc, } path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid); xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state)); - } else { + break; + case LIBXL_DOMAIN_TYPE_PV: + { char *sysfs_path = libxl__sprintf(gc, SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); FILE *f = fopen(sysfs_path, "r"); @@ -921,6 +930,9 @@ skip1: } fclose(f); } + default: + abort(); + } out: /* don't do multiple resets while some functions are still passed through */ if ( (pcidev->vdevfn & 0x7) == 0 ) { _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |