[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v9 07/13] qcow2: Discard/zero clusters by byte c
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v9 07/13] qcow2: Discard/zero clusters by byte count |
Date: |
Tue, 11 Apr 2017 17:12:29 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
On 04/10/2017 08:17 PM, Eric Blake wrote:
> Passing a byte offset, but sector count, when we ultimately
> want to operate on cluster granularity, is madness. Clean up
> the external interfaces to take both offset and count as bytes,
> while still keeping the assertion added previously that the
> caller must align the values to a cluster. Then rename things
> to make sure backports don't get confused by changed units:
> instead of qcow2_discard_clusters() and qcow2_zero_clusters(),
> we now have qcow2_cluster_discard() and qcow2_cluster_zeroize().
>
> The internal functions still operate on clusters at a time, and
> return an int for number of cleared clusters; but on an image
> with 2M clusters, a single L2 table holds 256k entries that each
> represent a 2M cluster, totalling well over INT_MAX bytes if we
> ever had a request for that many bytes at once. All our callers
> currently limit themselves to 32-bit bytes (and therefore fewer
> clusters), but by making this function 64-bit clean, we have one
> less place to clean up if we later improve the block layer to
> support 64-bit bytes through all operations (with the block layer
> auto-fragmenting on behalf of more-limited drivers), rather than
> the current state where some interfaces are artificially limited
> to INT_MAX at a time.
>
> Signed-off-by: Eric Blake <address@hidden>
>
> +int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
> + uint64_t bytes, int flags)
> {
> BDRVQcow2State *s = bs->opaque;
> uint64_t end_offset;
> uint64_t nb_clusters;
> + int64_t cleared;
> int ret;
>
> - end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
> + end_offset = offset + bytes;
>
> /* Caller must pass aligned values, except at image end */
> assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
> assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
> end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
> + assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
And I promptly botched my rebasing. qemu-iotests 154 caught my mistake
(the whole point of calculating end_offset is because bytes need not be
cluster-aligned if end_offset is at EOF). I'll send the obvious fixup.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v9 04/13] qemu-io: Switch 'map' output to byte-based reporting, (continued)
- [Qemu-devel] [PATCH v9 04/13] qemu-io: Switch 'map' output to byte-based reporting, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 02/13] iotests: Add test 179 to cover write zeroes with unmap, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 06/13] qcow2: Assert that cluster operations are aligned, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 09/13] blkdebug: Refactor error injection, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 03/13] qemu-io: Switch 'alloc' command to byte-based length, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 01/13] qcow2: Unallocate unmapped zero clusters if no backing file, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 05/13] qcow2: Optimize write zero of unaligned tail cluster, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 07/13] qcow2: Discard/zero clusters by byte count, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 08/13] blkdebug: Sanity check block layer guarantees, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 10/13] blkdebug: Add pass-through write_zero and discard support, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 12/13] blkdebug: Add ability to override unmap geometries, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 11/13] blkdebug: Simplify override logic, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 13/13] tests: Add coverage for recent block geometry fixes, Eric Blake, 2017/04/10