From 461e0f1a2df4fd0cd2e16d38bb2847cf7be9a365 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 13 Jul 2011 16:24:38 -0600 Subject: [PATCH] flags: use common dumpxml flags check The previous patches only cleaned up ATTRIBUTE_UNUSED flags cases; auditing the drivers found other places where flags was being used but not validated. In particular, domainGetXMLDesc had issues with clients accepting a different set of flags than the common virDomainDefFormat helper function. * src/conf/domain_conf.c (virDomainDefFormat): Add common flag check. * src/uml/uml_driver.c (umlDomainAttachDeviceFlags) (umlDomainDetachDeviceFlags): Reject unknown flags. * src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc) (vboxDomainAttachDeviceFlags) (vboxDomainDetachDeviceFlags): Likewise. * src/qemu/qemu_driver.c (qemudDomainMemoryPeek): Likewise. (qemuDomainGetXMLDesc): Document common flag handling. * src/libxl/libxl_driver.c (libxlDomainGetXMLDesc): Likewise. * src/lxc/lxc_driver.c (lxcDomainGetXMLDesc): Likewise. * src/openvz/openvz_driver.c (openvzDomainGetXMLDesc): Likewise. * src/phyp/phyp_driver.c (phypDomainGetXMLDesc): Likewise. * src/test/test_driver.c (testDomainGetXMLDesc): Likewise. * src/vmware/vmware_driver.c (vmwareDomainGetXMLDesc): Likewise. * src/xenapi/xenapi_driver.c (xenapiDomainGetXMLDesc): Likewise. --- src/conf/domain_conf.c | 4 ++++ src/libxl/libxl_driver.c | 2 ++ src/lxc/lxc_driver.c | 2 ++ src/openvz/openvz_driver.c | 2 ++ src/phyp/phyp_driver.c | 2 ++ src/qemu/qemu_driver.c | 6 +++--- src/test/test_driver.c | 2 ++ src/uml/uml_driver.c | 24 +++++++++++++++--------- src/vbox/vbox_tmpl.c | 18 ++++++++++++++---- src/vmware/vmware_driver.c | 2 ++ src/xenapi/xenapi_driver.c | 4 +--- 11 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a78996fbb8..788981f93e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9624,6 +9624,10 @@ char *virDomainDefFormat(virDomainDefPtr def, const char *type = NULL; int n, allones = 1; + virCheckFlags(VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_INACTIVE | + VIR_DOMAIN_XML_UPDATE_CPU, NULL); + if (!(type = virDomainVirtTypeToString(def->virtType))) { virDomainReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected domain type %d"), def->virtType); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index f938e24545..cc37d05af8 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2494,6 +2494,8 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) virDomainObjPtr vm; char *ret = NULL; + /* Flags checked by virDomainDefFormat */ + libxlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); libxlDriverUnlock(driver); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index b6da757b75..78f0f9dca1 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -967,6 +967,8 @@ static char *lxcDomainGetXMLDesc(virDomainPtr dom, virDomainObjPtr vm; char *ret = NULL; + /* Flags checked by virDomainDefFormat */ + lxcDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); lxcDriverUnlock(driver); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index d50ecf16ff..cc0c590539 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -461,6 +461,8 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { virDomainObjPtr vm; char *ret = NULL; + /* Flags checked by virDomainDefFormat */ + openvzDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); openvzDriverUnlock(driver); diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 62ba192e2f..2489063a3c 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3317,6 +3317,8 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) virDomainDef def; char *managed_system = phyp_driver->managed_system; + /* Flags checked by virDomainDefFormat */ + memset(&def, 0, sizeof(virDomainDef)); def.virtType = VIR_DOMAIN_VIRT_PHYP; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f3a495f36c..0a73a59701 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3850,9 +3850,7 @@ static char *qemuDomainGetXMLDesc(virDomainPtr dom, unsigned long balloon; int err; - virCheckFlags(VIR_DOMAIN_XML_SECURE | - VIR_DOMAIN_XML_INACTIVE | - VIR_DOMAIN_XML_UPDATE_CPU, NULL); + /* Flags checked by virDomainDefFormat */ qemuDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); @@ -6283,6 +6281,8 @@ qemudDomainMemoryPeek (virDomainPtr dom, int fd = -1, ret = -1; qemuDomainObjPrivatePtr priv; + virCheckFlags(VIR_MEMORY_VIRTUAL | VIR_MEMORY_PHYSICAL, -1); + qemuDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); qemuDriverUnlock(driver); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f3fb320f26..064a1cdee5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2366,6 +2366,8 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virDomainObjPtr privdom; char *ret = NULL; + /* Flags checked by virDomainDefFormat */ + testDriverLock(privconn); privdom = virDomainFindByName(&privconn->domains, domain->name); diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index d0374ea4ac..557c948db1 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1653,9 +1653,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, virDomainObjPtr vm; char *ret = NULL; - virCheckFlags(VIR_DOMAIN_XML_SECURE | - VIR_DOMAIN_XML_INACTIVE | - VIR_DOMAIN_XML_UPDATE_CPU, NULL); + /* Flags checked by virDomainDefFormat */ umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); @@ -1929,9 +1927,13 @@ cleanup: } -static int umlDomainAttachDeviceFlags(virDomainPtr dom, - const char *xml, - unsigned int flags) { +static int +umlDomainAttachDeviceFlags(virDomainPtr dom, + const char *xml, + unsigned int flags) +{ + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { umlReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot modify the persistent configuration of a domain")); @@ -2037,9 +2039,13 @@ cleanup: } -static int umlDomainDetachDeviceFlags(virDomainPtr dom, - const char *xml, - unsigned int flags) { +static int +umlDomainDetachDeviceFlags(virDomainPtr dom, + const char *xml, + unsigned int flags) +{ + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { umlReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot modify the persistent configuration of a domain")); diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 6cb9bb4ce6..53bac798b8 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2145,6 +2145,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { nsresult rc; char *tmp; + /* Flags checked by virDomainDefFormat */ + if (VIR_ALLOC(def) < 0) { virReportOOMError(); goto cleanup; @@ -5296,8 +5298,12 @@ static int vboxDomainAttachDevice(virDomainPtr dom, const char *xml) { return vboxDomainAttachDeviceImpl(dom, xml, 0); } -static int vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, - unsigned int flags) { +static int +vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, + unsigned int flags) +{ + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { vboxError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot modify the persistent configuration of a domain")); @@ -5446,8 +5452,12 @@ cleanup: return ret; } -static int vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, - unsigned int flags) { +static int +vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, + unsigned int flags) +{ + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { vboxError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot modify the persistent configuration of a domain")); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index c0430fee4f..36b48e0fb8 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -807,6 +807,8 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) virDomainObjPtr vm; char *ret = NULL; + /* Flags checked by virDomainDefFormat */ + vmwareDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); vmwareDriverUnlock(driver); diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 98838e69ee..97da1d1e2f 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1318,9 +1318,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) struct xen_vif_set *vif_set = NULL; char *xml; - virCheckFlags(VIR_DOMAIN_XML_SECURE | - VIR_DOMAIN_XML_INACTIVE | - VIR_DOMAIN_XML_UPDATE_CPU, NULL); + /* Flags checked by virDomainDefFormat */ if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL; if (vms->size != 1) { -- GitLab