From nobody Wed Feb 11 10:17:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 148959600383498.9429380724772; Wed, 15 Mar 2017 09:40:03 -0700 (PDT) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2FGathG016483; Wed, 15 Mar 2017 12:36:55 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2FGapOg024929 for ; Wed, 15 Mar 2017 12:36:51 -0400 Received: from angien.brq.redhat.com (dhcp129-47.brq.redhat.com [10.34.129.47]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2FGafIL000870; Wed, 15 Mar 2017 12:36:50 -0400 From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 15 Mar 2017 17:37:19 +0100 Message-Id: <01946b284e1be9b144f92146c79c16f98b0a1a9d.1489595335.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 07/23] qemu: domain: Add helper to lookup disk by node name 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Looks up a disk and it's corresponding backing chain element by node name. --- src/qemu/qemu_domain.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 6 ++++++ 2 files changed, 49 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 07ce22417..95ea63615 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8369,3 +8369,46 @@ qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driv= er, cleanup: return ret; } + + +/** + * qemuDomainDiskLookupByNodename: + * @def: domain definition to look for the disk + * @nodename: block backend node name to find + * @src: filled with the specific backing store element if provided + * @idx: index of @src in the backing chain, if provided + * + * Looks up the disk in the domain via @nodename and returns it's definiti= on. + * Optionally fills @src and @idx if provided with the specific backing ch= ain + * element which corresponds to the node name. + */ +virDomainDiskDefPtr +qemuDomainDiskLookupByNodename(virDomainDefPtr def, + const char *nodename, + virStorageSourcePtr *src, + unsigned int *idx) +{ + size_t i; + unsigned int srcindex; + virStorageSourcePtr tmp =3D NULL; + + if (!idx) + idx =3D &srcindex; + + if (src) + *src =3D NULL; + + *idx =3D 0; + + for (i =3D 0; i < def->ndisks; i++) { + if ((tmp =3D virStorageSourceFindByNodeName(def->disks[i]->src, + nodename, idx))) { + if (src) + *src =3D tmp; + + return def->disks[i]; + } + } + + return NULL; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index c646828e6..15eb72a5c 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -852,4 +852,10 @@ int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr drive= r, int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRNGDefPtr rng); + +virDomainDiskDefPtr qemuDomainDiskLookupByNodename(virDomainDefPtr def, + const char *nodename, + virStorageSourcePtr *sr= c, + unsigned int *idx); + #endif /* __QEMU_DOMAIN_H__ */ --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list