mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
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.
This commit is contained in:
parent
37754a74bb
commit
461e0f1a2d
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
static int
|
||||
umlDomainAttachDeviceFlags(virDomainPtr dom,
|
||||
const char *xml,
|
||||
unsigned int flags) {
|
||||
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,
|
||||
static int
|
||||
umlDomainDetachDeviceFlags(virDomainPtr dom,
|
||||
const char *xml,
|
||||
unsigned int flags) {
|
||||
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"));
|
||||
|
@ -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"));
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user