qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCHv2 09/11] iscsi: factor out sector conversions


From: Peter Lieven
Subject: [Qemu-devel] [PATCHv2 09/11] iscsi: factor out sector conversions
Date: Thu, 27 Jun 2013 15:11:33 +0200

Signed-off-by: Peter Lieven <address@hidden>
---
 block/iscsi.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 621ca40..e9ecfce 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -293,6 +293,11 @@ static int64_t sector_qemu2lun(int64_t sector, IscsiLun 
*iscsilun)
     return sector * BDRV_SECTOR_SIZE / iscsilun->block_size;
 }
 
+static int64_t sector_lun2qemu(int64_t sector, IscsiLun *iscsilun)
+{
+    return sector * iscsilun->block_size / BDRV_SECTOR_SIZE;
+}
+
 static int
 iscsi_aio_writev_acb(IscsiAIOCB *acb)
 {
@@ -340,7 +345,7 @@ iscsi_aio_writev_acb(IscsiAIOCB *acb)
     lba = sector_qemu2lun(acb->sector_num, acb->iscsilun);
     *(uint32_t *)&acb->task->cdb[2]  = htonl(lba >> 32);
     *(uint32_t *)&acb->task->cdb[6]  = htonl(lba & 0xffffffff);
-    num_sectors = size / acb->iscsilun->block_size;
+    num_sectors = sector_qemu2lun(acb->nb_sectors, acb->iscsilun);
     *(uint32_t *)&acb->task->cdb[10] = htonl(num_sectors);
     acb->task->expxferlen = size;
 
@@ -659,7 +664,7 @@ static int iscsi_aio_discard_acb(IscsiAIOCB *acb) {
     acb->buf        = NULL;
 
     list[0].lba = sector_qemu2lun(acb->sector_num, acb->iscsilun);
-    list[0].num = acb->nb_sectors * BDRV_SECTOR_SIZE / 
acb->iscsilun->block_size;
+    list[0].num = sector_qemu2lun(acb->nb_sectors, acb->iscsilun);
 
     acb->task = iscsi_unmap_task(iscsi, acb->iscsilun->lun,
                                  0, 0, &list[0], 1,
@@ -910,7 +915,7 @@ retry:
         goto fail;
     }
 
-    *pnum = lbasd->num_blocks * (iscsilun->block_size / BDRV_SECTOR_SIZE);
+    *pnum = sector_lun2qemu(lbasd->num_blocks, iscsilun);
     if (*pnum > nb_sectors) {
         *pnum = nb_sectors;
     }
@@ -937,7 +942,7 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, 
int64_t sector_num,
     struct unmap_list list[1];
 
     if (!iscsilun->lbprz || !iscsilun->lbpu || !(bs->open_flags & 
BDRV_O_UNMAP) ||
-        nb_sectors * BDRV_SECTOR_SIZE / iscsilun->block_size > 
iscsilun->max_unmap) {
+        sector_qemu2lun(nb_sectors, iscsilun) > iscsilun->max_unmap) {
         /* fall back to writev */
         return -ENOTSUP;
     }
@@ -945,7 +950,7 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, 
int64_t sector_num,
     iscsi_co_init_iscsitask(iscsilun, &iTask);
 
     list[0].lba = sector_qemu2lun(sector_num, iscsilun);
-    list[0].num = nb_sectors * BDRV_SECTOR_SIZE / iscsilun->block_size;
+    list[0].num = sector_qemu2lun(nb_sectors, iscsilun);
 
 retry:
     if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list[0], 1,
@@ -1322,8 +1327,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
*options, int flags)
     if ((ret = iscsi_readcapacity_sync(iscsilun)) != 0) {
         goto out;
     }
-    bs->total_sectors    = iscsilun->num_blocks *
-                           iscsilun->block_size / BDRV_SECTOR_SIZE ;
+    bs->total_sectors    = sector_lun2qemu(iscsilun->num_blocks, iscsilun);
 
     /* Medium changer or tape. We dont have any emulation for this so this must
      * be sg ioctl compatible. We force it to be sg, otherwise qemu will try
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]