]> xenbits.xensource.com Git - libvirt.git/commitdiff
virISCSIScanTargets: Allow making targets persistent
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 29 Jun 2018 14:18:23 +0000 (16:18 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 25 Jul 2018 05:11:13 +0000 (07:11 +0200)
After a new iSCSI interface is successfully set up, we issue a
sendtargets command. However, after 56057900dc53df490d we don't
update the host config which in turn makes login fail because
iscsiadm is unable to find any matching record for the interface.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/storage/storage_backend_iscsi.c
src/util/viriscsi.c
src/util/viriscsi.h
tests/viriscsitest.c

index 3b9dddb4fdd4536b5b501084efd84319ca3c9990..6242cd0fac26b2b4fab6d4b0c9c64a8685b5cea1 100644 (file)
@@ -196,6 +196,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
 
     if (virISCSIScanTargets(portal,
                             source->initiator.iqn,
+                            false,
                             &ntargets, &targets) < 0)
         goto cleanup;
 
index 549f75b4344984252ab7ef16ee2c5c9627c55539..e2c80acaaa9c794ad215f17b2274f1d5d93a647a 100644 (file)
@@ -43,6 +43,7 @@ VIR_LOG_INIT("util.iscsi");
 static int
 virISCSIScanTargetsInternal(const char *portal,
                             const char *ifacename,
+                            bool persist,
                             size_t *ntargetsret,
                             char ***targetsret);
 
@@ -294,9 +295,11 @@ virISCSIConnection(const char *portal,
              * unless you've first issued a 'sendtargets' command to the
              * portal. Without the sendtargets all that is received is a
              * "iscsiadm: No records found". However, we must ensure that
-             * the command is issued over interface name we invented above.
+             * the command is issued over interface name we invented above
+             * and that targets are made persistent.
              */
-            if (virISCSIScanTargetsInternal(portal, ifacename, NULL, NULL) < 0)
+            if (virISCSIScanTargetsInternal(portal, ifacename,
+                                            true, NULL, NULL) < 0)
                 goto cleanup;
 
             break;
@@ -382,6 +385,7 @@ virISCSIGetTargets(char **const groups,
 static int
 virISCSIScanTargetsInternal(const char *portal,
                             const char *ifacename,
+                            bool persist,
                             size_t *ntargetsret,
                             char ***targetsret)
 {
@@ -406,9 +410,14 @@ virISCSIScanTargetsInternal(const char *portal,
                                              "--mode", "discovery",
                                              "--type", "sendtargets",
                                              "--portal", portal,
-                                             "--op", "nonpersistent",
                                              NULL);
 
+    if (!persist) {
+        virCommandAddArgList(cmd,
+                             "--op", "nonpersistent",
+                             NULL);
+    }
+
     if (ifacename) {
         virCommandAddArgList(cmd,
                              "--interface", ifacename,
@@ -445,6 +454,7 @@ virISCSIScanTargetsInternal(const char *portal,
  * virISCSIScanTargets:
  * @portal: iSCSI portal
  * @initiatoriqn: Initiator IQN
+ * @persists: whether scanned targets should be saved
  * @ntargets: number of items in @targetsret array
  * @targets: array of targets
  *
@@ -453,12 +463,16 @@ virISCSIScanTargetsInternal(const char *portal,
  * The targets are stored into @targets array and the size of
  * the array is stored into @ntargets.
  *
+ * If @persist is true, then targets returned by iSCSI portal are
+ * made persistent on the host (their config is saved).
+ *
  * Returns: 0 on success,
  *         -1 otherwise (with error reported)
  */
 int
 virISCSIScanTargets(const char *portal,
                     const char *initiatoriqn,
+                    bool persist,
                     size_t *ntargets,
                     char ***targets)
 {
@@ -486,7 +500,8 @@ virISCSIScanTargets(const char *portal,
         }
     }
 
-    ret = virISCSIScanTargetsInternal(portal, ifacename, ntargets, targets);
+    ret = virISCSIScanTargetsInternal(portal, ifacename,
+                                      persist, ntargets, targets);
     VIR_FREE(ifacename);
     return ret;
 }
index 31b589dbf9e9b4380d2951f089a497f533039315..4da9becfb2a72775195154333f2868872dbd6349 100644 (file)
@@ -50,6 +50,7 @@ virISCSIRescanLUNs(const char *session)
 int
 virISCSIScanTargets(const char *portal,
                     const char *initiatoriqn,
+                    bool persist,
                     size_t *ntargetsret,
                     char ***targetsret)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
index 4bdb782e3613ddc44401af0d292b315c3931a2cb..3bb39931963befaddd6730eb7c7f3048cdf22e7a 100644 (file)
@@ -145,7 +145,8 @@ testISCSIScanTargets(const void *data)
 
     virCommandSetDryRun(NULL, testIscsiadmCb, NULL);
 
-    if (virISCSIScanTargets(info->portal, NULL, &ntargets, &targets) < 0)
+    if (virISCSIScanTargets(info->portal, NULL,
+                            false, &ntargets, &targets) < 0)
         goto cleanup;
 
     if (info->nexpected != ntargets) {