]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Add source pool auth info to virDomainDiskDef for iSCSI
authorJohn Ferlan <jferlan@redhat.com>
Fri, 19 Jul 2013 18:38:45 +0000 (14:38 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 23 Jul 2013 14:49:02 +0000 (10:49 -0400)
During qemuTranslateDiskSourcePool() execution, if the srcpool has been
defined with authentication information, then for iSCSI pools copy the
authentication and host information to virDomainDiskDef.

src/qemu/qemu_conf.c

index 6e6163f677a51a6d815f794e342c5b36b29dcac1..3e7b78a30fbabe5fbed54c5f346af95c7fe0dc62 100644 (file)
@@ -1186,6 +1186,58 @@ cleanup:
     return ret;
 }
 
+static int
+qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def,
+                                virStoragePoolDefPtr pooldef)
+{
+    int ret = -1;
+
+    /* Only necessary when authentication set */
+    if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_NONE) {
+        ret = 0;
+        goto cleanup;
+    }
+
+    /* Copy the authentication information from the storage pool
+     * into the virDomainDiskDef
+     */
+    if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
+        if (VIR_STRDUP(def->auth.username,
+                       pooldef->source.auth.chap.username) < 0)
+            goto cleanup;
+        if (pooldef->source.auth.chap.secret.uuidUsable) {
+            def->auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_UUID;
+            memcpy(def->auth.secret.uuid,
+                   pooldef->source.auth.chap.secret.uuid,
+                   VIR_UUID_BUFLEN);
+        } else {
+            if (VIR_STRDUP(def->auth.secret.usage,
+                           pooldef->source.auth.chap.secret.usage) < 0)
+                goto cleanup;
+            def->auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_USAGE;
+        }
+    } else if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_CEPHX) {
+        if (VIR_STRDUP(def->auth.username,
+                       pooldef->source.auth.cephx.username) < 0)
+            goto cleanup;
+        if (pooldef->source.auth.cephx.secret.uuidUsable) {
+            def->auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_UUID;
+            memcpy(def->auth.secret.uuid,
+                   pooldef->source.auth.cephx.secret.uuid,
+                   VIR_UUID_BUFLEN);
+        } else {
+            if (VIR_STRDUP(def->auth.secret.usage,
+                           pooldef->source.auth.cephx.secret.usage) < 0)
+                goto cleanup;
+            def->auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_USAGE;
+        }
+    }
+    ret = 0;
+
+cleanup:
+    return ret;
+}
+
 int
 qemuTranslateDiskSourcePool(virConnectPtr conn,
                             virDomainDiskDefPtr def)
@@ -1254,6 +1306,9 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
                 if (!(def->src = virStorageVolGetPath(vol)))
                     goto cleanup;
             }
+
+            if (qemuTranslateDiskSourcePoolAuth(def, pooldef) < 0)
+                goto cleanup;
         } else {
             if (!(def->src = virStorageVolGetPath(vol)))
                 goto cleanup;