[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v5.1 06/11] virCaps: get rid of defaultDiskDriverName



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.
---
 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 064da80..a3838e6 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -164,7 +164,6 @@ struct _virCaps {
     /* Move to virDomainXMLOption 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 8467424..1771c4d 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 7ee60d6..268223f 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -552,8 +552,9 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver)
 }

 virDomainXMLOptionPtr
-virQEMUDriverCreateXMLConf(void)
+virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver)
 {
+    virQEMUDriverDomainDefParserConfig.priv = driver;
     return virDomainXMLOptionNew(&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 12f74be..5299920 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);
-virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(void);
+virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
+

 #endif /* __QEMUD_CONF_H */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 80e70cd..2e7a986 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 1215fec..3f62414 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->xmlopt = virQEMUDriverCreateXMLConf()))
+    if (!(qemu_driver->xmlopt = 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 ac5137e..6f1c600 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.xmlopt = virQEMUDriverCreateXMLConf()))
+    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
         return EXIT_FAILURE;

 # define DO_TEST(name, uuid, internal)                                  \
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index ec250ad..9167d88 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.xmlopt = virQEMUDriverCreateXMLConf()))
+    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
         return EXIT_FAILURE;

 # define DO_TEST_FULL(name, extraFlags, migrateFrom)                     \
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index fdf67a1..24685c7 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -451,7 +451,7 @@ mymain(void)
 #endif

     if (virThreadInitialize() < 0 ||
-        !(xmlopt = virQEMUDriverCreateXMLConf()))
+        !(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
         return EXIT_FAILURE;

     virEventRegisterDefaultImpl();
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 7a63e90..099fb36 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.xmlopt = virQEMUDriverCreateXMLConf()))
+    if (!(driver.xmlopt = 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 8f892d1..aa058bd 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.xmlopt = virQEMUDriverCreateXMLConf()))
+    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
         return EXIT_FAILURE;

 # define DO_TEST_FULL(name, is_different, when)                         \
diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c
index dadf40c..e6b42dc 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.xmlopt = virQEMUDriverCreateXMLConf()))
+    if (!(driver.xmlopt = 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 c595f9b..f585f6f 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -328,7 +328,7 @@ mymain(void)
     if ((caps = testQemuCapsInit()) == NULL)
         return EXIT_FAILURE;

-    if (!(xmlopt = virQEMUDriverCreateXMLConf()))
+    if (!(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
         return EXIT_FAILURE;

 #define DO_TEST_LABELING(name) \
-- 
1.8.1.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]