From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696252201416.56466267281155; Wed, 4 Jul 2018 02:24:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7EFF8553F; Wed, 4 Jul 2018 09:24:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06C4F1001F3D; Wed, 4 Jul 2018 09:24:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E7BB31800CAD; Wed, 4 Jul 2018 09:24:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O4tK000734 for ; Wed, 4 Jul 2018 05:24:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5FD22178BD; Wed, 4 Jul 2018 09:24:04 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id E519C7C5D for ; Wed, 4 Jul 2018 09:24:03 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:35 +0200 Message-Id: <5a1677af913c6f5b1f76086f1a91357ffc82dafe.1530695759.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/10] virStorageBackendIQNFound: Fix ret value assignment X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Jul 2018 09:24:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Perform some method clean-up to follow more accepted coding standards: * Initialize @ret to error value and prove otherwise. * Initialize *ifacename to NULL Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/util/viriscsi.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index d4c745a1af..ad857f8cac 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -117,15 +117,16 @@ static int virStorageBackendIQNFound(const char *initiatoriqn, char **ifacename) { - int ret =3D IQN_MISSING, fd =3D -1; + int ret =3D IQN_ERROR, fd =3D -1; char ebuf[64]; FILE *fp =3D NULL; char *line =3D NULL, *newline =3D NULL, *iqn =3D NULL, *token =3D NULL; virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); =20 + *ifacename =3D NULL; + if (VIR_ALLOC_N(line, LINE_SIZE) !=3D 0) { - ret =3D IQN_ERROR; virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not allocate memory for output of '%s'"), ISCSIADM); @@ -135,24 +136,20 @@ virStorageBackendIQNFound(const char *initiatoriqn, memset(line, 0, LINE_SIZE); =20 virCommandSetOutputFD(cmd, &fd); - if (virCommandRunAsync(cmd, NULL) < 0) { - ret =3D IQN_ERROR; + if (virCommandRunAsync(cmd, NULL) < 0) goto out; - } =20 if ((fp =3D VIR_FDOPEN(fd, "r")) =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open stream for file descriptor " "when reading output from '%s': '%s'"), ISCSIADM, virStrerror(errno, ebuf, sizeof(ebuf))); - ret =3D IQN_ERROR; goto out; } =20 while (fgets(line, LINE_SIZE, fp) !=3D NULL) { newline =3D strrchr(line, '\n'); if (newline =3D=3D NULL) { - ret =3D IQN_ERROR; virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected line > %d characters " "when parsing output of '%s'"), @@ -169,24 +166,24 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (STREQ(iqn, initiatoriqn)) { token =3D strchr(line, ' '); if (!token) { - ret =3D IQN_ERROR; virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing space when parsing output " "of '%s'"), ISCSIADM); goto out; } - if (VIR_STRNDUP(*ifacename, line, token - line) < 0) { - ret =3D IQN_ERROR; + + if (VIR_STRNDUP(*ifacename, line, token - line) < 0) goto out; - } + VIR_DEBUG("Found interface '%s' with IQN '%s'", *ifacename, iq= n); - ret =3D IQN_FOUND; break; } } =20 if (virCommandWait(cmd, NULL) < 0) - ret =3D IQN_ERROR; + goto out; + + ret =3D *ifacename ? IQN_FOUND : IQN_MISSING; =20 out: if (ret =3D=3D IQN_MISSING) --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696252714414.7231197628747; Wed, 4 Jul 2018 02:24:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 107EC4E4EE; Wed, 4 Jul 2018 09:24:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B01258C9D5; Wed, 4 Jul 2018 09:24:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5413D1800CAC; Wed, 4 Jul 2018 09:24:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O5CU000739 for ; Wed, 4 Jul 2018 05:24:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21104178BD; Wed, 4 Jul 2018 09:24:05 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id A71627C5D for ; Wed, 4 Jul 2018 09:24:04 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:36 +0200 Message-Id: <6fec379e41c10252766a98832b4aad3dd3eaf35b.1530695759.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 02/10] virStorageBackendIQNFound: Rename out label X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 04 Jul 2018 09:24:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is in fact 'cleanup' label and it should be named as such. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/util/viriscsi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index ad857f8cac..01b5b4be68 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -130,21 +130,21 @@ virStorageBackendIQNFound(const char *initiatoriqn, virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not allocate memory for output of '%s'"), ISCSIADM); - goto out; + goto cleanup; } =20 memset(line, 0, LINE_SIZE); =20 virCommandSetOutputFD(cmd, &fd); if (virCommandRunAsync(cmd, NULL) < 0) - goto out; + goto cleanup; =20 if ((fp =3D VIR_FDOPEN(fd, "r")) =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open stream for file descriptor " "when reading output from '%s': '%s'"), ISCSIADM, virStrerror(errno, ebuf, sizeof(ebuf))); - goto out; + goto cleanup; } =20 while (fgets(line, LINE_SIZE, fp) !=3D NULL) { @@ -154,7 +154,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, _("Unexpected line > %d characters " "when parsing output of '%s'"), LINE_SIZE, ISCSIADM); - goto out; + goto cleanup; } *newline =3D '\0'; =20 @@ -169,11 +169,11 @@ virStorageBackendIQNFound(const char *initiatoriqn, virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing space when parsing output " "of '%s'"), ISCSIADM); - goto out; + goto cleanup; } =20 if (VIR_STRNDUP(*ifacename, line, token - line) < 0) - goto out; + goto cleanup; =20 VIR_DEBUG("Found interface '%s' with IQN '%s'", *ifacename, iq= n); break; @@ -181,11 +181,11 @@ virStorageBackendIQNFound(const char *initiatoriqn, } =20 if (virCommandWait(cmd, NULL) < 0) - goto out; + goto cleanup; =20 ret =3D *ifacename ? IQN_FOUND : IQN_MISSING; =20 - out: + cleanup: if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153069627133594.39383242744577; Wed, 4 Jul 2018 02:24:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F1DA4901F; Wed, 4 Jul 2018 09:24:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB33D309128B; Wed, 4 Jul 2018 09:24:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 955444A46C; Wed, 4 Jul 2018 09:24:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O5gu000750 for ; Wed, 4 Jul 2018 05:24:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8F41178BD; Wed, 4 Jul 2018 09:24:05 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67DE37C5D for ; Wed, 4 Jul 2018 09:24:05 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:37 +0200 Message-Id: <53144a2fe12d3e0e938d97aed4eafa9fff3d0441.1530695759.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/10] virStorageBackendIQNFound: Rework iscsiadm output parsing X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 04 Jul 2018 09:24:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Firstly, we can utilize virCommandSetOutputBuffer() API which will collect the command output for us. Secondly, sscanf()-ing through each line is easier to understand (and more robust) than jumping over a string with strchr(). Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/util/viriscsi.c | 85 +++++++++++++++++++++----------------------------= ---- 1 file changed, 34 insertions(+), 51 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 01b5b4be68..1ddf00aa4c 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -108,7 +108,6 @@ virISCSIGetSession(const char *devpath, =20 =20 =20 -#define LINE_SIZE 4096 #define IQN_FOUND 1 #define IQN_MISSING 0 #define IQN_ERROR -1 @@ -117,71 +116,56 @@ static int virStorageBackendIQNFound(const char *initiatoriqn, char **ifacename) { - int ret =3D IQN_ERROR, fd =3D -1; - char ebuf[64]; - FILE *fp =3D NULL; - char *line =3D NULL, *newline =3D NULL, *iqn =3D NULL, *token =3D NULL; + int ret =3D IQN_ERROR; + char *outbuf =3D NULL; + char *line =3D NULL; + char *iface =3D NULL; + char *iqn =3D NULL; virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); =20 *ifacename =3D NULL; =20 - if (VIR_ALLOC_N(line, LINE_SIZE) !=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not allocate memory for output of '%s'"), - ISCSIADM); + virCommandSetOutputBuffer(cmd, &outbuf); + if (virCommandRun(cmd, NULL) < 0) goto cleanup; - } =20 - memset(line, 0, LINE_SIZE); + /* Example of data we are dealing with: + * default tcp,,,, + * iser iser,,,, + * libvirt-iface-253db048 tcp,,,,iqn.2017-03.com.= user:client + */ =20 - virCommandSetOutputFD(cmd, &fd); - if (virCommandRunAsync(cmd, NULL) < 0) - goto cleanup; + line =3D outbuf; + while (line && *line) { + char *newline; + int num; =20 - if ((fp =3D VIR_FDOPEN(fd, "r")) =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to open stream for file descriptor " - "when reading output from '%s': '%s'"), - ISCSIADM, virStrerror(errno, ebuf, sizeof(ebuf))); - goto cleanup; - } + if (!(newline =3D strchr(line, '\n'))) + break; =20 - while (fgets(line, LINE_SIZE, fp) !=3D NULL) { - newline =3D strrchr(line, '\n'); - if (newline =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected line > %d characters " - "when parsing output of '%s'"), - LINE_SIZE, ISCSIADM); - goto cleanup; - } *newline =3D '\0'; =20 - iqn =3D strrchr(line, ','); - if (iqn =3D=3D NULL) - continue; - iqn++; + VIR_FREE(iface); + VIR_FREE(iqn); + num =3D sscanf(line, "%ms %*[^,],%*[^,],%*[^,],%*[^,],%ms", &iface= , &iqn); + + if (num !=3D 2) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("malformed output of %s: %s"), + ISCSIADM, line); + goto cleanup; + } =20 if (STREQ(iqn, initiatoriqn)) { - token =3D strchr(line, ' '); - if (!token) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing space when parsing output " - "of '%s'"), ISCSIADM); - goto cleanup; - } - - if (VIR_STRNDUP(*ifacename, line, token - line) < 0) - goto cleanup; + VIR_STEAL_PTR(*ifacename, iface); =20 VIR_DEBUG("Found interface '%s' with IQN '%s'", *ifacename, iq= n); break; } - } =20 - if (virCommandWait(cmd, NULL) < 0) - goto cleanup; + line =3D newline + 1; + } =20 ret =3D *ifacename ? IQN_FOUND : IQN_MISSING; =20 @@ -189,11 +173,10 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 - VIR_FREE(line); - VIR_FORCE_FCLOSE(fp); - VIR_FORCE_CLOSE(fd); + VIR_FREE(iqn); + VIR_FREE(iface); + VIR_FREE(outbuf); virCommandFree(cmd); - return ret; } =20 --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696271270116.20206312677453; Wed, 4 Jul 2018 02:24:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1776385550; Wed, 4 Jul 2018 09:24:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC35E1001911; Wed, 4 Jul 2018 09:24:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 837004A460; Wed, 4 Jul 2018 09:24:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O6YJ000755 for ; Wed, 4 Jul 2018 05:24:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9D3E5178BD; Wed, 4 Jul 2018 09:24:06 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C6777C5D for ; Wed, 4 Jul 2018 09:24:06 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:38 +0200 Message-Id: <7a58a957d0496a57410ec912f71ed3e9839adb87.1530695759.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/10] virISCSIScanTargets: Honour iSCSI interface X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Jul 2018 09:24:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When scanning for targets, iSCSI might give different results depending on the interface used. This is basically just name of config file under /etc/iscsi/ifaces to use. The file contains initiator IQN thus different results claim. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/storage/storage_backend_iscsi.c | 4 +- src/util/viriscsi.c | 79 +++++++++++++++++++++++++++++++++= +--- src/util/viriscsi.h | 1 + tests/viriscsitest.c | 2 +- 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index 7871d1915b..3b9dddb4fd 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -194,7 +194,9 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, if (!(portal =3D virStorageBackendISCSIPortal(source))) goto cleanup; =20 - if (virISCSIScanTargets(portal, &ntargets, &targets) < 0) + if (virISCSIScanTargets(portal, + source->initiator.iqn, + &ntargets, &targets) < 0) goto cleanup; =20 if (VIR_ALLOC_N(list.sources, ntargets) < 0) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 1ddf00aa4c..549f75b434 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -40,6 +40,13 @@ VIR_LOG_INIT("util.iscsi"); =20 =20 +static int +virISCSIScanTargetsInternal(const char *portal, + const char *ifacename, + size_t *ntargetsret, + char ***targetsret); + + struct virISCSISessionData { char *session; const char *devpath; @@ -286,9 +293,10 @@ virISCSIConnection(const char *portal, * iscsiadm doesn't let you send commands to the Interface IQN, * unless you've first issued a 'sendtargets' command to the * portal. Without the sendtargets all that is received is a - * "iscsiadm: No records found" + * "iscsiadm: No records found". However, we must ensure that + * the command is issued over interface name we invented above. */ - if (virISCSIScanTargets(portal, NULL, NULL) < 0) + if (virISCSIScanTargetsInternal(portal, ifacename, NULL, NULL)= < 0) goto cleanup; =20 break; @@ -371,10 +379,11 @@ virISCSIGetTargets(char **const groups, } =20 =20 -int -virISCSIScanTargets(const char *portal, - size_t *ntargetsret, - char ***targetsret) +static int +virISCSIScanTargetsInternal(const char *portal, + const char *ifacename, + size_t *ntargetsret, + char ***targetsret) { /** * @@ -400,6 +409,12 @@ virISCSIScanTargets(const char *portal, "--op", "nonpersistent", NULL); =20 + if (ifacename) { + virCommandAddArgList(cmd, + "--interface", ifacename, + NULL); + } + memset(&list, 0, sizeof(list)); =20 if (virCommandRunRegex(cmd, @@ -425,6 +440,58 @@ virISCSIScanTargets(const char *portal, return ret; } =20 + +/** + * virISCSIScanTargets: + * @portal: iSCSI portal + * @initiatoriqn: Initiator IQN + * @ntargets: number of items in @targetsret array + * @targets: array of targets + * + * For given @portal issue sendtargets command. Optionally, + * @initiatoriqn can be set to override default configuration. + * The targets are stored into @targets array and the size of + * the array is stored into @ntargets. + * + * Returns: 0 on success, + * -1 otherwise (with error reported) + */ +int +virISCSIScanTargets(const char *portal, + const char *initiatoriqn, + size_t *ntargets, + char ***targets) +{ + char *ifacename =3D NULL; + int ret =3D -1; + + if (ntargets) + *ntargets =3D 0; + if (targets) + *targets =3D NULL; + + if (initiatoriqn) { + switch ((virStorageBackendIQNFound(initiatoriqn, &ifacename))) { + case IQN_FOUND: + break; + + case IQN_MISSING: + virReportError(VIR_ERR_OPERATION_FAILED, + _("no iSCSI interface defined for IQN %s"), + initiatoriqn); + ATTRIBUTE_FALLTHROUGH; + case IQN_ERROR: + default: + return -1; + } + } + + ret =3D virISCSIScanTargetsInternal(portal, ifacename, ntargets, targe= ts); + VIR_FREE(ifacename); + return ret; +} + + /* * virISCSINodeNew: * @portal: address for iSCSI target diff --git a/src/util/viriscsi.h b/src/util/viriscsi.h index a44beeaf67..31b589dbf9 100644 --- a/src/util/viriscsi.h +++ b/src/util/viriscsi.h @@ -49,6 +49,7 @@ virISCSIRescanLUNs(const char *session) =20 int virISCSIScanTargets(const char *portal, + const char *initiatoriqn, size_t *ntargetsret, char ***targetsret) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index aa4ba57707..4bdb782e36 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -145,7 +145,7 @@ testISCSIScanTargets(const void *data) =20 virCommandSetDryRun(NULL, testIscsiadmCb, NULL); =20 - if (virISCSIScanTargets(info->portal, &ntargets, &targets) < 0) + if (virISCSIScanTargets(info->portal, NULL, &ntargets, &targets) < 0) goto cleanup; =20 if (info->nexpected !=3D ntargets) { --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696281379956.2006286769654; Wed, 4 Jul 2018 02:24:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DBD6307D86D; Wed, 4 Jul 2018 09:24:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D179C2010CCC; Wed, 4 Jul 2018 09:24:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 74EFF3FCC3; Wed, 4 Jul 2018 09:24:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O7D7000760 for ; Wed, 4 Jul 2018 05:24:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6305E178BD; Wed, 4 Jul 2018 09:24:07 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6D997C5D for ; Wed, 4 Jul 2018 09:24:06 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:39 +0200 Message-Id: <470ecd153fd49faf96d9dd040fc5c00d6c960cc8.1530695759.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 05/10] virISCSIScanTargets: Allow making targets persistent X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 04 Jul 2018 09:24:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: John Ferlan --- src/storage/storage_backend_iscsi.c | 1 + src/util/viriscsi.c | 23 +++++++++++++++++++---- src/util/viriscsi.h | 1 + tests/viriscsitest.c | 3 ++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index 3b9dddb4fd..6242cd0fac 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -196,6 +196,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, =20 if (virISCSIScanTargets(portal, source->initiator.iqn, + false, &ntargets, &targets) < 0) goto cleanup; =20 diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 549f75b434..e2c80acaaa 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -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); =20 @@ -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; =20 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); =20 + 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, } } =20 - ret =3D virISCSIScanTargetsInternal(portal, ifacename, ntargets, targe= ts); + ret =3D virISCSIScanTargetsInternal(portal, ifacename, + persist, ntargets, targets); VIR_FREE(ifacename); return ret; } diff --git a/src/util/viriscsi.h b/src/util/viriscsi.h index 31b589dbf9..4da9becfb2 100644 --- a/src/util/viriscsi.h +++ b/src/util/viriscsi.h @@ -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; diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index 4bdb782e36..3bb3993196 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -145,7 +145,8 @@ testISCSIScanTargets(const void *data) =20 virCommandSetDryRun(NULL, testIscsiadmCb, NULL); =20 - if (virISCSIScanTargets(info->portal, NULL, &ntargets, &targets) < 0) + if (virISCSIScanTargets(info->portal, NULL, + false, &ntargets, &targets) < 0) goto cleanup; =20 if (info->nexpected !=3D ntargets) { --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696286993319.55127094251543; Wed, 4 Jul 2018 02:24:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D18D84ACBC; Wed, 4 Jul 2018 09:24:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92B3760BE7; Wed, 4 Jul 2018 09:24:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 35FDA1800B6B; Wed, 4 Jul 2018 09:24:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O85u000773 for ; Wed, 4 Jul 2018 05:24:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 26612178BD; Wed, 4 Jul 2018 09:24:08 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAC867C5D for ; Wed, 4 Jul 2018 09:24:07 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:40 +0200 Message-Id: <846b58dbe557579007d3fe578ea7b16cd2ffa788.1530695759.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/10] virCommandWait: Propagate dryRunCallback return value properly X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 04 Jul 2018 09:24:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The documentation to virCommandWait() function states that if @exitstatus is NULL and command finished with error -1 is returned. In other words, if @dryRunCallback is set and returns an error (by setting its @status argument to a nonzero value) we must propagate this error properly honouring the documentation (and also regular run). Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/util/vircommand.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 6dab105f56..13f75967fa 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -2553,6 +2553,8 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) dryRunStatus); if (exitstatus) *exitstatus =3D dryRunStatus; + else if (dryRunStatus) + return -1; return 0; } =20 --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696292863814.81173870736; Wed, 4 Jul 2018 02:24:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C580B8553E; Wed, 4 Jul 2018 09:24:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E2F7D717A; Wed, 4 Jul 2018 09:24:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 229FC1800B70; Wed, 4 Jul 2018 09:24:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O962000788 for ; Wed, 4 Jul 2018 05:24:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDF72178BD; Wed, 4 Jul 2018 09:24:08 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E7947C5D for ; Wed, 4 Jul 2018 09:24:08 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:41 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 07/10] viriscsitest: Test virISCSIConnectionLogin X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Jul 2018 09:24:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce one basic test that tests the simplest case: logging into portal without any IQN. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tests/viriscsitest.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index 3bb3993196..a7287069ba 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -94,6 +94,16 @@ static void testIscsiadmCb(const char *const*args, args[8] && STREQ(args[8], "nonpersistent") && args[9] =3D=3D NULL) { ignore_value(VIR_STRDUP(*output, iscsiadmSendtargetsOutput)); + } else if (args[0] && STREQ(args[0], ISCSIADM) && + args[1] && STREQ(args[1], "--mode") && + args[2] && STREQ(args[2], "node") && + args[3] && STREQ(args[3], "--portal") && + args[4] && STREQ(args[4], "10.20.30.40:3260,1") && + args[5] && STREQ(args[5], "--targetname") && + args[6] && STREQ(args[6], "iqn.2004-06.example:example1:isc= si.test") && + args[7] && STREQ(args[7], "--login") && + args[8] =3D=3D NULL) { + /* nada */ } else { *status =3D -1; } @@ -175,6 +185,32 @@ testISCSIScanTargets(const void *data) return ret; } =20 + +struct testConnectionInfoLogin { + const char *portal; + const char *initiatoriqn; + const char *target; +}; + + +static int +testISCSIConnectionLogin(const void *data) +{ + const struct testConnectionInfoLogin *info =3D data; + int ret =3D -1; + + virCommandSetDryRun(NULL, testIscsiadmCb, NULL); + + if (virISCSIConnectionLogin(info->portal, info->initiatoriqn, info->ta= rget) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virCommandSetDryRun(NULL, NULL, NULL); + return ret; +} + + static int mymain(void) { @@ -213,6 +249,16 @@ mymain(void) if (virTestRun("ISCSI scan targets", testISCSIScanTargets, &infoTarget= s) < 0) rv =3D -1; =20 +# define DO_LOGIN_TEST(portal, iqn, target) \ + do { \ + struct testConnectionInfoLogin info =3D {portal, iqn, target }; \ + if (virTestRun("ISCSI login " portal, \ + testISCSIConnectionLogin, &info) < 0) \ + rv =3D -1; \ + } while (0) + + DO_LOGIN_TEST("10.20.30.40:3260,1", NULL, "iqn.2004-06.example:example= 1:iscsi.test"); + if (rv < 0) return EXIT_FAILURE; return EXIT_SUCCESS; --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696277227497.56244676732706; Wed, 4 Jul 2018 02:24:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8737DC0272CF; Wed, 4 Jul 2018 09:24:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B9D41001F3D; Wed, 4 Jul 2018 09:24:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EBCE84BB78; Wed, 4 Jul 2018 09:24:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649O9Ou000795 for ; Wed, 4 Jul 2018 05:24:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3C19178BD; Wed, 4 Jul 2018 09:24:09 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 330221C59E for ; Wed, 4 Jul 2018 09:24:09 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:42 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/10] viriscsitest: Move testSessionInfo struct X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 04 Jul 2018 09:24:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This struct has nothing to do with testIscsiadmCb() rather than testISCSIGetSession(). Move it closer to the latter. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tests/viriscsitest.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index a7287069ba..361bf6a8da 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -60,12 +60,6 @@ const char *iscsiadmSendtargetsOutput =3D "10.20.30.40:3260,1 iqn.2008-04.example:example1:iscsi.bar\n" "10.20.30.40:3260,1 iqn.2009-04.example:example1:iscsi.seven\n"; =20 -struct testSessionInfo { - const char *device_path; - int output_version; - const char *expected_session; -}; - static void testIscsiadmCb(const char *const*args, const char *const*env ATTRIBUTE_UNUSED, const char *input ATTRIBUTE_UNUSED, @@ -109,6 +103,12 @@ static void testIscsiadmCb(const char *const*args, } } =20 +struct testSessionInfo { + const char *device_path; + int output_version; + const char *expected_session; +}; + static int testISCSIGetSession(const void *data) { --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696271403226.11042851490208; Wed, 4 Jul 2018 02:24:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C6F1317C3EC; Wed, 4 Jul 2018 09:24:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04A202271A; Wed, 4 Jul 2018 09:24:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 996D21800B68; Wed, 4 Jul 2018 09:24:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649OAGB000808 for ; Wed, 4 Jul 2018 05:24:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 66AAD178BD; Wed, 4 Jul 2018 09:24:10 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAF5C7C5D for ; Wed, 4 Jul 2018 09:24:09 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:43 +0200 Message-Id: <724635c2ce2fa648acd8eb138d249c77f06df7c5.1530695759.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/10] viriscsitest: Introduce testIscsiadmCbData struct X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 04 Jul 2018 09:24:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some tests will want to pass their own callback data into the testIscsiadmCbData callback. Introduce testIscsiadmCbData struct to give this some form and order. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tests/viriscsitest.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index 361bf6a8da..c6e0e3b8ff 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -60,6 +60,10 @@ const char *iscsiadmSendtargetsOutput =3D "10.20.30.40:3260,1 iqn.2008-04.example:example1:iscsi.bar\n" "10.20.30.40:3260,1 iqn.2009-04.example:example1:iscsi.seven\n"; =20 +struct testIscsiadmCbData { + bool output_version; +}; + static void testIscsiadmCb(const char *const*args, const char *const*env ATTRIBUTE_UNUSED, const char *input ATTRIBUTE_UNUSED, @@ -68,12 +72,13 @@ static void testIscsiadmCb(const char *const*args, int *status, void *opaque) { - int *output_version =3D opaque; + struct testIscsiadmCbData *data =3D opaque; + if (args[0] && STREQ(args[0], ISCSIADM) && args[1] && STREQ(args[1], "--mode") && args[2] && STREQ(args[2], "session") && args[3] =3D=3D NULL) { - if (*output_version =3D=3D 1) + if (data->output_version) ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutputNonFlash= )); else ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutput)); @@ -113,11 +118,13 @@ static int testISCSIGetSession(const void *data) { const struct testSessionInfo *info =3D data; - int ver =3D info->output_version; + struct testIscsiadmCbData cbData =3D { 0 }; char *actual_session =3D NULL; int ret =3D -1; =20 - virCommandSetDryRun(NULL, testIscsiadmCb, &ver); + cbData.output_version =3D info->output_version; + + virCommandSetDryRun(NULL, testIscsiadmCb, &cbData); =20 actual_session =3D virISCSIGetSession(info->device_path, true); =20 --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 05:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530696302934342.8645647343983; Wed, 4 Jul 2018 02:25:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B997887647; Wed, 4 Jul 2018 09:25:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5786760910; Wed, 4 Jul 2018 09:25:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CC2E31800B69; Wed, 4 Jul 2018 09:25:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w649OBmN000820 for ; Wed, 4 Jul 2018 05:24:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29661178BD; Wed, 4 Jul 2018 09:24:11 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADD261C59E for ; Wed, 4 Jul 2018 09:24:10 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:23:44 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 10/10] viriscsitest: Extend virISCSIConnectionLogin test X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 04 Jul 2018 09:25:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extend this existing test so that a case when IQN is provided is tested too. Since a special iSCSI interface is created and its name is randomly generated at runtime we need to link with virrandommock to have predictable names. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tests/viriscsitest.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index c6e0e3b8ff..55889d04a3 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -60,8 +60,19 @@ const char *iscsiadmSendtargetsOutput =3D "10.20.30.40:3260,1 iqn.2008-04.example:example1:iscsi.bar\n" "10.20.30.40:3260,1 iqn.2009-04.example:example1:iscsi.seven\n"; =20 +const char *iscsiadmIfaceDefaultOutput =3D + "default tcp,,,,\n" + "iser iser,,,,\n"; + +const char *iscsiadmIfaceIfaceOutput =3D + "default tcp,,,,\n" + "iser iser,,,,\n" + "libvirt-iface-03020100 tcp,,,,iqn.2004-06.exampl= e:example1:initiator\n"; + + struct testIscsiadmCbData { bool output_version; + bool iface_created; }; =20 static void testIscsiadmCb(const char *const*args, @@ -103,6 +114,62 @@ static void testIscsiadmCb(const char *const*args, args[7] && STREQ(args[7], "--login") && args[8] =3D=3D NULL) { /* nada */ + } else if (args[0] && STREQ(args[0], ISCSIADM) && + args[1] && STREQ(args[1], "--mode") && + args[2] && STREQ(args[2], "iface") && + args[3] =3D=3D NULL) { + if (data->iface_created) + ignore_value(VIR_STRDUP(*output, iscsiadmIfaceIfaceOutput)); + else + ignore_value(VIR_STRDUP(*output, iscsiadmIfaceDefaultOutput)); + } else if (args[0] && STREQ(args[0], ISCSIADM) && + args[1] && STREQ(args[1], "--mode") && + args[2] && STREQ(args[2], "iface") && + args[3] && STREQ(args[3], "--interface") && + args[4] && STREQ(args[4], "libvirt-iface-03020100") && + args[5] && STREQ(args[5], "--op") && + args[6] && STREQ(args[6], "new") && + args[7] =3D=3D NULL) { + data->iface_created =3D true; + } else if (args[0] && STREQ(args[0], ISCSIADM) && + args[1] && STREQ(args[1], "--mode") && + args[2] && STREQ(args[2], "iface") && + args[3] && STREQ(args[3], "--interface") && + args[4] && STREQ(args[4], "libvirt-iface-03020100") && + args[5] && STREQ(args[5], "--op") && + args[6] && STREQ(args[6], "update") && + args[7] && STREQ(args[7], "--name") && + args[8] && STREQ(args[8], "iface.initiatorname") && + args[9] && STREQ(args[9], "--value") && + args[10] && STREQ(args[10], "iqn.2004-06.example:example1:i= nitiator") && + args[11] =3D=3D NULL && + data->iface_created) { + /* nada */ + } else if (args[0] && STREQ(args[0], ISCSIADM) && + args[1] && STREQ(args[1], "--mode") && + args[2] && STREQ(args[2], "discovery") && + args[3] && STREQ(args[3], "--type") && + args[4] && STREQ(args[4], "sendtargets") && + args[5] && STREQ(args[5], "--portal") && + args[6] && STREQ(args[6], "10.20.30.40:3260,1") && + args[7] && STREQ(args[7], "--interface") && + args[8] && STREQ(args[8], "libvirt-iface-03020100") && + args[9] =3D=3D NULL && + data->iface_created) { + ignore_value(VIR_STRDUP(*output, iscsiadmSendtargetsOutput)); + } else if (args[0] && STREQ(args[0], ISCSIADM) && + args[1] && STREQ(args[1], "--mode") && + args[2] && STREQ(args[2], "node") && + args[3] && STREQ(args[3], "--portal") && + args[4] && STREQ(args[4], "10.20.30.40:3260,1") && + args[5] && STREQ(args[5], "--targetname") && + args[6] && STREQ(args[6], "iqn.2004-06.example:example1:isc= si.test") && + args[7] && STREQ(args[7], "--login") && + args[8] && STREQ(args[8], "--interface") && + args[9] && STREQ(args[9], "libvirt-iface-03020100") && + args[10] =3D=3D NULL && + data->iface_created) { + /* nada */ } else { *status =3D -1; } @@ -204,9 +271,10 @@ static int testISCSIConnectionLogin(const void *data) { const struct testConnectionInfoLogin *info =3D data; + struct testIscsiadmCbData cbData =3D { 0 }; int ret =3D -1; =20 - virCommandSetDryRun(NULL, testIscsiadmCb, NULL); + virCommandSetDryRun(NULL, testIscsiadmCb, &cbData); =20 if (virISCSIConnectionLogin(info->portal, info->initiatoriqn, info->ta= rget) < 0) goto cleanup; @@ -265,11 +333,14 @@ mymain(void) } while (0) =20 DO_LOGIN_TEST("10.20.30.40:3260,1", NULL, "iqn.2004-06.example:example= 1:iscsi.test"); + DO_LOGIN_TEST("10.20.30.40:3260,1", "iqn.2004-06.example:example1:init= iator", + "iqn.2004-06.example:example1:iscsi.test"); =20 if (rv < 0) return EXIT_FAILURE; return EXIT_SUCCESS; } =20 -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, + abs_builddir "/.libs/virrandommock.so") #endif /* WIN32 */ --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list