From nobody Mon Feb 9 17:23:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594938146; cv=none; d=zohomail.com; s=zohoarc; b=jOolpbm2Z7gcf/fzpWi8dw6YZSA0HITOPhm4gM88QrbySMk7RBrY+yJ2qzCXhDFmr3EgHdHbfEBU5u5ChMfxQF3xlG2/ZHb0Y68GOyExJUdrpK0ytEOOwPlWHKKHj7wRoBQ0iMGhLvI7m0J4TtLeTwx6ainJmp//FSOZeRRCupM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594938146; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u1gAiuVnQAFWNpufrKXOLgP1zOdagfg5W4GbhjYmyRI=; b=LhAkFKRvDE3116TvOMfgP8ChZhmux+kPSXyLjWJVrKVkE6pPAuKBShohWXJmuBHHBP/P9SfEWnlUw4dwAvMEnF7rn0sbNaOvHnGiFRjGocC4necH/v1u2bmP741mTGDW8MaEwx6lKo+GKklNFjKndPKyhvhjyAmFM11yw923/ec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594938146466194.7417192150432; Thu, 16 Jul 2020 15:22:26 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-nLJMnf92OYK11M169HrI-Q-1; Thu, 16 Jul 2020 18:22:22 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 578E0100AA2D; Thu, 16 Jul 2020 22:22:14 +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 C83C81001B07; Thu, 16 Jul 2020 22:22:13 +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 96FC196243; Thu, 16 Jul 2020 22:22:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06GMLs0x022337 for ; Thu, 16 Jul 2020 18:21:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 62FA56FED1; Thu, 16 Jul 2020 22:21:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-38.phx2.redhat.com [10.3.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34A9C724B8 for ; Thu, 16 Jul 2020 22:21:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594938145; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=u1gAiuVnQAFWNpufrKXOLgP1zOdagfg5W4GbhjYmyRI=; b=AUSAyDHglqMPshN+DeAyHnbrtlA8O59kCNYHIjMG5ez2IjdCE407bWpfVwqG829jyB8McX ef+Lqy2S9hHZIUBcVxdnTzW+dq3DKXtO4xJFmzVCzGfW0ZoyeCELU2LDIQIi356yR+afEL fn8xJL+8oHgLfdqA2qUZWWsxFuXzSio= X-MC-Unique: nLJMnf92OYK11M169HrI-Q-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 13/16] virsh: Factor out function to find node device Date: Thu, 16 Jul 2020 17:21:43 -0500 Message-Id: <20200716222146.1241-14-jjongsma@redhat.com> In-Reply-To: <20200716222146.1241-1-jjongsma@redhat.com> References: <20200716222146.1241-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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: , 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Several functions accept providing a node device by name or by wwnn,wwpn pair. Extract the logic to do this into a function that can be used by both callers. Signed-off-by: Jonathon Jongsma --- tools/virsh-nodedev.c | 58 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c02b79a349..57f987a81e 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -112,23 +112,18 @@ static const vshCmdOptDef opts_node_device_destroy[] = =3D { {.name =3D NULL} }; =20 -static bool -cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) +static virNodeDevicePtr +vshFindNodeDevice(vshControl *ctl, const char *value) { virNodeDevicePtr dev =3D NULL; - bool ret =3D false; - const char *device_value =3D NULL; char **arr =3D NULL; int narr; virshControlPtr priv =3D ctl->privData; =20 - if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) - return false; - - if (strchr(device_value, ',')) { - narr =3D vshStringToArray(device_value, &arr); + if (strchr(value, ',')) { + narr =3D vshStringToArray(value, &arr); if (narr !=3D 2) { - vshError(ctl, _("Malformed device value '%s'"), device_value); + vshError(ctl, _("Malformed device value '%s'"), value); goto cleanup; } =20 @@ -137,9 +132,30 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cm= d) =20 dev =3D virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1= ], 0); } else { - dev =3D virNodeDeviceLookupByName(priv->conn, device_value); + dev =3D virNodeDeviceLookupByName(priv->conn, value); } =20 + if (!dev) { + vshError(ctl, "%s '%s'", _("Could not find matching device"), valu= e); + goto cleanup; + } + +cleanup: + virStringListFree(arr); + return dev; +} + +static bool +cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) +{ + virNodeDevicePtr dev =3D NULL; + bool ret =3D false; + const char *device_value =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; + + dev =3D vshFindNodeDevice(ctl, device_value); if (!dev) { vshError(ctl, "%s '%s'", _("Could not find matching device"), devi= ce_value); goto cleanup; @@ -154,7 +170,6 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - virStringListFree(arr); if (dev) virNodeDeviceFree(dev); return ret; @@ -570,28 +585,12 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *c= md) virNodeDevicePtr device =3D NULL; char *xml =3D NULL; const char *device_value =3D NULL; - char **arr =3D NULL; - int narr; bool ret =3D false; - virshControlPtr priv =3D ctl->privData; =20 if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) return false; =20 - if (strchr(device_value, ',')) { - narr =3D vshStringToArray(device_value, &arr); - if (narr !=3D 2) { - vshError(ctl, _("Malformed device value '%s'"), device_value); - goto cleanup; - } - - if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) - goto cleanup; - - device =3D virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], ar= r[1], 0); - } else { - device =3D virNodeDeviceLookupByName(priv->conn, device_value); - } + device =3D vshFindNodeDevice(ctl, device_value); =20 if (!device) { vshError(ctl, "%s '%s'", _("Could not find matching device"), devi= ce_value); @@ -605,7 +604,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - virStringListFree(arr); VIR_FREE(xml); if (device) virNodeDeviceFree(device); --=20 2.21.3