diff mbox

block/iscsi: precache the allocation status of a target

Message ID 1467284899-22575-1-git-send-email-pl@kamp.de (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Lieven June 30, 2016, 11:08 a.m. UTC
this fills up the allocationmap at iscsi_open. This helps
to reduce the number of get_block_status requests during runtime
significantly.

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

Comments

Paolo Bonzini June 30, 2016, 3:59 p.m. UTC | #1
On 30/06/2016 13:08, Peter Lieven wrote:
> this fills up the allocationmap at iscsi_open. This helps
> to reduce the number of get_block_status requests during runtime
> significantly.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block/iscsi.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 0cdcedb..04fb0a3 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -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;
> +                }
> +            }
>          }
>      }
>  
> 

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
Peter Lieven July 7, 2016, 11:40 a.m. UTC | #2
Am 30.06.2016 um 17:59 schrieb Paolo Bonzini:
>
> On 30/06/2016 13:08, Peter Lieven wrote:
>> this fills up the allocationmap at iscsi_open. This helps
>> to reduce the number of get_block_status requests during runtime
>> significantly.
>>
>> Signed-off-by: Peter Lieven <pl@kamp.de>
>> ---
>>   block/iscsi.c | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>
>> diff --git a/block/iscsi.c b/block/iscsi.c
>> index 0cdcedb..04fb0a3 100644
>> --- a/block/iscsi.c
>> +++ b/block/iscsi.c
>> @@ -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;
>> +                }
>> +            }
>>           }
>>       }
>>   
>>
> 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
Paolo Bonzini July 7, 2016, 12:21 p.m. UTC | #3
On 07/07/2016 13:40, Peter Lieven wrote:
>>>
>> 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
diff mbox

Patch

diff --git a/block/iscsi.c b/block/iscsi.c
index 0cdcedb..04fb0a3 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -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;
+                }
+            }
         }
     }