Skip to contentSkip to conversation

block/iscsi: precache the allocation status of a target

PATCH In review Peter Lieven 2 participants 4 messages Jun 30, 2016 – Jul 7, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/iscsi: precache the allocation status of a target

this fills up the allocationmap at iscsi_open. This helps to reduce the number of get_block_status requests during runtime significantly.

---
 block/iscsi.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/iscsi.c +16 -0
index 0cdcedb..04fb0a3 100644
@@ -1774,6 +1774,22 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
                                      iscsilun->block_size) >> BDRV_SECTOR_BITS;
         if (iscsilun->lbprz) {
             ret = iscsi_allocmap_init(iscsilun, bs->open_flags);
+            if (ret == 0) {
+                unsigned int max_reqs = 64;
+                int64_t sector_num = 0;
+                while (max_reqs-- && sector_num < bs->total_sectors) {
+                    int n;
+                    BlockDriverState *file;
+                    ret = bdrv_get_block_status(bs, sector_num,
+                                                BDRV_REQUEST_MAX_SECTORS,
+                                                &n, &file);
+                    if (ret < 0) {
+                        break;
+                    }
+                    sector_num += n;
+                    ret = 0;
+                }
+            }
         }
     }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 27 lines · Peter Lieven

this fills up the allocationmap at iscsi_open. This helps to reduce the number of get_block_status requests during runtime significantly.

---
 block/iscsi.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/iscsi.c +9 -0
index 0cdcedb..04fb0a3 100644
@@ -1774,6 +1774,22 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
                                      iscsilun->block_size) >> BDRV_SECTOR_BITS;
         if (iscsilun->lbprz) {
             ret = iscsi_allocmap_init(iscsilun, bs->open_flags);
+            if (ret == 0) {
+                unsigned int max_reqs = 64;
+                int64_t sector_num = 0;
+                while (max_reqs-- && sector_num < bs->total_sectors) {
+                    int n;
+                    BlockDriverState *file;
+                    ret = bdrv_get_block_status(bs, sector_num,
+                                                BDRV_REQUEST_MAX_SECTORS,
+                                                &n, &file);

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1795

Quoted 10 lines
block/iscsi.c +7 -0
+                    if (ret < 0) {
+                        break;
+                    }
+                    sector_num += n;
+                    ret = 0;
+                }
+            }
         }
     }
 

This can take a long time and the disks may not even be ever used. I don't think it's a good idea.

Paolo

#2 lore raw

Am 30.06.2016 um 17:59 schrieb Paolo Bonzini:

Quoted 33 lines · Peter Lieven
Quoted 31 lines

this fills up the allocationmap at iscsi_open. This helps to reduce the number of get_block_status requests during runtime significantly.

---
  block/iscsi.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
block/iscsi.c +14 -0
index 0cdcedb..04fb0a3 100644
@@ -1774,6 +1774,22 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
                                       iscsilun->block_size) >> BDRV_SECTOR_BITS;
          if (iscsilun->lbprz) {
              ret = iscsi_allocmap_init(iscsilun, bs->open_flags);
+            if (ret == 0) {
+                unsigned int max_reqs = 64;
+                int64_t sector_num = 0;
+                while (max_reqs-- && sector_num < bs->total_sectors) {
+                    int n;
+                    BlockDriverState *file;
+                    ret = bdrv_get_block_status(bs, sector_num,
+                                                BDRV_REQUEST_MAX_SECTORS,
+                                                &n, &file);
+                    if (ret < 0) {
+                        break;
+                    }
+                    sector_num += n;
+                    ret = 0;
Quoted 8 lines

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1795

Quoted 6 lines
block/iscsi.c +2 -0
+                }
+            }
          }
      }
 

This can take a long time and the disks may not even be ever used. I don't think it's a good idea.

Sure, the target might stay unused, but why do you suspect its slow?

Peter

#3 lore raw
Quoted 5 lines · Peter Lieven
Quoted 3 lines
Quoted 1 line

This can take a long time and the disks may not even be ever used. I don't think it's a good idea.

Sure, the target might stay unused, but why do you suspect its slow?

I don't suspect it's slow; it's just that it can be O(size of disk), and can send really a lot of commands down the link. I don't think it's a good thing to do in advance.

Paolo