This patch removes the defaultDiskDriverName from the virCaps
structure. This particular default value is used only in the qemu driver
so this patch uses the recently added callback to fill the driver name
if it's needed instead of propagating it through virCaps.
---
Notes:
Version 5:
- already ACKed in v3, confirmed in v4
Version 4:
- tweaked naming to comply
- v3 was already ACKed
Version 3:
- new in series
src/conf/capabilities.h | 1 -
src/conf/domain_conf.c | 8 --------
src/qemu/qemu_conf.c | 5 ++---
src/qemu/qemu_conf.h | 3 ++-
src/qemu/qemu_domain.c | 25 ++++++++++++++++++++++---
src/qemu/qemu_driver.c | 2 +-
tests/domainsnapshotxml2xmltest.c | 2 +-
tests/qemuargv2xmltest.c | 2 +-
tests/qemumonitorjsontest.c | 2 +-
tests/qemuxml2argvtest.c | 2 +-
tests/qemuxml2xmltest.c | 2 +-
tests/qemuxmlnstest.c | 2 +-
tests/securityselinuxlabeltest.c | 2 +-
13 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 43ace12..5fd1bb5 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -164,7 +164,6 @@ struct _virCaps {
/* Move to virDomainXMLConf later */
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
unsigned int emulatorRequired : 1;
- const char *defaultDiskDriverName;
int defaultDiskDriverType; /* enum virStorageFileFormat */
int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch);
bool hasWideScsiBus;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1c41d4c..5d3b0c7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4829,11 +4829,6 @@ virDomainDiskDefParseXML(virCapsPtr caps,
def->format = caps->defaultDiskDriverType;
}
- if (!def->driverName &&
- caps->defaultDiskDriverName &&
- !(def->driverName = strdup(caps->defaultDiskDriverName)))
- goto no_memory;
-
if (mirrorFormat) {
def->mirrorFormat = virStorageFileFormatTypeFromString(mirrorFormat);
if (def->mirrorFormat <= 0) {
@@ -4896,9 +4891,6 @@ cleanup:
ctxt->node = save_ctxt;
return def;
-no_memory:
- virReportOOMError();
-
error:
virDomainDiskDefFree(def);
def = NULL;
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 128baf8..aab3375 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -552,8 +552,9 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr
driver)
}
virDomainXMLConfPtr
-virQEMUDriverCreateXMLConf(void)
+virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver)
{
+ virQEMUDriverDomainDefParserConfig.priv = driver;
return virDomainXMLConfNew(&virQEMUDriverDomainDefParserConfig,
&virQEMUDriverPrivateDataCallbacks,
&virQEMUDriverDomainXMLNamespace);
@@ -574,10 +575,8 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
goto no_memory;
if (cfg->allowDiskFormatProbing) {
- caps->defaultDiskDriverName = NULL;
caps->defaultDiskDriverType = VIR_STORAGE_FILE_AUTO;
} else {
- caps->defaultDiskDriverName = "qemu";
caps->defaultDiskDriverType = VIR_STORAGE_FILE_RAW;
}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index c5ddaad..4b917a7 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -301,6 +301,7 @@ void qemuSharedDiskEntryFree(void *payload, const void *name)
ATTRIBUTE_NONNULL(1);
int qemuDriverAllocateID(virQEMUDriverPtr driver);
-virDomainXMLConfPtr virQEMUDriverCreateXMLConf(void);
+virDomainXMLConfPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
+
#endif /* __QEMUD_CONF_H */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 20c370a..b1b50c9 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -666,19 +666,38 @@ static int
qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
virDomainDefPtr def ATTRIBUTE_UNUSED,
virCapsPtr caps ATTRIBUTE_UNUSED,
- void *opaque ATTRIBUTE_UNUSED)
+ void *opaque)
{
+ int ret = -1;
+ virQEMUDriverPtr driver = opaque;
+ virQEMUDriverConfigPtr cfg = NULL;
+
if (dev->type == VIR_DOMAIN_DEVICE_NET &&
dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
if (!dev->data.net->model &&
!(dev->data.net->model = strdup("rtl8139")))
goto no_memory;
}
- return 0;
+
+ if (dev->type == VIR_DOMAIN_DEVICE_DISK &&
+ !dev->data.disk->driverName &&
+ driver &&
+ (cfg = virQEMUDriverGetConfig(driver))) {
+ if (!cfg->allowDiskFormatProbing &&
+ !(dev->data.disk->driverName = strdup("qemu"))) {
+ goto no_memory;
+ }
+ }
+
+ ret = 0;
+
+cleanup:
+ virObjectUnref(cfg);
+ return ret;
no_memory:
virReportOOMError();
- return -1;
+ goto cleanup;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c1275b3..f187c97 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -723,7 +723,7 @@ qemuStartup(bool privileged,
if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == NULL)
goto error;
- if (!(qemu_driver->xmlconf = virQEMUDriverCreateXMLConf()))
+ if (!(qemu_driver->xmlconf = virQEMUDriverCreateXMLConf(qemu_driver)))
goto error;
/* If hugetlbfs is present, then we need to create a sub-directory within
diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c
index 7d95310..e6bd3a6 100644
--- a/tests/domainsnapshotxml2xmltest.c
+++ b/tests/domainsnapshotxml2xmltest.c
@@ -91,7 +91,7 @@ mymain(void)
if ((driver.caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
- if (!(driver.xmlconf = virQEMUDriverCreateXMLConf()))
+ if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver)))
return EXIT_FAILURE;
# define DO_TEST(name, uuid, internal) \
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index 6fd1de6..810bddd 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -120,7 +120,7 @@ mymain(void)
if ((driver.caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
- if (!(driver.xmlconf = virQEMUDriverCreateXMLConf()))
+ if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver)))
return EXIT_FAILURE;
# define DO_TEST_FULL(name, extraFlags, migrateFrom) \
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 639eeb1..d6f1d64 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -451,7 +451,7 @@ mymain(void)
#endif
if (virThreadInitialize() < 0 ||
- !(xmlconf = virQEMUDriverCreateXMLConf()))
+ !(xmlconf = virQEMUDriverCreateXMLConf(NULL)))
return EXIT_FAILURE;
virEventRegisterDefaultImpl();
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index db1b794..02d0213 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -294,7 +294,7 @@ mymain(void)
if ((driver.caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
- if (!(driver.xmlconf = virQEMUDriverCreateXMLConf()))
+ if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver)))
return EXIT_FAILURE;
VIR_FREE(driver.config->stateDir);
if ((driver.config->stateDir = strdup("/nowhere")) == NULL)
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index eb62409..8c7f6af 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -106,7 +106,7 @@ mymain(void)
if ((driver.caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
- if (!(driver.xmlconf = virQEMUDriverCreateXMLConf()))
+ if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver)))
return EXIT_FAILURE;
# define DO_TEST_FULL(name, is_different, when) \
diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c
index 7a5ac2c..15628dd 100644
--- a/tests/qemuxmlnstest.c
+++ b/tests/qemuxmlnstest.c
@@ -204,7 +204,7 @@ mymain(void)
driver.config = virQEMUDriverConfigNew(false);
if ((driver.caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
- if (!(driver.xmlconf = virQEMUDriverCreateXMLConf()))
+ if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver)))
return EXIT_FAILURE;
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0
||
cpuMapOverride(map) < 0) {
diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index e296e95..c132927 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -328,7 +328,7 @@ mymain(void)
if ((caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
- if (!(xmlconf = virQEMUDriverCreateXMLConf()))
+ if (!(xmlconf = virQEMUDriverCreateXMLConf(NULL)))
return EXIT_FAILURE;
#define DO_TEST_LABELING(name) \
--
1.8.1.5