提交 461e0f1a 编写于 作者: E Eric Blake

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.
上级 37754a74
...@@ -9624,6 +9624,10 @@ char *virDomainDefFormat(virDomainDefPtr def, ...@@ -9624,6 +9624,10 @@ char *virDomainDefFormat(virDomainDefPtr def,
const char *type = NULL; const char *type = NULL;
int n, allones = 1; int n, allones = 1;
virCheckFlags(VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_UPDATE_CPU, NULL);
if (!(type = virDomainVirtTypeToString(def->virtType))) { if (!(type = virDomainVirtTypeToString(def->virtType))) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR, virDomainReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected domain type %d"), def->virtType); _("unexpected domain type %d"), def->virtType);
......
...@@ -2494,6 +2494,8 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -2494,6 +2494,8 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
virDomainObjPtr vm; virDomainObjPtr vm;
char *ret = NULL; char *ret = NULL;
/* Flags checked by virDomainDefFormat */
libxlDriverLock(driver); libxlDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
libxlDriverUnlock(driver); libxlDriverUnlock(driver);
......
...@@ -967,6 +967,8 @@ static char *lxcDomainGetXMLDesc(virDomainPtr dom, ...@@ -967,6 +967,8 @@ static char *lxcDomainGetXMLDesc(virDomainPtr dom,
virDomainObjPtr vm; virDomainObjPtr vm;
char *ret = NULL; char *ret = NULL;
/* Flags checked by virDomainDefFormat */
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
......
...@@ -461,6 +461,8 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { ...@@ -461,6 +461,8 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
virDomainObjPtr vm; virDomainObjPtr vm;
char *ret = NULL; char *ret = NULL;
/* Flags checked by virDomainDefFormat */
openvzDriverLock(driver); openvzDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
openvzDriverUnlock(driver); openvzDriverUnlock(driver);
......
...@@ -3317,6 +3317,8 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -3317,6 +3317,8 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
virDomainDef def; virDomainDef def;
char *managed_system = phyp_driver->managed_system; char *managed_system = phyp_driver->managed_system;
/* Flags checked by virDomainDefFormat */
memset(&def, 0, sizeof(virDomainDef)); memset(&def, 0, sizeof(virDomainDef));
def.virtType = VIR_DOMAIN_VIRT_PHYP; def.virtType = VIR_DOMAIN_VIRT_PHYP;
......
...@@ -3850,9 +3850,7 @@ static char *qemuDomainGetXMLDesc(virDomainPtr dom, ...@@ -3850,9 +3850,7 @@ static char *qemuDomainGetXMLDesc(virDomainPtr dom,
unsigned long balloon; unsigned long balloon;
int err; int err;
virCheckFlags(VIR_DOMAIN_XML_SECURE | /* Flags checked by virDomainDefFormat */
VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_UPDATE_CPU, NULL);
qemuDriverLock(driver); qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
...@@ -6283,6 +6281,8 @@ qemudDomainMemoryPeek (virDomainPtr dom, ...@@ -6283,6 +6281,8 @@ qemudDomainMemoryPeek (virDomainPtr dom,
int fd = -1, ret = -1; int fd = -1, ret = -1;
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
virCheckFlags(VIR_MEMORY_VIRTUAL | VIR_MEMORY_PHYSICAL, -1);
qemuDriverLock(driver); qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver); qemuDriverUnlock(driver);
......
...@@ -2366,6 +2366,8 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) ...@@ -2366,6 +2366,8 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
virDomainObjPtr privdom; virDomainObjPtr privdom;
char *ret = NULL; char *ret = NULL;
/* Flags checked by virDomainDefFormat */
testDriverLock(privconn); testDriverLock(privconn);
privdom = virDomainFindByName(&privconn->domains, privdom = virDomainFindByName(&privconn->domains,
domain->name); domain->name);
......
...@@ -1653,9 +1653,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, ...@@ -1653,9 +1653,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom,
virDomainObjPtr vm; virDomainObjPtr vm;
char *ret = NULL; char *ret = NULL;
virCheckFlags(VIR_DOMAIN_XML_SECURE | /* Flags checked by virDomainDefFormat */
VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_UPDATE_CPU, NULL);
umlDriverLock(driver); umlDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
...@@ -1929,9 +1927,13 @@ cleanup: ...@@ -1929,9 +1927,13 @@ cleanup:
} }
static int umlDomainAttachDeviceFlags(virDomainPtr dom, static int
const char *xml, umlDomainAttachDeviceFlags(virDomainPtr dom,
unsigned int flags) { const char *xml,
unsigned int flags)
{
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
umlReportError(VIR_ERR_OPERATION_INVALID, umlReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration of a domain")); "%s", _("cannot modify the persistent configuration of a domain"));
...@@ -2037,9 +2039,13 @@ cleanup: ...@@ -2037,9 +2039,13 @@ cleanup:
} }
static int umlDomainDetachDeviceFlags(virDomainPtr dom, static int
const char *xml, umlDomainDetachDeviceFlags(virDomainPtr dom,
unsigned int flags) { const char *xml,
unsigned int flags)
{
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
umlReportError(VIR_ERR_OPERATION_INVALID, umlReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration of a domain")); "%s", _("cannot modify the persistent configuration of a domain"));
......
...@@ -2145,6 +2145,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { ...@@ -2145,6 +2145,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
nsresult rc; nsresult rc;
char *tmp; char *tmp;
/* Flags checked by virDomainDefFormat */
if (VIR_ALLOC(def) < 0) { if (VIR_ALLOC(def) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
...@@ -5296,8 +5298,12 @@ static int vboxDomainAttachDevice(virDomainPtr dom, const char *xml) { ...@@ -5296,8 +5298,12 @@ static int vboxDomainAttachDevice(virDomainPtr dom, const char *xml) {
return vboxDomainAttachDeviceImpl(dom, xml, 0); return vboxDomainAttachDeviceImpl(dom, xml, 0);
} }
static int vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, static int
unsigned int flags) { 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) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
vboxError(VIR_ERR_OPERATION_INVALID, "%s", vboxError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot modify the persistent configuration of a domain")); _("cannot modify the persistent configuration of a domain"));
...@@ -5446,8 +5452,12 @@ cleanup: ...@@ -5446,8 +5452,12 @@ cleanup:
return ret; return ret;
} }
static int vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, static int
unsigned int flags) { 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) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
vboxError(VIR_ERR_OPERATION_INVALID, "%s", vboxError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot modify the persistent configuration of a domain")); _("cannot modify the persistent configuration of a domain"));
......
...@@ -807,6 +807,8 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -807,6 +807,8 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
virDomainObjPtr vm; virDomainObjPtr vm;
char *ret = NULL; char *ret = NULL;
/* Flags checked by virDomainDefFormat */
vmwareDriverLock(driver); vmwareDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
vmwareDriverUnlock(driver); vmwareDriverUnlock(driver);
......
...@@ -1318,9 +1318,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -1318,9 +1318,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
struct xen_vif_set *vif_set = NULL; struct xen_vif_set *vif_set = NULL;
char *xml; char *xml;
virCheckFlags(VIR_DOMAIN_XML_SECURE | /* Flags checked by virDomainDefFormat */
VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_UPDATE_CPU, NULL);
if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL; if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL;
if (vms->size != 1) { if (vms->size != 1) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册