If the size of the qiov is smaller than the sector size, do not truncate
the qiov, which would effectively make it empty. Instead, allow it to
pass as is.

This is necessary for SCSI requests like READ CAPACITY which have small
buffers, e.g. 32 bytes.

Signed-off-by: Alex Pyrgiotis <apyr...@arrikto.com>
Signed-off-by: Dimitris Aragiorgis <dim...@arrikto.com>

diff --git a/dma-helpers.c b/dma-helpers.c
index e1ea7b3..b8f2ae0 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -162,7 +162,16 @@ static void dma_map_sg(DMAAIOCB *dbs)
         return;
     }
 
-    if (dbs->iov.size & ~BDRV_SECTOR_MASK) {
+    /*
+     * If the size of the qiov is not a multiple of the sector size, truncate
+     * the qiov.
+     *
+     * NOTE: If the qiov is less than a sector, we can assume that there is a
+     * reason for it, e.g., a SCSI request such as READ CAPACITY, and we should
+     * not truncate it.
+     */
+    if (dbs->iov.size & ~BDRV_SECTOR_MASK &&
+            dbs->iov.size > BDRV_SECTOR_SIZE) {
         qemu_iovec_discard_back(&dbs->iov, dbs->iov.size & ~BDRV_SECTOR_MASK);
     }
 }
-- 
2.6.2


Reply via email to