# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1310997150 -3600
# Node ID 97cb910d39b303005936f321eb93efbbd03e7c4c
# Parent 6efc1985c010ecbccde4f21223850a4227f3f4a2
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>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---
diff -r 6efc1985c010 -r 97cb910d39b3 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Mon Jul 18 14:52:29 2011 +0100
+++ b/tools/libxl/libxl.c Mon Jul 18 14:52:30 2011 +0100
@@ -240,7 +240,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 6efc1985c010 -r 97cb910d39b3 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c Mon Jul 18 14:52:29 2011 +0100
+++ b/tools/libxl/libxl_dom.c Mon Jul 18 14:52:30 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 @@
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 6efc1985c010 -r 97cb910d39b3 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Mon Jul 18 14:52:29 2011 +0100
+++ b/tools/libxl/libxl_internal.h Mon Jul 18 14:52:30 2011 +0100
@@ -166,9 +166,10 @@
/* 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 6efc1985c010 -r 97cb910d39b3 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c Mon Jul 18 14:52:29 2011 +0100
+++ b/tools/libxl/libxl_pci.c Mon Jul 18 14:52:30 2011 +0100
@@ -286,7 +286,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
}
}
- 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 @@
}
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 @@
}
fclose(f);
}
+ default:
+ abort();
+ }
out:
/* don't do multiple resets while some functions are still passed through
*/
if ( (pcidev->vdevfn & 0x7) == 0 ) {
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|