Skip to content
  • Eric Blake's avatar
    890cbccb
    nbd: Fix large trim/zero requests · 890cbccb
    Eric Blake authored
    Although qemu as NBD client limits requests to <2G, the NBD protocol
    allows clients to send requests almost all the way up to 4G.  But
    because our block layer is not yet 64-bit clean, we accidentally wrap
    such requests into a negative size, and fail with EIO instead of
    performing the intended operation.
    
    The bug is visible in modern systems with something as simple as:
    
    $ qemu-img create -f qcow2 /tmp/image.img 5G
    $ sudo qemu-nbd --connect=/dev/nbd0 /tmp/image.img
    $ sudo blkdiscard /dev/nbd0
    
    or with user-space only:
    
    $ truncate --size=3G file
    $ qemu-nbd -f raw file
    $ nbdsh -u nbd://localhost:10809 -c 'h.trim(3*1024*1024*1024,0)'
    
    Although both blk_co_pdiscard and blk_pwrite_zeroes currently return 0
    on success, this is also a good time to fix our code to a more robust
    paradigm that treats all non-negative values as success.
    
    Alas, our iotests do not currently make it easy to add external
    dependencies on blkdiscard or nbdsh, so we have to rely on manual
    testing for now.
    
    This patch can be reverted when we later improve the overall block
    layer to be 64-bit clean, but for now, a minimal fix was deemed less
    risky prior to release.
    
    CC: qemu-stable@nongnu.org
    Fixes: 1f4d6d18
    Fixes: 1c6c4bb7
    Fixes: https://github.com/systemd/systemd/issues/16242
    
    
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Message-Id: <20200722212231.535072-1-eblake@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    [eblake: rework success tests to use >=0]
    890cbccb
    nbd: Fix large trim/zero requests
    Eric Blake authored
    Although qemu as NBD client limits requests to <2G, the NBD protocol
    allows clients to send requests almost all the way up to 4G.  But
    because our block layer is not yet 64-bit clean, we accidentally wrap
    such requests into a negative size, and fail with EIO instead of
    performing the intended operation.
    
    The bug is visible in modern systems with something as simple as:
    
    $ qemu-img create -f qcow2 /tmp/image.img 5G
    $ sudo qemu-nbd --connect=/dev/nbd0 /tmp/image.img
    $ sudo blkdiscard /dev/nbd0
    
    or with user-space only:
    
    $ truncate --size=3G file
    $ qemu-nbd -f raw file
    $ nbdsh -u nbd://localhost:10809 -c 'h.trim(3*1024*1024*1024,0)'
    
    Although both blk_co_pdiscard and blk_pwrite_zeroes currently return 0
    on success, this is also a good time to fix our code to a more robust
    paradigm that treats all non-negative values as success.
    
    Alas, our iotests do not currently make it easy to add external
    dependencies on blkdiscard or nbdsh, so we have to rely on manual
    testing for now.
    
    This patch can be reverted when we later improve the overall block
    layer to be 64-bit clean, but for now, a minimal fix was deemed less
    risky prior to release.
    
    CC: qemu-stable@nongnu.org
    Fixes: 1f4d6d18
    Fixes: 1c6c4bb7
    Fixes: https://github.com/systemd/systemd/issues/16242
    
    
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Message-Id: <20200722212231.535072-1-eblake@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    [eblake: rework success tests to use >=0]
Loading