Patchwork [PATCHv4] block/get_block_status: avoid redundant callouts on raw devices

login
register
mail settings
Submitter Peter Lieven
Date Oct. 2, 2013, 4:02 p.m.
Message ID <524C439A.6050003@kamp.de>
Download mbox | patch
Permalink /patch/279800/
State New
Headers show

Comments

Peter Lieven - Oct. 2, 2013, 4:02 p.m.
Am 02.10.2013 17:13, schrieb Paolo Bonzini:
> Il 02/10/2013 17:06, Stefan Hajnoczi ha scritto:
>> Sorry I didn't review this earlier but this flag looks hacky and I'm not
>> confident about merging the patch yet.
>>
>> The patch makes me wonder if the raw_bsd driver should avoid calling
>> bs->file itself:
>>
>> return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID |
>>        (sector_num << BDRV_SECTOR_BITS);
>>
>> Let block.c:bdrv_co_get_block_status() call down into bs->file.
>>
>> The problem is then the protocol cannot report unallocated sectors with
>> this approach.
>>
>> I think we want to preserve bs' offset while taking the other flags from
>> bs->file (DATA, ZERO).
> This would cause other changes.  For example, a qcow2 with full metadata
> preallocation (i.e. all L2 tables are there but it points to holes)
> would not return DATA anymore.  I think this is wrong, and especially a
> change from the old is_allocated API.
>
> However, a variant on this idea could be to return
>
>    BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID |
>         (sector_num << BDRV_SECTOR_BITS);
>
> and then BDRV_BLOCK_RAW would mean "take DATA and ZERO from bs->file".
Like this?

Patch

diff --git a/block.c b/block.c
index 93e113a..71fab1f 100644
--- a/block.c
+++ b/block.c
@@ -3146,6 +3146,10 @@  static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
         *pnum = 0;
         return ret;
     }
+   
+    if (ret & BDRV_BLOCK_RAW) {
+        return bdrv_get_block_status(bs->file, sector_num, nb_sectors, pnum);
+    }
 
     if (!(ret & BDRV_BLOCK_DATA)) {
         if (bdrv_has_zero_init(bs)) {
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index d4ace60..308d605 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -62,7 +62,8 @@  static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
                                             int64_t sector_num,
                                             int nb_sectors, int *pnum)
 {
-    return bdrv_get_block_status(bs->file, sector_num, nb_sectors, pnum);
+    return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID |
+           (sector_num << BDRV_SECTOR_BITS);
 }