Also fix a logic bug in xenXMDomain{Attach,Detach}DeviceFlags, where (flags & VIR_DOMAIN_DEVICE_MODIFY_CURRENT) is always false. * src/xen/xen_driver.c (xenUnifiedDomainXMLFromNative) (xenUnifiedDomainXMLToNative, xenUnifiedDomainBlockPeek): Reject unknown flags. * src/xen/xen_hypervisor.c (xenHypervisorOpen) (xenHypervisorGetDomainState): Likewise. * src/xen/xen_inotify.c (xenInotifyOpen): Likewise. * src/xen/xs_internal.c (xenStoreOpen, xenStoreDomainGetState) (xenStoreDomainReboot): Likewise. * src/xen/xend_internal.c (xenDaemonOpen, xenDaemonDomainReboot) (xenDaemonDomainCoreDump, xenDaemonDomainGetState) (xenDaemonDomainMigratePrepare, xenDaemonDomainSetVcpusFlags, xenDaemonDomainGetVcpusFlags, xenDaemonAttachDeviceFlags, xenDaemonDetachDeviceFlags): Likewise. (xenDaemonDomainGetXMLDesc): Prefer unsigned flags. * src/xen/xend_internal.h (xenDaemonDomainGetXMLDesc): Likewise. * src/xen/xm_internal.h (xenXMDomainGetXMLDesc): Likewise. * src/xen/xm_internal.c (xenXMDomainGetXMLDesc): Likewise. (xenXMOpen, xenXMDomainGetState, xenXMDomainSetVcpusFlags) (xenXMDomainGetVcpusFlags): Reject unknown flags. (xenXMDomainAttachDeviceFlags, xenXMDomainDetachDeviceFlags): Likewise, and avoid always-false conditional. * src/xen/xen_driver.h (XEN_MIGRATION_FLAGS): New define. --- v3: address concerns about migration and coredump flags src/xen/xen_driver.c | 18 +++++++++++++++--- src/xen/xen_driver.h | 7 +++++++ src/xen/xen_hypervisor.c | 8 ++++++-- src/xen/xen_inotify.c | 4 +++- src/xen/xend_internal.c | 42 ++++++++++++++++++++++++++++++++++-------- src/xen/xend_internal.h | 3 ++- src/xen/xm_internal.c | 33 ++++++++++++++++++++++++++------- src/xen/xm_internal.h | 2 +- src/xen/xs_internal.c | 12 +++++++++--- 9 files changed, 103 insertions(+), 26 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 1d75da3..dd1ba6c 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1261,7 +1261,7 @@ static char * xenUnifiedDomainXMLFromNative(virConnectPtr conn, const char *format, const char *config, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDomainDefPtr def = NULL; char *ret = NULL; @@ -1271,6 +1271,8 @@ xenUnifiedDomainXMLFromNative(virConnectPtr conn, int vncport; GET_PRIVATE(conn); + virCheckFlags(0, NULL); + if (STRNEQ(format, XEN_CONFIG_FORMAT_XM) && STRNEQ(format, XEN_CONFIG_FORMAT_SEXPR)) { xenUnifiedError(VIR_ERR_INVALID_ARG, @@ -1311,13 +1313,15 @@ static char * xenUnifiedDomainXMLToNative(virConnectPtr conn, const char *format, const char *xmlData, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDomainDefPtr def = NULL; char *ret = NULL; virConfPtr conf = NULL; GET_PRIVATE(conn); + virCheckFlags(0, NULL); + if (STRNEQ(format, XEN_CONFIG_FORMAT_XM) && STRNEQ(format, XEN_CONFIG_FORMAT_SEXPR)) { xenUnifiedError(VIR_ERR_INVALID_ARG, @@ -1368,6 +1372,8 @@ xenUnifiedDomainMigratePrepare (virConnectPtr dconn, { GET_PRIVATE(dconn); + virCheckFlags(XEN_MIGRATION_FLAGS, -1); + if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) return xenDaemonDomainMigratePrepare (dconn, cookie, cookielen, uri_in, uri_out, @@ -1388,6 +1394,8 @@ xenUnifiedDomainMigratePerform (virDomainPtr dom, { GET_PRIVATE(dom->conn); + virCheckFlags(XEN_MIGRATION_FLAGS, -1); + if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) return xenDaemonDomainMigratePerform (dom, cookie, cookielen, uri, flags, dname, resource); @@ -1408,6 +1416,8 @@ xenUnifiedDomainMigrateFinish (virConnectPtr dconn, char *domain_xml = NULL; virDomainPtr dom_new = NULL; + virCheckFlags(XEN_MIGRATION_FLAGS, NULL); + dom = xenUnifiedDomainLookupByName (dconn, dname); if (! dom) { return NULL; @@ -1765,11 +1775,13 @@ xenUnifiedDomainInterfaceStats (virDomainPtr dom, const char *path, static int xenUnifiedDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long offset, size_t size, - void *buffer, unsigned int flags ATTRIBUTE_UNUSED) + void *buffer, unsigned int flags) { int r; GET_PRIVATE (dom->conn); + virCheckFlags(0, -1); + if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) { r = xenDaemonDomainBlockPeek (dom, path, offset, size, buffer); if (r != -2) return r; diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h index 6d45f7d..a6fe475 100644 --- a/src/xen/xen_driver.h +++ b/src/xen/xen_driver.h @@ -63,6 +63,13 @@ extern int xenRegister (void); # define XEN_SCHED_SEDF_NPARAM 6 # define XEN_SCHED_CRED_NPARAM 2 +/* The set of migration flags explicitly supported by xen. */ +# define XEN_MIGRATION_FLAGS \ + (VIR_MIGRATE_LIVE | \ + VIR_MIGRATE_UNDEFINE_SOURCE | \ + VIR_MIGRATE_PAUSED | \ + VIR_MIGRATE_PERSIST_DEST) + /* _xenUnifiedDriver: * * Entry points into the underlying Xen drivers. This structure diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index a92b743..543dfb1 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -2201,11 +2201,13 @@ xenHypervisorInit(void) virDrvOpenStatus xenHypervisorOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret; xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (initialized == 0) if (xenHypervisorInit() == -1) return -1; @@ -3272,11 +3274,13 @@ int xenHypervisorGetDomainState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = domain->conn->privateData; virDomainInfo info; + virCheckFlags(0, -1); + if (domain->conn == NULL) return -1; diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index 2d7207c..241dbc7 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -383,13 +383,15 @@ cleanup: virDrvOpenStatus xenInotifyOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { DIR *dh; struct dirent *ent; char *path; xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (priv->configDir) { priv->useXenConfigCache = 1; } else { diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index d0679b7..dec8484 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1323,11 +1323,13 @@ error: virDrvOpenStatus xenDaemonOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *port = NULL; int ret = VIR_DRV_OPEN_ERROR; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + /* Switch on the scheme, which we expect to be NULL (file), * "http" or "xen". */ @@ -1488,8 +1490,10 @@ xenDaemonDomainShutdown(virDomainPtr domain) * Returns 0 in case of success, -1 (with errno) in case of error. */ int -xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) +xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags) { + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); return(-1); @@ -1629,8 +1633,10 @@ xenDaemonDomainSave(virDomainPtr domain, const char *filename) */ static int xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_DUMP_LIVE | VIR_DUMP_CRASH, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) || (filename == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); @@ -1837,12 +1843,15 @@ cleanup: * the caller must free() the returned value. */ char * -xenDaemonDomainGetXMLDesc(virDomainPtr domain, int flags, const char *cpus) +xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags, + const char *cpus) { xenUnifiedPrivatePtr priv; virDomainDefPtr def; char *xml; + /* Flags checked by virDomainDefFormat */ + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); return(NULL); @@ -1921,11 +1930,13 @@ int xenDaemonDomainGetState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = domain->conn->privateData; struct sexpr *root; + virCheckFlags(0, -1); + if (domain->id < 0 && priv->xendConfigVersion < 3) return -1; @@ -2213,6 +2224,10 @@ xenDaemonDomainSetVcpusFlags(virDomainPtr domain, unsigned int vcpus, xenUnifiedPrivatePtr priv; int max; + virCheckFlags(VIR_DOMAIN_VCPU_LIVE | + VIR_DOMAIN_VCPU_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) || (vcpus < 1)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); @@ -2364,6 +2379,10 @@ xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) int ret; xenUnifiedPrivatePtr priv; + virCheckFlags(VIR_DOMAIN_VCPU_LIVE | + VIR_DOMAIN_VCPU_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM, -1); + if (domain == NULL || domain->conn == NULL || domain->name == NULL) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); return -1; @@ -2660,6 +2679,8 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml, char class[8], ref[80]; char *target = NULL; + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); return -1; @@ -2825,8 +2846,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml, virBuffer buf = VIR_BUFFER_INITIALIZER; char class[8], ref[80]; - virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_CURRENT | - VIR_DOMAIN_DEVICE_MODIFY_LIVE | + virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE | VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1); if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { @@ -2940,6 +2960,8 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain, const char *xml, char *xendev = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); return (-1); @@ -3149,10 +3171,12 @@ xenDaemonDomainMigratePrepare (virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { + virCheckFlags(XEN_MIGRATION_FLAGS, -1); + /* If uri_in is NULL, get the current hostname as a best guess * of how the source host should connect to us. Note that caller * deallocates this string. @@ -3187,6 +3211,8 @@ xenDaemonDomainMigratePerform (virDomainPtr domain, int undefined_source = 0; + virCheckFlags(XEN_MIGRATION_FLAGS, -1); + /* Xen doesn't support renaming domains during migration. */ if (dname) { virXendError(VIR_ERR_NO_SUPPORT, diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h index 5d324da..c4ed9ba 100644 --- a/src/xen/xend_internal.h +++ b/src/xen/xend_internal.h @@ -115,7 +115,8 @@ int xenDaemonDomainGetState(virDomainPtr domain, int *state, int *reason, unsigned int flags); -char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, int flags, const char *cpus); +char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags, + const char *cpus); unsigned long xenDaemonDomainGetMaxMemory(virDomainPtr domain); char **xenDaemonListDomainsOld(virConnectPtr xend); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 68181d2..6ec295e 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -442,10 +442,12 @@ int xenXMConfigCacheRefresh (virConnectPtr conn) { virDrvOpenStatus xenXMOpen (virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + priv->configDir = XM_CONFIG_DIR; priv->configCache = virHashCreate(50, xenXMConfigFree); @@ -485,8 +487,10 @@ int xenXMDomainGetState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if (domain->id != -1) return -1; @@ -543,12 +547,15 @@ error: * Turn a config record into a lump of XML describing the * domain, suitable for later feeding for virDomainCreateXML */ -char *xenXMDomainGetXMLDesc(virDomainPtr domain, int flags) { +char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) +{ xenUnifiedPrivatePtr priv; const char *filename; xenXMConfCachePtr entry; char *ret = NULL; + /* Flags checked by virDomainDefFormat */ + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { xenXMError(VIR_ERR_INVALID_ARG, __FUNCTION__); return(NULL); @@ -714,6 +721,10 @@ xenXMDomainSetVcpusFlags(virDomainPtr domain, unsigned int vcpus, int ret = -1; int max; + virCheckFlags(VIR_DOMAIN_VCPU_LIVE | + VIR_DOMAIN_VCPU_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { xenXMError(VIR_ERR_INVALID_ARG, __FUNCTION__); return -1; @@ -794,6 +805,10 @@ xenXMDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) xenXMConfCachePtr entry; int ret = -2; + virCheckFlags(VIR_DOMAIN_VCPU_LIVE | + VIR_DOMAIN_VCPU_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { xenXMError(VIR_ERR_INVALID_ARG, __FUNCTION__); return -1; @@ -1378,7 +1393,8 @@ cleanup: */ static int xenXMDomainAttachDeviceFlags(virDomainPtr domain, const char *xml, - unsigned int flags) { + unsigned int flags) +{ const char *filename = NULL; xenXMConfCachePtr entry = NULL; int ret = -1; @@ -1386,6 +1402,8 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain, const char *xml, virDomainDefPtr def; xenUnifiedPrivatePtr priv; + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if ((!domain) || (!domain->conn) || (!domain->name) || (!xml)) { xenXMError(VIR_ERR_INVALID_ARG, __FUNCTION__); return -1; @@ -1395,7 +1413,7 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain, const char *xml, return -1; if ((flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) || - (domain->id != -1 && (flags & VIR_DOMAIN_DEVICE_MODIFY_CURRENT))) { + (domain->id != -1 && flags == VIR_DOMAIN_DEVICE_MODIFY_CURRENT)) { xenXMError(VIR_ERR_OPERATION_INVALID, "%s", _("Xm driver only supports modifying persistent config")); return -1; @@ -1481,17 +1499,18 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml, int i; xenUnifiedPrivatePtr priv; + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if ((!domain) || (!domain->conn) || (!domain->name) || (!xml)) { xenXMError(VIR_ERR_INVALID_ARG, __FUNCTION__); return -1; } - if (domain->conn->flags & VIR_CONNECT_RO) return -1; if ((flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) || - (domain->id != -1 && (flags & VIR_DOMAIN_DEVICE_MODIFY_CURRENT))) { + (domain->id != -1 && flags == VIR_DOMAIN_DEVICE_MODIFY_CURRENT)) { xenXMError(VIR_ERR_OPERATION_INVALID, "%s", _("Xm driver only supports modifying persistent config")); return -1; diff --git a/src/xen/xm_internal.h b/src/xen/xm_internal.h index cf315cd..89af23e 100644 --- a/src/xen/xm_internal.h +++ b/src/xen/xm_internal.h @@ -45,7 +45,7 @@ int xenXMDomainGetState(virDomainPtr domain, int *state, int *reason, unsigned int flags); -char *xenXMDomainGetXMLDesc(virDomainPtr domain, int flags); +char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags); int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory); int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory); unsigned long xenXMDomainGetMaxMemory(virDomainPtr domain); diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c index 48e450a..f62d716 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -267,10 +267,12 @@ virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name) virDrvOpenStatus xenStoreOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (flags & VIR_CONNECT_RO) priv->xshandle = xs_daemon_open_readonly(); else @@ -461,10 +463,12 @@ int xenStoreDomainGetState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *running; + virCheckFlags(0, -1); + if (domain->id == -1) return -1; @@ -778,11 +782,13 @@ xenStoreDomainShutdown(virDomainPtr domain) * Returns 0 in case of success, -1 in case of error. */ int -xenStoreDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) +xenStoreDomainReboot(virDomainPtr domain, unsigned int flags) { int ret; xenUnifiedPrivatePtr priv; + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL)) { virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__); return(-1); -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list