diff options
author | Kevin Wolf <kwolf@redhat.com> | 2009-06-16 11:31:30 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-06-16 15:18:37 -0500 |
commit | 9923e05e1adbba54b1a646ae39f8aa8fc88d78a6 (patch) | |
tree | 4378680f843a3e6b08ce464b30b84769e022dc77 /block | |
parent | 4c1612d95412bcc487e0c734ad5b738105b67b19 (diff) | |
download | qemu-9923e05e1adbba54b1a646ae39f8aa8fc88d78a6.tar.gz qemu-9923e05e1adbba54b1a646ae39f8aa8fc88d78a6.tar.bz2 qemu-9923e05e1adbba54b1a646ae39f8aa8fc88d78a6.zip |
update_refcount: Write complete sectors
When updating the refcount blocks in update_refcount(), write complete sectors
instead of updating single entries.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/qcow2-refcount.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index b38390cece..dd6e293d05 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -209,6 +209,27 @@ static int64_t alloc_refcount_block(BlockDriverState *bs, int64_t cluster_index) return refcount_block_offset; } +#define REFCOUNTS_PER_SECTOR (512 >> REFCOUNT_SHIFT) +static int write_refcount_block_entries(BDRVQcowState *s, + int64_t refcount_block_offset, int first_index, int last_index) +{ + size_t size; + + first_index &= ~(REFCOUNTS_PER_SECTOR - 1); + last_index = (last_index + REFCOUNTS_PER_SECTOR) + & ~(REFCOUNTS_PER_SECTOR - 1); + + size = (last_index - first_index) << REFCOUNT_SHIFT; + if (bdrv_pwrite(s->hd, + refcount_block_offset + (first_index << REFCOUNT_SHIFT), + &s->refcount_block_cache[first_index], size) != size) + { + return -EIO; + } + + return 0; +} + /* XXX: cache several refcount block clusters ? */ static int update_refcount(BlockDriverState *bs, int64_t offset, int64_t length, @@ -238,10 +259,9 @@ static int update_refcount(BlockDriverState *bs, old_table_index = table_index; table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT); if ((old_table_index >= 0) && (table_index != old_table_index)) { - size_t size = (last_index - first_index + 1) << REFCOUNT_SHIFT; - if (bdrv_pwrite(s->hd, - refcount_block_offset + (first_index << REFCOUNT_SHIFT), - &s->refcount_block_cache[first_index], size) != size) + + if (write_refcount_block_entries(s, refcount_block_offset, + first_index, last_index) < 0) { return -EIO; } @@ -278,10 +298,8 @@ static int update_refcount(BlockDriverState *bs, /* Write last changed block to disk */ if (refcount_block_offset != 0) { - size_t size = (last_index - first_index + 1) << REFCOUNT_SHIFT; - if (bdrv_pwrite(s->hd, - refcount_block_offset + (first_index << REFCOUNT_SHIFT), - &s->refcount_block_cache[first_index], size) != size) + if (write_refcount_block_entries(s, refcount_block_offset, + first_index, last_index) < 0) { return -EIO; } |