[PATCH 6/8] qemuDomainVirStorageSourceFindByNodeName: Extract nodename matching

Peter Krempa posted 8 patches 1 month ago
[PATCH 6/8] qemuDomainVirStorageSourceFindByNodeName: Extract nodename matching
Posted by Peter Krempa 1 month ago
Extract the matching of the node name of a single virStorage source so
that the logic can be extended in the upcoming patch.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_domain.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index d28ff0cd22..150f0736f3 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2884,6 +2884,25 @@ qemuDomainObjPrivateXMLParseBlockjobChain(xmlNodePtr node,
 }


+/**
+ * qemuDomainVirStorageSourceMatchNodename:
+ * @src: storage source to match
+ * @nodeName to match
+ *
+ * Returns true if any of the nodenames of @src matches @nodeName.
+ */
+static bool
+qemuDomainVirStorageSourceMatchNodename(virStorageSource *src,
+                                        const char *nodeName)
+{
+    const char *nodestorage = qemuBlockStorageSourceGetStorageNodename(src);
+    const char *nodeformat = qemuBlockStorageSourceGetFormatNodename(src);
+
+    return (nodeformat && STREQ(nodeformat, nodeName)) ||
+           (nodestorage && STREQ(nodestorage, nodeName));
+}
+
+
 /**
  * qemuDomainVirStorageSourceFindByNodeName:
  * @top: backing chain top
@@ -2900,11 +2919,7 @@ qemuDomainVirStorageSourceFindByNodeName(virStorageSource *top,
     virStorageSource *tmp;

     for (tmp = top; virStorageSourceIsBacking(tmp); tmp = tmp->backingStore) {
-        const char *nodestorage = qemuBlockStorageSourceGetStorageNodename(tmp);
-        const char *nodeformat = qemuBlockStorageSourceGetFormatNodename(tmp);
-
-        if ((nodeformat && STREQ(nodeformat, nodeName)) ||
-            (nodestorage && STREQ(nodestorage, nodeName)))
+        if (qemuDomainVirStorageSourceMatchNodename(tmp, nodeName))
             return tmp;
     }

-- 
2.47.0
Re: [PATCH 6/8] qemuDomainVirStorageSourceFindByNodeName: Extract nodename matching
Posted by Jiri Denemark 4 weeks ago
On Tue, Nov 26, 2024 at 16:16:17 +0100, Peter Krempa wrote:
> Extract the matching of the node name of a single virStorage source so
> that the logic can be extended in the upcoming patch.

This is confusing. I was expecting the logic in
qemuDomainVirStorageSourceFindByNodeName to be extended in the following
patch, but in reality you just needed to reuse the same code in another
place. That is the goal of moving the code to a separate function was to
avoid code duplication.

Jirka
Re: [PATCH 6/8] qemuDomainVirStorageSourceFindByNodeName: Extract nodename matching
Posted by Peter Krempa 4 weeks ago
On Thu, Nov 28, 2024 at 10:22:53 +0100, Jiri Denemark wrote:
> On Tue, Nov 26, 2024 at 16:16:17 +0100, Peter Krempa wrote:
> > Extract the matching of the node name of a single virStorage source so
> > that the logic can be extended in the upcoming patch.
> 
> This is confusing. I was expecting the logic in
> qemuDomainVirStorageSourceFindByNodeName to be extended in the following
> patch, but in reality you just needed to reuse the same code in another
> place. That is the goal of moving the code to a separate function was to
> avoid code duplication.

so s/extended/reused/ ?
Re: [PATCH 6/8] qemuDomainVirStorageSourceFindByNodeName: Extract nodename matching
Posted by Jiri Denemark 4 weeks ago
On Thu, Nov 28, 2024 at 10:24:07 +0100, Peter Krempa wrote:
> On Thu, Nov 28, 2024 at 10:22:53 +0100, Jiri Denemark wrote:
> > On Tue, Nov 26, 2024 at 16:16:17 +0100, Peter Krempa wrote:
> > > Extract the matching of the node name of a single virStorage source so
> > > that the logic can be extended in the upcoming patch.
> > 
> > This is confusing. I was expecting the logic in
> > qemuDomainVirStorageSourceFindByNodeName to be extended in the following
> > patch, but in reality you just needed to reuse the same code in another
> > place. That is the goal of moving the code to a separate function was to
> > avoid code duplication.
> 
> so s/extended/reused/ ?

Sounds good.

Jirka