Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
tools/libxl/libxl.c | 31 +++++++++++++++++++++----------
tools/libxl/libxl_dom.c | 14 ++++++++++----
tools/libxl/libxl_pci.c | 14 ++++++++------
3 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 6eb17e8..c31e6bf 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -427,9 +427,10 @@ out:
int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid)
{
libxl_gc gc = LIBXL_INIT_GC(ctx);
- int rc = 0;
+ int hvm, rc = 0;
- if (is_hvm(ctx, domid)) {
+ hvm = is_hvm(ctx, domid); if (hvm<0) { rc = hvm; goto out; }
+ if (hvm) {
XL_LOG(ctx, XL_LOG_DEBUG, "Called domain_resume on "
"non-cooperative hvm domain %u", domid);
rc = ERROR_NI;
@@ -645,11 +646,13 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm)
int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
uint32_t domid, int fd)
{
- int hvm = is_hvm(ctx, domid);
+ int hvm;
int live = info != NULL && info->flags & XL_SUSPEND_LIVE;
int debug = info != NULL && info->flags & XL_SUSPEND_DEBUG;
int rc = 0;
+ hvm = is_hvm(ctx, domid); if (hvm<0) return hvm;
+
core_suspend(ctx, domid, fd, hvm, live, debug);
if (hvm)
rc = save_device_model(ctx, domid, fd);
@@ -685,9 +688,10 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
libxl_gc gc = LIBXL_INIT_GC(ctx);
char *path;
char *state;
- int ret, rc = 0;
+ int hvm, ret, rc = 0;
- if (is_hvm(ctx, domid)) {
+ hvm = is_hvm(ctx, domid); if (hvm<0) return hvm;
+ if (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")) {
@@ -717,6 +721,7 @@ int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid,
int req)
libxl_gc gc = LIBXL_INIT_GC(ctx);
char *shutdown_path;
char *dom_path;
+ int hvm, rc = 0;
if (req > ARRAY_SIZE(req_table)) {
libxl_free_all(&gc);
@@ -732,7 +737,8 @@ int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid,
int req)
shutdown_path = libxl_sprintf(&gc, "%s/control/shutdown", dom_path);
xs_write(ctx->xsh, XBT_NULL, shutdown_path, req_table[req],
strlen(req_table[req]));
- if (is_hvm(ctx,domid)) {
+ hvm = is_hvm(ctx,domid); if (hvm<0) { rc = hvm; goto out; }
+ if (hvm) {
unsigned long acpi_s_state = 0;
unsigned long pvdriver = 0;
int ret;
@@ -754,8 +760,9 @@ int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid,
int req)
}
}
}
+ out:
libxl_free_all(&gc);
- return 0;
+ return rc;
}
int libxl_get_wait_fd(libxl_ctx *ctx, int *fd)
@@ -920,9 +927,10 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
int force)
libxl_gc gc = LIBXL_INIT_GC(ctx);
char *dom_path;
char *vm_path;
- int rc, dm_present;
+ int rc, hvm, dm_present;
- if (is_hvm(ctx, domid)) {
+ hvm = is_hvm(ctx, domid); if (hvm<0) { rc = hvm; goto out; }
+ if (hvm) {
dm_present = 1;
} else {
char *pid;
@@ -1004,11 +1012,14 @@ out:
int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm)
{
+ int hvm;
uint32_t stubdomid = libxl_get_stubdom_id(ctx, domid_vm);
+
if (stubdomid)
return libxl_console_exec(ctx, stubdomid, 1, LIBXL_CONSTYPE_PV);
else {
- if (is_hvm(ctx, domid_vm))
+ hvm = is_hvm(ctx, domid); if (hvm<0) return hvm;
+ if (hvm)
return libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSTYPE_SERIAL);
else
return libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSTYPE_PV);
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 1691858..a56e890 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -37,10 +37,16 @@ int is_hvm(libxl_ctx *ctx, uint32_t domid)
int ret;
ret = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
- if (ret != 1)
- return -1;
- if (info.domain != domid)
- return -1;
+ if (ret != 1) {
+ XL_LOG_ERRNO(ctx,XL_LOG_ERROR, "is_hvm: xc_domain_getinfolist failed");
+ return ERROR_FAIL;
+ }
+ if (info.domain != domid) {
+ XL_LOG(ctx, XL_LOG_ERROR, "is_hvm: xc_domain_getinfolist gave info "
+ "for %"PRIu32"d when we asked for %"PRIu32"d",
+ info.domain, domid);
+ return ERROR_FAIL;
+ }
return !!(info.flags & XEN_DOMINF_hvm_guest);
}
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index f32db3b..8bcabb0 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -266,7 +266,7 @@ static int libxl_device_pci_add_xenstore(libxl_gc *gc,
uint32_t domid, libxl_dev
libxl_ctx *ctx = libxl_gc_owner(gc);
flexarray_t *back;
char *num_devs, *be_path;
- int num = 0;
+ int hvm, num = 0;
unsigned int boffset = 0;
xs_transaction_t t;
@@ -275,7 +275,8 @@ static int libxl_device_pci_add_xenstore(libxl_gc *gc,
uint32_t domid, libxl_dev
if (!num_devs)
return libxl_create_pci_backend(gc, domid, pcidev, 1);
- if (!is_hvm(ctx, domid)) {
+ hvm = is_hvm(ctx, domid); if (hvm<0) return hvm;
+ if (!hvm) {
if (libxl_wait_for_backend(ctx, be_path, "4") < 0)
return ERROR_FAIL;
}
@@ -330,7 +331,8 @@ static int libxl_device_pci_remove_xenstore(libxl_gc *gc,
uint32_t domid, libxl_
return ERROR_INVAL;
num = atoi(num_devs);
- if (!is_hvm(ctx, domid)) {
+ hvm = is_hvm(ctx, domid); if (hvm<0) return hvm;
+ if (!hvm) {
if (libxl_wait_for_backend(ctx, be_path, "4") < 0) {
XL_LOG(ctx, XL_LOG_DEBUG, "pci backend at %s is not ready",
be_path);
return ERROR_FAIL;
@@ -358,7 +360,7 @@ retry_transaction:
if (errno == EAGAIN)
goto retry_transaction;
- if (!is_hvm(ctx, domid)) {
+ if (!hvm) {
if (libxl_wait_for_backend(ctx, be_path, "4") < 0) {
XL_LOG(ctx, XL_LOG_DEBUG, "pci backend at %s is not ready",
be_path);
return ERROR_FAIL;
@@ -610,7 +612,7 @@ static int do_pci_add(libxl_gc *gc, uint32_t domid,
libxl_device_pci *pcidev)
char *state, *vdevfn;
int rc, hvm;
- hvm = is_hvm(ctx, domid);
+ hvm = is_hvm(ctx, domid); if (hvm<0) return hvm;
if (hvm) {
if (libxl_wait_for_device_model(ctx, domid, "running", NULL, NULL) <
0) {
return ERROR_FAIL;
@@ -834,7 +836,7 @@ static int do_pci_remove(libxl_gc *gc, uint32_t domid,
libxl_device_pci *pcidev)
libxl_device_pci_remove_xenstore(gc, domid, pcidev);
- hvm = is_hvm(ctx, domid);
+ hvm = is_hvm(ctx, domid); if (hvm<0) return hvm;
if (hvm) {
if (libxl_wait_for_device_model(ctx, domid, "running", NULL, NULL) <
0) {
return ERROR_FAIL;
--
1.5.6.5
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|