[libvirt] [PATCH 4/9] util: storage: use stored index to lookup disks

Peter Krempa posted 9 patches 7 years, 7 months ago
[libvirt] [PATCH 4/9] util: storage: use stored index to lookup disks
Posted by Peter Krempa 7 years, 7 months ago
We can now use the backing store ID directly rather than counting the
number of images seen while looking up images.
---
 src/util/virstoragefile.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 2b9f4c892..9568a5068 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1588,25 +1588,14 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
     const char *start = chain->path;
     char *parentDir = NULL;
     bool nameIsFile = virStorageIsFile(name);
-    size_t i = 0;

     if (!parent)
         parent = &prev;
     *parent = NULL;

     if (startFrom) {
-        while (chain && chain != startFrom->backingStore) {
+        while (chain && chain != startFrom->backingStore)
             chain = chain->backingStore;
-            i++;
-        }
-
-        if (idx && idx < i) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("requested backing store index %u is above '%s' "
-                             "in chain for '%s'"),
-                           idx, NULLSTR(startFrom->path), NULLSTR(start));
-            return NULL;
-        }

         *parent = startFrom;
     }
@@ -1616,8 +1605,8 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
             if (!chain->backingStore)
                 break;
         } else if (idx) {
-            VIR_DEBUG("%zu: %s", i, chain->path);
-            if (idx == i)
+            VIR_DEBUG("%u: %s", chain->id, chain->path);
+            if (idx == chain->id)
                 break;
         } else {
             if (STREQ_NULLABLE(name, chain->relPath) ||
@@ -1649,7 +1638,6 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
         }
         *parent = chain;
         chain = chain->backingStore;
-        i++;
     }

     if (!chain)
-- 
2.14.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/9] util: storage: use stored index to lookup disks
Posted by Eric Blake 7 years, 7 months ago
On 10/12/2017 02:07 PM, Peter Krempa wrote:
> We can now use the backing store ID directly rather than counting the
> number of images seen while looking up images.
> ---
>  src/util/virstoragefile.c | 18 +++---------------
>  1 file changed, 3 insertions(+), 15 deletions(-)
> 

I guess if we've always been counting the chain depth, the id
renumbering question I had on patch 3 is somewhat answered: 'vda[1]'
does not always refer to the same file in the chain.  As long as we're
okay with that, I didn't see any other problems in patch 3 or in this one.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

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