[libvirt] [PATCH 03/11] Stop iSCSI targets automatically logging back in after logout

Eric Blake eblake at redhat.com
Fri Nov 19 18:09:31 UTC 2010


On 11/12/2010 09:22 AM, Daniel P. Berrange wrote:
> The Linux iSCSI initiator toolchain has the dubious feature that
> if you ever run the 'sendtargets' command to merely query what
> targets are available from a server, the results will be recorded
> in /var/lib/iscsi. Any time the '/etc/init.d/iscsi' script runs
> in the future, it will then automatically login to all those
> targets. /etc/init.d/iscsi is automatically run whenever a NIC
> comes online.

Is that worth reporting as a bug in the iscsi toolchain?  At any rate,
we need this patch whether or not that tool changes behavior to
something more sane.  However, I'm not sure this is ready for ack
without answers to some questions first:

> To stop this stupid behaviour, we need to run
> 
>   iscsiadm --portal $PORTAL --target $TARGET
>    --op update --name node.startup --value manual
> 

> +static int
> +virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
> +                                 char **const groups,
> +                                 void *data)
> +{
> +    struct virStorageBackendISCSITargetList *list = data;
> +    char *target;
> +
> +    if (!(target = strdup(groups[1]))) {
> +        virReportOOMError();
> +        return -1;
> +    }
> +
> +    if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) {

Up to you if you want to rebase this to use VIR_RESIZE_N (or
VIR_EXPAND_N), or to just leave that to me as a subsequent followup
patch (I'm already searching through the code base for other instances
to convert; one more won't hurt me).

>  static int
> -virStorageBackendISCSIScanTargets(const char *portal)
> +virStorageBackendISCSIScanTargets(const char *portal,
> +                                  const char *initiatoriqn,
> +                                  size_t *ntargetsret,
> +                                  char ***targetsret)
>  {
> -    const char *const sendtargets[] = {
> -        ISCSIADM, "--mode", "discovery", "--type", "sendtargets", "--portal", portal, NULL
> +    /**
> +     *
> +     * The output of sendtargets is very simple, just two columns,
> +     * portal then target name
> +     *
> +     * 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo0.bf6d84
> +     * 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo1.bf6d84
> +     * 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo2.bf6d84
> +     * 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo3.bf6d84
> +     */
> +    const char *regexes[] = {
> +        "^\\s*(\\S+)\\s+(\\S+)\\s*$"

\s and \S are GNU-isms, and regcomp() on other platforms will reject it;
is this regex only used on Linux, or do we need to be portable to iscsi
implementations on other platforms?

> +    };
> +    int vars[] = { 2 };
> +    const char *const cmdsendtarget[] = {
> +        ISCSIADM, "--mode", "discovery", "--type", "sendtargets",
> +        "--portal", portal, NULL
>      };
> -    if (virRun(sendtargets, NULL) < 0) {
> +    struct virStorageBackendISCSITargetList list;
> +    int i;
> +    int exitstatus;
> +
> +    memset(&list, 0, sizeof(list));
> +
> +    if (virStorageBackendRunProgRegex(NULL, /* No pool for callback */
> +                                      cmdsendtarget,
> +                                      1,
> +                                      regexes,
> +                                      vars,
> +                                      virStorageBackendISCSIGetTargets,
> +                                      &list,
> +                                      &exitstatus) < 0) {
>          virStorageReportError(VIR_ERR_INTERNAL_ERROR,
> -                              _("Failed to run %s to get target list"),
> -                              sendtargets[0]);
> +                              "%s", _("lvs command failed"));

Should this message be about iscsiadm rather than lvs?

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20101119/49cf331e/attachment-0001.sig>


More information about the libvir-list mailing list