[PATCH v4 1/3] Add a privileged field to storageDriverState

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

 



Use the privileged value in order to generate a connection which could
be passed to the various storage backend drivers.

In particular, the iSCSI driver will need a connect in order to perform
pool authentication using the 'chap' secrets.  Additionally, the RBD backend
utilizes the connection during pool refresh for pools using 'ceph' secrets.
---
 src/conf/storage_conf.h      |  1 +
 src/storage/storage_driver.c | 19 +++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index fd9b2e7..62ff1fd 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -354,6 +354,7 @@ struct _virStorageDriverState {
 
     char *configDir;
     char *autostartDir;
+    bool privileged;
 };
 
 typedef struct _virStoragePoolSourceList virStoragePoolSourceList;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index a8eb731..f38acef 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -68,6 +68,13 @@ static void storageDriverUnlock(virStorageDriverStatePtr driver)
 static void
 storageDriverAutostart(virStorageDriverStatePtr driver) {
     size_t i;
+    virConnectPtr conn = NULL;
+
+    if (driverState->privileged)
+        conn = virConnectOpen("qemu:///system");
+    else
+        conn = virConnectOpen("qemu:///session");
+    /* Ignoring NULL conn - let backends decide */
 
     for (i = 0; i < driver->pools.count; i++) {
         virStoragePoolObjPtr pool = driver->pools.objs[i];
@@ -82,7 +89,7 @@ storageDriverAutostart(virStorageDriverStatePtr driver) {
         }
 
         if (backend->checkPool &&
-            backend->checkPool(NULL, pool, &started) < 0) {
+            backend->checkPool(conn, pool, &started) < 0) {
             virErrorPtr err = virGetLastError();
             VIR_ERROR(_("Failed to initialize storage pool '%s': %s"),
                       pool->def->name, err ? err->message :
@@ -95,7 +102,7 @@ storageDriverAutostart(virStorageDriverStatePtr driver) {
             pool->autostart &&
             !virStoragePoolObjIsActive(pool)) {
             if (backend->startPool &&
-                backend->startPool(NULL, pool) < 0) {
+                backend->startPool(conn, pool) < 0) {
                 virErrorPtr err = virGetLastError();
                 VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
                           pool->def->name, err ? err->message :
@@ -107,10 +114,10 @@ storageDriverAutostart(virStorageDriverStatePtr driver) {
         }
 
         if (started) {
-            if (backend->refreshPool(NULL, pool) < 0) {
+            if (backend->refreshPool(conn, pool) < 0) {
                 virErrorPtr err = virGetLastError();
                 if (backend->stopPool)
-                    backend->stopPool(NULL, pool);
+                    backend->stopPool(conn, pool);
                 VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
                           pool->def->name, err ? err->message :
                           _("no error message found"));
@@ -121,6 +128,9 @@ storageDriverAutostart(virStorageDriverStatePtr driver) {
         }
         virStoragePoolObjUnlock(pool);
     }
+
+    if (conn)
+        virConnectClose(conn);
 }
 
 /**
@@ -152,6 +162,7 @@ storageStateInitialize(bool privileged,
         if (!base)
             goto error;
     }
+    driverState->privileged = privileged;
 
     /* Configuration paths are either $USER_CONFIG_HOME/libvirt/storage/... (session) or
      * /etc/libvirt/storage/... (system).
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]