]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage_backend_iscsi_direct: Simplify vol zeroing
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 1 Mar 2019 10:42:20 +0000 (11:42 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Mar 2019 12:20:36 +0000 (13:20 +0100)
So far we have two branches: either we zero BLOCK_PER_PACKET
(currently 128) block at once, or if we're close to the last block
then we zero out one block at the time. This is very suboptimal.
We know how many block are there left. Might as well just write
them all at once.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/storage/storage_backend_iscsi_direct.c

index 6283a2836b11de330bd5b721e294c3f9a128f11c..deb02a717345cf8a3fe545a1f49febc32772c4ff 100644 (file)
@@ -638,21 +638,23 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDefPtr vol,
         return ret;
 
     while (lba < nb_block) {
-        if (nb_block - lba > block_size * BLOCK_PER_PACKET) {
+        const uint64_t to_write = MIN(nb_block - lba + 1, BLOCK_PER_PACKET);
 
-            if (!(task = iscsi_write16_sync(iscsi, lun, lba, data,
-                                            block_size * BLOCK_PER_PACKET,
-                                            block_size, 0, 0, 0, 0, 0)))
-                return -1;
-            scsi_free_scsi_task(task);
-            lba += BLOCK_PER_PACKET;
-        } else {
-            if (!(task = iscsi_write16_sync(iscsi, lun, lba, data, block_size,
-                                        block_size, 0, 0, 0, 0, 0)))
-                return -1;
+        task = iscsi_write16_sync(iscsi, lun, lba, data,
+                                  block_size * to_write,
+                                  block_size, 0, 0, 0, 0, 0);
+
+        if (!task ||
+            task->status != SCSI_STATUS_GOOD) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("failed to write to LUN %d: %s"),
+                           lun, iscsi_get_error(iscsi));
             scsi_free_scsi_task(task);
-            lba++;
+            return -1;
         }
+
+        scsi_free_scsi_task(task);
+        lba += to_write;
     }
 
     return 0;