[PATCH v3 1/3] storage: refactor volume capacity in iscsi-direct backend

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

 



From: Clementine Hayat <clem@xxxxxxxxxxxx>

The size of blocks inside a volume and the number of blocks are needed
later. Having a function that return thoses information will avoid code
duplication.

Signed-off-by: Clementine Hayat <clem@xxxxxxxxxxxx>
---
 src/storage/storage_backend_iscsi_direct.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index 0764356b62..62b7e0d8bc 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -237,13 +237,13 @@ virISCSIDirectSetVolumeAttributes(virStoragePoolObjPtr pool,
 }
 
 static int
-virISCSIDirectSetVolumeCapacity(struct iscsi_context *iscsi,
-                                virStorageVolDefPtr vol,
-                                int lun)
+virISCSIDirectGetVolumeCapacity(struct iscsi_context *iscsi,
+                                int lun,
+                                uint32_t *block_size,
+                                uint32_t *nb_block)
 {
     struct scsi_task *task = NULL;
     struct scsi_inquiry_standard *inq = NULL;
-    long long size = 0;
     int ret = -1;
 
     if (!(task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64)) ||
@@ -282,10 +282,8 @@ virISCSIDirectSetVolumeCapacity(struct iscsi_context *iscsi,
             goto cleanup;
         }
 
-        size  = rc10->block_size;
-        size *= rc10->lba;
-        vol->target.capacity = size;
-        vol->target.allocation = size;
+        *block_size  = rc10->block_size;
+        *nb_block = rc10->lba;
 
     }
 
@@ -303,6 +301,8 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool,
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
     virStorageVolDefPtr vol = NULL;
+    uint32_t block_size;
+    uint32_t nb_block;
     int ret = -1;
 
     virStoragePoolObjClearVols(pool);
@@ -314,9 +314,12 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool,
 
     vol->type = VIR_STORAGE_VOL_NETWORK;
 
-    if (virISCSIDirectSetVolumeCapacity(iscsi, vol, lun) < 0)
+    if (virISCSIDirectGetVolumeCapacity(iscsi, lun,
+                                        &block_size, &nb_block) < 0)
         goto cleanup;
 
+    vol->target.capacity = block_size * nb_block;
+    vol->target.allocation = block_size * nb_block;
     def->capacity += vol->target.capacity;
     def->allocation += vol->target.allocation;
 
-- 
2.18.0

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux