Patchwork [2/4] iscsi: add .bdrv_get_info

login
register
mail settings
Submitter Peter Lieven
Date July 15, 2013, 10:49 a.m.
Message ID <1373885375-13601-3-git-send-email-pl@kamp.de>
Download mbox | patch
Permalink /patch/258995/
State New
Headers show

Comments

Peter Lieven - July 15, 2013, 10:49 a.m.
this is used to reveal max_unmap and discard_zeroes capabilities.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Patch

diff --git a/block/iscsi.c b/block/iscsi.c
index 2b8fab9..74a35b9 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -927,6 +927,11 @@  retry:
     return 0;
 }
 
+static bool iscsi_discard_zeroes(IscsiLun *iscsilun)
+{
+    return iscsilun->lbprz && iscsilun->lbpu;
+}
+
 static int
 coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
                                    int nb_sectors)
@@ -937,8 +942,7 @@  coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
         return -EINVAL;
     }
 
-    if (!iscsilun->lbprz || !iscsilun->lbpu ||
-        !(bs->open_flags & BDRV_O_UNMAP)) {
+    if (!iscsi_discard_zeroes(iscsilun) || !(bs->open_flags & BDRV_O_UNMAP)) {
         /* fall back to writev */
         return -ENOTSUP;
     }
@@ -1468,6 +1472,16 @@  out:
     return ret;
 }
 
+static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
+{
+    IscsiLun *iscsilun = bs->opaque;
+
+    bdi->max_unmap = sector_lun2qemu(iscsilun->max_unmap, iscsilun);
+    bdi->discard_zeroes =  iscsi_discard_zeroes(iscsilun);
+
+    return 0;
+}
+
 static QEMUOptionParameter iscsi_create_options[] = {
     {
         .name = BLOCK_OPT_SIZE,
@@ -1488,6 +1502,7 @@  static BlockDriver bdrv_iscsi = {
     .create_options  = iscsi_create_options,
 
     .bdrv_getlength  = iscsi_getlength,
+    .bdrv_get_info   = iscsi_get_info,
     .bdrv_truncate   = iscsi_truncate,
 
     .bdrv_co_is_allocated = iscsi_co_is_allocated,