]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Add connection for autostart storage pool
authorJohn Ferlan <jferlan@redhat.com>
Mon, 15 Jul 2013 20:26:10 +0000 (16:26 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 23 Jul 2013 16:56:10 +0000 (12:56 -0400)
Add a privileged field to storageDriverState

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 and the RBD driver utilizes
the connection during pool refresh for pools using 'ceph' secrets.

For now that connection will be to be to qemu driver until a mechanism
is devised to get a connection to just the secret driver without qemu.

src/conf/storage_conf.h
src/storage/storage_driver.c

index fd9b2e76276e1c12a61623a7ccd2634bf5d1c56b..62ff1fd93e232c7d2f2a187c245324e623e0f0dd 100644 (file)
@@ -354,6 +354,7 @@ struct _virStorageDriverState {
 
     char *configDir;
     char *autostartDir;
+    bool privileged;
 };
 
 typedef struct _virStoragePoolSourceList virStoragePoolSourceList;
index 43bf6dece5f19b48be6a128f0c9d563202424303..4f0c63182c88f7d0d2d2784a8fd06d4454862589 100644 (file)
@@ -68,6 +68,14 @@ static void storageDriverUnlock(virStorageDriverStatePtr driver)
 static void
 storageDriverAutostart(virStorageDriverStatePtr driver) {
     size_t i;
+    virConnectPtr conn = NULL;
+
+    /* XXX Remove hardcoding of QEMU URI */
+    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 +90,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 +103,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 +115,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 +129,9 @@ storageDriverAutostart(virStorageDriverStatePtr driver) {
         }
         virStoragePoolObjUnlock(pool);
     }
+
+    if (conn)
+        virConnectClose(conn);
 }
 
 /**
@@ -152,6 +163,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).