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

[libvirt] [PATCH v1 1/2] change qemu_driver's qemuImgBinary field



qemuImgBinary is a poor name, change to qemuImgTool,
and init it at qemu driver start-up phase, before this
change, if we need qemu-img or kvm-img we have to call
qemuFindQemuImgBinary every time, seems a little boring,
from then on, we can use qemuImgTool directly,
e.g.
use virCommandRun(driver->qemuImgTool, ...)
instead of
img_tool = qemuFindQemuImgBinary(driver);
qemuFindQemuImgBinary(img_tool, ...);

Signed-off-by: liguang <lig fnst cn fujitsu com>
---
 src/qemu/qemu_conf.h   |    2 +-
 src/qemu/qemu_domain.c |   22 ++--------------------
 src/qemu/qemu_domain.h |    2 --
 src/qemu/qemu_driver.c |   12 ++++++++++--
 4 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 2c7f70c..47f349c 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -84,7 +84,7 @@ struct qemud_driver {
     char *cacheDir;
     char *saveDir;
     char *snapshotDir;
-    char *qemuImgBinary;
+    char *qemuImgTool;
     unsigned int vncAutoUnixSocket : 1;
     unsigned int vncTLS : 1;
     unsigned int vncTLSx509verify : 1;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e0d6951..97e4fa1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1588,22 +1588,6 @@ cleanup:
     return ret;
 }
 
-/* Locate an appropriate 'qemu-img' binary.  */
-const char *
-qemuFindQemuImgBinary(struct qemud_driver *driver)
-{
-    if (!driver->qemuImgBinary) {
-        driver->qemuImgBinary = virFindFileInPath("kvm-img");
-        if (!driver->qemuImgBinary)
-            driver->qemuImgBinary = virFindFileInPath("qemu-img");
-        if (!driver->qemuImgBinary)
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           "%s", _("unable to find kvm-img or qemu-img"));
-    }
-
-    return driver->qemuImgBinary;
-}
-
 int
 qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                 virDomainSnapshotObjPtr snapshot,
@@ -1659,11 +1643,9 @@ qemuDomainSnapshotForEachQcow2Raw(struct qemud_driver *driver,
     int i;
     bool skipped = false;
 
-    qemuimgarg[0] = qemuFindQemuImgBinary(driver);
-    if (qemuimgarg[0] == NULL) {
-        /* qemuFindQemuImgBinary set the error */
+    qemuimgarg[0] = driver->qemuImgTool;
+    if (qemuimgarg[0] == NULL)
         return -1;
-    }
 
     qemuimgarg[2] = op;
     qemuimgarg[3] = name;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index a2acc0a..548cd20 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -300,8 +300,6 @@ int qemuDomainAppendLog(struct qemud_driver *driver,
                         int logFD,
                         const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(4, 5);
 
-const char *qemuFindQemuImgBinary(struct qemud_driver *driver);
-
 int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
                                     virDomainSnapshotObjPtr snapshot,
                                     char *snapshotDir);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 436e853..e87e7b4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -643,6 +643,14 @@ qemudStartup(int privileged) {
     if (!qemu_driver->domainEventState)
         goto error;
 
+    /* find kvm-img or qemu-img */
+    qemu_driver->qemuImgTool = virFindFileInPath("kvm-img");
+    if (!qemu_driver->qemuImgTool)
+        qemu_driver->qemuImgTool = virFindFileInPath("qemu-img");
+    if (!qemu_driver->qemuImgTool)
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("unable to find kvm-img or qemu-img"));
+
     /* read the host sysinfo */
     if (privileged)
         qemu_driver->hostsysinfo = virSysinfoRead();
@@ -1029,7 +1037,7 @@ qemudShutdown(void) {
     VIR_FREE(qemu_driver->cacheDir);
     VIR_FREE(qemu_driver->saveDir);
     VIR_FREE(qemu_driver->snapshotDir);
-    VIR_FREE(qemu_driver->qemuImgBinary);
+    VIR_FREE(qemu_driver->qemuImgTool);
     VIR_FREE(qemu_driver->autoDumpPath);
     VIR_FREE(qemu_driver->vncTLSx509certdir);
     VIR_FREE(qemu_driver->vncListen);
@@ -10706,7 +10714,7 @@ qemuDomainSnapshotCreateInactiveExternal(struct qemud_driver *driver,
 
     int ret = -1;
 
-    if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
+    if (!(qemuImgPath = driver->qemuImgTool))
         return -1;
 
     if (!(created = virBitmapNew(snap->def->ndisks))) {
-- 
1.7.1


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