mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-05 16:33:50 +00:00
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:
parent
2e5ad5881b
commit
adfcbdff91
@ -196,6 +196,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
|
|||||||
|
|
||||||
if (virISCSIScanTargets(portal,
|
if (virISCSIScanTargets(portal,
|
||||||
source->initiator.iqn,
|
source->initiator.iqn,
|
||||||
|
false,
|
||||||
&ntargets, &targets) < 0)
|
&ntargets, &targets) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ VIR_LOG_INIT("util.iscsi");
|
|||||||
static int
|
static int
|
||||||
virISCSIScanTargetsInternal(const char *portal,
|
virISCSIScanTargetsInternal(const char *portal,
|
||||||
const char *ifacename,
|
const char *ifacename,
|
||||||
|
bool persist,
|
||||||
size_t *ntargetsret,
|
size_t *ntargetsret,
|
||||||
char ***targetsret);
|
char ***targetsret);
|
||||||
|
|
||||||
@ -294,9 +295,11 @@ virISCSIConnection(const char *portal,
|
|||||||
* unless you've first issued a 'sendtargets' command to the
|
* unless you've first issued a 'sendtargets' command to the
|
||||||
* portal. Without the sendtargets all that is received is a
|
* portal. Without the sendtargets all that is received is a
|
||||||
* "iscsiadm: No records found". However, we must ensure that
|
* "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;
|
goto cleanup;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -382,6 +385,7 @@ virISCSIGetTargets(char **const groups,
|
|||||||
static int
|
static int
|
||||||
virISCSIScanTargetsInternal(const char *portal,
|
virISCSIScanTargetsInternal(const char *portal,
|
||||||
const char *ifacename,
|
const char *ifacename,
|
||||||
|
bool persist,
|
||||||
size_t *ntargetsret,
|
size_t *ntargetsret,
|
||||||
char ***targetsret)
|
char ***targetsret)
|
||||||
{
|
{
|
||||||
@ -406,9 +410,14 @@ virISCSIScanTargetsInternal(const char *portal,
|
|||||||
"--mode", "discovery",
|
"--mode", "discovery",
|
||||||
"--type", "sendtargets",
|
"--type", "sendtargets",
|
||||||
"--portal", portal,
|
"--portal", portal,
|
||||||
"--op", "nonpersistent",
|
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
if (!persist) {
|
||||||
|
virCommandAddArgList(cmd,
|
||||||
|
"--op", "nonpersistent",
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (ifacename) {
|
if (ifacename) {
|
||||||
virCommandAddArgList(cmd,
|
virCommandAddArgList(cmd,
|
||||||
"--interface", ifacename,
|
"--interface", ifacename,
|
||||||
@ -445,6 +454,7 @@ virISCSIScanTargetsInternal(const char *portal,
|
|||||||
* virISCSIScanTargets:
|
* virISCSIScanTargets:
|
||||||
* @portal: iSCSI portal
|
* @portal: iSCSI portal
|
||||||
* @initiatoriqn: Initiator IQN
|
* @initiatoriqn: Initiator IQN
|
||||||
|
* @persists: whether scanned targets should be saved
|
||||||
* @ntargets: number of items in @targetsret array
|
* @ntargets: number of items in @targetsret array
|
||||||
* @targets: array of targets
|
* @targets: array of targets
|
||||||
*
|
*
|
||||||
@ -453,12 +463,16 @@ virISCSIScanTargetsInternal(const char *portal,
|
|||||||
* The targets are stored into @targets array and the size of
|
* The targets are stored into @targets array and the size of
|
||||||
* the array is stored into @ntargets.
|
* 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,
|
* Returns: 0 on success,
|
||||||
* -1 otherwise (with error reported)
|
* -1 otherwise (with error reported)
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virISCSIScanTargets(const char *portal,
|
virISCSIScanTargets(const char *portal,
|
||||||
const char *initiatoriqn,
|
const char *initiatoriqn,
|
||||||
|
bool persist,
|
||||||
size_t *ntargets,
|
size_t *ntargets,
|
||||||
char ***targets)
|
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);
|
VIR_FREE(ifacename);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ virISCSIRescanLUNs(const char *session)
|
|||||||
int
|
int
|
||||||
virISCSIScanTargets(const char *portal,
|
virISCSIScanTargets(const char *portal,
|
||||||
const char *initiatoriqn,
|
const char *initiatoriqn,
|
||||||
|
bool persist,
|
||||||
size_t *ntargetsret,
|
size_t *ntargetsret,
|
||||||
char ***targetsret)
|
char ***targetsret)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
@ -145,7 +145,8 @@ testISCSIScanTargets(const void *data)
|
|||||||
|
|
||||||
virCommandSetDryRun(NULL, testIscsiadmCb, NULL);
|
virCommandSetDryRun(NULL, testIscsiadmCb, NULL);
|
||||||
|
|
||||||
if (virISCSIScanTargets(info->portal, NULL, &ntargets, &targets) < 0)
|
if (virISCSIScanTargets(info->portal, NULL,
|
||||||
|
false, &ntargets, &targets) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (info->nexpected != ntargets) {
|
if (info->nexpected != ntargets) {
|
||||||
|
Loading…
Reference in New Issue
Block a user