virISCSIScanTargets: Allow making targets persistent

After a new iSCSI interface is successfully set up, we issue a
sendtargets command. However, after 56057900dc 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>
This commit is contained in:
Michal Privoznik 2018-06-29 16:18:23 +02:00
parent 2e5ad5881b
commit adfcbdff91
4 changed files with 23 additions and 5 deletions

View File

@ -196,6 +196,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
if (virISCSIScanTargets(portal,
source->initiator.iqn,
false,
&ntargets, &targets) < 0)
goto cleanup;

View 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;
}

View 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;

View 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) {