Re: [libvirt] [PATCH 8/9] utils: storage: Add helper for checking if storage source is the same

2018-07-20 Thread Ján Tomko

On Wed, Jul 18, 2018 at 05:22:09PM +0200, Peter Krempa wrote:

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 
---
src/libvirt_private.syms  |  1 +
src/util/virstoragefile.c | 43 +++
src/util/virstoragefile.h |  3 +++
3 files changed, 47 insertions(+)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 8/9] utils: storage: Add helper for checking if storage source is the same

2018-07-18 Thread Peter Krempa
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 
---
 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 location.
+ * 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) != virStorageSourceGetActualType(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 == VIR_STORAGE_TYPE_NETWORK) {
+if (a->protocol != b->protocol ||
+a->nhosts != b->nhosts)
+return false;
+
+for (i = 0; i < a->nhosts; i++) {
+if (a->hosts[i].transport != b->hosts[i].transport ||
+a->hosts[i].port != 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(virStorageSourcePtr 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)
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list