Skip to content
  • Nir Soffer's avatar
    0da98568
    nbd: server: Report holes for raw images · 0da98568
    Nir Soffer authored
    When querying image extents for raw image, qemu-nbd reports holes as
    zero:
    
    $ qemu-nbd -t -r -f raw empty-6g.raw
    
    $ qemu-img map --output json nbd://localhost
    [{ "start": 0, "length": 6442450944, "depth": 0, "zero": true, "data": true, "offset": 0}]
    
    $ qemu-img map --output json empty-6g.raw
    [{ "start": 0, "length": 6442450944, "depth": 0, "zero": true, "data": false, "offset": 0}]
    
    Turns out that qemu-img map reports a hole based on BDRV_BLOCK_DATA, but
    nbd server reports a hole based on BDRV_BLOCK_ALLOCATED.
    
    The NBD protocol says:
    
        NBD_STATE_HOLE (bit 0): if set, the block represents a hole (and
        future writes to that area may cause fragmentation or encounter an
        NBD_ENOSPC error); if clear, the block is allocated or the server
        could not otherwise determine its status.
    
    qemu-img manual says:
    
        whether the sectors contain actual data or not (boolean field data;
        if false, the sectors are either unallocated or stored as
        optimized all-zero clusters);
    
    To me, data=false looks compatible with NBD_STATE_HOLE. From user point
    of view, getting same results from qemu-nbd and qemu-img is more
    important than being more correct about allocation status.
    
    Changing nbd server to report holes using BDRV_BLOCK_DATA makes qemu-nbd
    results compatible with qemu-img map:
    
    $ qemu-img map --output json nbd://localhost
    
    
    [{ "start": 0, "length": 6442450944, "depth": 0, "zero": true, "data": false, "offset": 0}]
    
    Signed-off-by: default avatarNir Soffer <nsoffer@redhat.com>
    Message-Id: <20210219160752.1826830-1-nsoffer@redhat.com>
    Reviewed-by: default avatarEric Blake <eblake@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    0da98568
    nbd: server: Report holes for raw images
    Nir Soffer authored
    When querying image extents for raw image, qemu-nbd reports holes as
    zero:
    
    $ qemu-nbd -t -r -f raw empty-6g.raw
    
    $ qemu-img map --output json nbd://localhost
    [{ "start": 0, "length": 6442450944, "depth": 0, "zero": true, "data": true, "offset": 0}]
    
    $ qemu-img map --output json empty-6g.raw
    [{ "start": 0, "length": 6442450944, "depth": 0, "zero": true, "data": false, "offset": 0}]
    
    Turns out that qemu-img map reports a hole based on BDRV_BLOCK_DATA, but
    nbd server reports a hole based on BDRV_BLOCK_ALLOCATED.
    
    The NBD protocol says:
    
        NBD_STATE_HOLE (bit 0): if set, the block represents a hole (and
        future writes to that area may cause fragmentation or encounter an
        NBD_ENOSPC error); if clear, the block is allocated or the server
        could not otherwise determine its status.
    
    qemu-img manual says:
    
        whether the sectors contain actual data or not (boolean field data;
        if false, the sectors are either unallocated or stored as
        optimized all-zero clusters);
    
    To me, data=false looks compatible with NBD_STATE_HOLE. From user point
    of view, getting same results from qemu-nbd and qemu-img is more
    important than being more correct about allocation status.
    
    Changing nbd server to report holes using BDRV_BLOCK_DATA makes qemu-nbd
    results compatible with qemu-img map:
    
    $ qemu-img map --output json nbd://localhost
    
    
    [{ "start": 0, "length": 6442450944, "depth": 0, "zero": true, "data": false, "offset": 0}]
    
    Signed-off-by: default avatarNir Soffer <nsoffer@redhat.com>
    Message-Id: <20210219160752.1826830-1-nsoffer@redhat.com>
    Reviewed-by: default avatarEric Blake <eblake@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
Loading