From nobody Mon Feb 9 01:31:01 2026 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 1531927379711617.1629868030046; Wed, 18 Jul 2018 08:22:59 -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 9BB8E89E5; Wed, 18 Jul 2018 15:22:57 +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 5CB99CB5EE; Wed, 18 Jul 2018 15:22:57 +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 F13C218037F5; Wed, 18 Jul 2018 15:22:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6IFMHJN001292 for ; Wed, 18 Jul 2018 11:22:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 836EC2156897; Wed, 18 Jul 2018 15:22:17 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24A912156893 for ; Wed, 18 Jul 2018 15:22:17 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 18 Jul 2018 17:22:09 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/9] utils: storage: Add helper for checking if storage source is the same 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.39]); Wed, 18 Jul 2018 15:22:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" To allow checking whether a storage source points to the same location add a helper which checks the relevant fields. This will allow replacing a similar check done by formatting the command line arguments for qemu-like syntax. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/util/virstoragefile.h | 3 +++ 3 files changed, 47 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1caecb96b6..fb7c8c724d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2855,6 +2855,7 @@ virStorageSourceIsBlockLocal; virStorageSourceIsEmpty; virStorageSourceIsLocalStorage; virStorageSourceIsRelative; +virStorageSourceIsSameLocation; virStorageSourceNetworkAssignDefaultPorts; virStorageSourceNewFromBacking; virStorageSourceNewFromBackingAbsolute; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 58f67278da..96ed4b1489 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2259,6 +2259,49 @@ virStorageSourceCopy(const virStorageSource *src, } +/** + * virStorageSourceIsSameLocation: + * + * Returns true if the sources @a and @b point to the same storage locatio= n. + * This does not compare any other configuration option + */ +bool +virStorageSourceIsSameLocation(virStorageSourcePtr a, + virStorageSourcePtr b) +{ + size_t i; + + /* there are multiple possibilities to define an empty source */ + if (virStorageSourceIsEmpty(a) && + virStorageSourceIsEmpty(b)) + return true; + + if (virStorageSourceGetActualType(a) !=3D virStorageSourceGetActualTyp= e(b)) + return false; + + if (STRNEQ_NULLABLE(a->path, b->path) || + STRNEQ_NULLABLE(a->volume, b->volume) || + STRNEQ_NULLABLE(a->snapshot, b->snapshot)) + return false; + + if (a->type =3D=3D VIR_STORAGE_TYPE_NETWORK) { + if (a->protocol !=3D b->protocol || + a->nhosts !=3D b->nhosts) + return false; + + for (i =3D 0; i < a->nhosts; i++) { + if (a->hosts[i].transport !=3D b->hosts[i].transport || + a->hosts[i].port !=3D b->hosts[i].port || + STRNEQ_NULLABLE(a->hosts[i].name, b->hosts[i].name) || + STRNEQ_NULLABLE(a->hosts[i].socket, b->hosts[i].socket)) + return false; + } + } + + return true; +} + + /** * virStorageSourceInitChainElement: * @newelem: New backing chain element disk source diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 991098e6c6..c2c40edf68 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -436,6 +436,9 @@ virStorageSourcePtr virStorageSourceNewFromBacking(virS= torageSourcePtr parent); virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src, bool backingChain) ATTRIBUTE_NONNULL(1); +bool virStorageSourceIsSameLocation(virStorageSourcePtr a, + virStorageSourcePtr b) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int virStorageSourceParseRBDColonString(const char *rbdstr, virStorageSourcePtr src) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list