[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 15/19] storage: Introduce virStoragePoolObjForEachVolume



Create/Use API to "walk" the storage pool object volume list.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/conf/virstorageobj.c           | 10 ++++++++++
 src/conf/virstorageobj.h           |  4 ++++
 src/libvirt_private.syms           |  1 +
 src/storage/storage_backend_disk.c | 26 +++++++++++++++-----------
 4 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index cc3464e..14feecb 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -343,6 +343,16 @@ virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj)
 
 
 virStorageVolDefPtr
+virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj,
+                               size_t curidx)
+{
+    if (curidx < obj->volumes.count)
+        return obj->volumes.objs[curidx];
+    return NULL;
+}
+
+
+virStorageVolDefPtr
 virStorageVolDefFindByKey(virStoragePoolObjPtr obj,
                           const char *key)
 {
diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h
index d27ff57..df0b4ae 100644
--- a/src/conf/virstorageobj.h
+++ b/src/conf/virstorageobj.h
@@ -139,6 +139,10 @@ size_t
 virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj);
 
 virStorageVolDefPtr
+virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj,
+                               size_t curidx);
+
+virStorageVolDefPtr
 virStorageVolDefFindByKey(virStoragePoolObjPtr obj,
                           const char *key);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 03777a3..fe0e203 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1014,6 +1014,7 @@ virStoragePoolObjDecrAsyncjobs;
 virStoragePoolObjDeleteDef;
 virStoragePoolObjFindByName;
 virStoragePoolObjFindByUUID;
+virStoragePoolObjForEachVolume;
 virStoragePoolObjGetAsyncjobs;
 virStoragePoolObjGetAutostart;
 virStoragePoolObjGetConfigFile;
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 0bf5567..0ec601e 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -192,12 +192,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
     /* Find the extended partition and increase the allocation value */
     if (vol->source.partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) {
         size_t i;
+        virStorageVolDefPtr voldef;
 
-        for (i = 0; i < pool->volumes.count; i++) {
-            if (pool->volumes.objs[i]->source.partType ==
-                VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) {
-                pool->volumes.objs[i]->target.allocation +=
-                    vol->target.allocation;
+        for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i)); i++) {
+            if (voldef->source.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) {
+                voldef->target.allocation += vol->target.allocation;
                 break;
             }
         }
@@ -533,8 +532,10 @@ virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool)
            can't be more than 3 to create a new primary partition */
         size_t i;
         int count = 0;
-        for (i = 0; i < pool->volumes.count; i++) {
-            int partType = pool->volumes.objs[i]->source.partType;
+        virStorageVolDefPtr voldef;
+
+        for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i)); i++) {
+            int partType = voldef->source.partType;
             if (partType == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY ||
                 partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED)
                 count++;
@@ -553,6 +554,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
                                 char** partFormat)
 {
     size_t i;
+    virStorageVolDefPtr voldef;
+
     if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
         const char *partedFormat;
         partedFormat = virStoragePartedFsTypeToString(vol->target.format);
@@ -563,8 +566,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
         }
         if (vol->target.format == VIR_STORAGE_VOL_DISK_EXTENDED) {
             /* make sure we don't have an extended partition already */
-            for (i = 0; i < pool->volumes.count; i++) {
-                if (pool->volumes.objs[i]->source.partType ==
+            for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i)); i++) {
+                if (voldef->source.partType ==
                     VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) {
                     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                    _("extended partition already exists"));
@@ -585,8 +588,9 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
                 break;
             case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL:
                 /* make sure we have an extended partition */
-                for (i = 0; i < pool->volumes.count; i++) {
-                    if (pool->volumes.objs[i]->source.partType ==
+                for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i));
+                     i++) {
+                    if (voldef->source.partType ==
                         VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) {
                         if (virAsprintf(partFormat, "logical %s",
                                         partedFormat) < 0)
-- 
2.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]