[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 17/18] nbd: BLOCK_STATUS for standard get_block_
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 17/18] nbd: BLOCK_STATUS for standard get_block_status function: server part |
Date: |
Wed, 15 Feb 2017 18:02:28 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
On 09/02/2017 16:38, Eric Blake wrote:
>> +static int blockstatus_to_extent(BlockDriverState *bs, uint64_t offset,
>> + uint64_t length, NBDExtent *extent)
>> +{
>> + BlockDriverState *file;
>> + uint64_t start_sector = offset >> BDRV_SECTOR_BITS;
>> + uint64_t last_sector = (offset + length - 1) >> BDRV_SECTOR_BITS;
> Converting from bytes to sectors by rounding...
>
>> + uint64_t begin = start_sector;
>> + uint64_t end = last_sector + 1;
>> +
>> + int nb = MIN(INT_MAX, end - begin);
>> + int64_t ret = bdrv_get_block_status_above(bs, NULL, begin, nb, &nb,
>> &file);
>> + if (ret < 0) {
>> + return ret;
>> + }
>> +
>> + extent->flags =
>> + cpu_to_be32((ret & BDRV_BLOCK_ALLOCATED ? 0 : NBD_STATE_HOLE) |
>> + (ret & BDRV_BLOCK_ZERO ? NBD_STATE_ZERO : 0));
>> + extent->length = cpu_to_be32((nb << BDRV_SECTOR_BITS) -
>> + (offset - (start_sector <<
>> BDRV_SECTOR_BITS)));
> ...then computing the length by undoing the rounding. I really think we
> should consider fixing bdrv_get_block_status_above() to be byte-based,
> but that's a separate series. Your calculations look correct in the
> meantime, although '(offset & (BDRV_SECTOR_SIZE - 1))' may be a bit
> easier to read than '(offset - (start_sector << BDRV_SECTOR_BITS))'.
Agreed. And please make it a separate variable, i.e.
uint64_t length;
length = (nb << BDRV_SECTOR_BITS) - (offset & BDRV_SECTOR_SIZE - 1);
...
extent->length = cpu_to_be32(length);
Paolo
Paolo
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [PATCH 04/18] nbd/client: refactor nbd_receive_starttls, (continued)
- [Qemu-devel] [PATCH 02/18] nbd-server: refactor simple reply sending, Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 07/18] nbd: Minimal structured read for client, Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 12/18] nbd: BLOCK_STATUS for bitmap export: client part, Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 17/18] nbd: BLOCK_STATUS for standard get_block_status function: server part, Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 16/18] iotests: add test for nbd dirty bitmap export, Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 09/18] block/dirty-bitmap: add bdrv_dirty_bitmap_next(), Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 11/18] nbd: BLOCK_STATUS for bitmap export: server part, Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 13/18] nbd: add nbd_dirty_bitmap_load, Vladimir Sementsov-Ogievskiy, 2017/02/03
- [Qemu-devel] [PATCH 15/18] qmp: add block-dirty-bitmap-load, Vladimir Sementsov-Ogievskiy, 2017/02/03