[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 039/100] block: Minimize raw use of bds->total_sector
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 039/100] block: Minimize raw use of bds->total_sectors |
Date: |
Fri, 7 Jul 2017 19:07:54 +0200 |
From: Eric Blake <address@hidden>
bdrv_is_allocated_above() was relying on intermediate->total_sectors,
which is a field that can have stale contents depending on the value
of intermediate->has_variable_length. An audit shows that we are safe
(we were first calling through bdrv_co_get_block_status() which in
turn calls bdrv_nb_sectors() and therefore just refreshed the current
length), but it's nicer to favor our accessor functions to avoid having
to repeat such an audit, even if it means refresh_total_sectors() is
called more frequently.
Suggested-by: John Snow <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Manos Pitsidianakis <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Reviewed-by: John Snow <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/io.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/block/io.c b/block/io.c
index 6656d7f..aad7fd3 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1947,6 +1947,7 @@ int bdrv_is_allocated_above(BlockDriverState *top,
intermediate = top;
while (intermediate && intermediate != base) {
int64_t pnum_inter;
+ int64_t size_inter;
int psectors_inter;
ret = bdrv_is_allocated(intermediate, sector_num * BDRV_SECTOR_SIZE,
@@ -1962,15 +1963,12 @@ int bdrv_is_allocated_above(BlockDriverState *top,
return 1;
}
- /*
- * [sector_num, nb_sectors] is unallocated on top but intermediate
- * might have
- *
- * [sector_num+x, nr_sectors] allocated.
- */
+ size_inter = bdrv_nb_sectors(intermediate);
+ if (size_inter < 0) {
+ return size_inter;
+ }
if (n > psectors_inter &&
- (intermediate == top ||
- sector_num + psectors_inter < intermediate->total_sectors)) {
+ (intermediate == top || sector_num + psectors_inter < size_inter))
{
n = psectors_inter;
}
--
1.8.3.1
- [Qemu-block] [PULL 029/100] mirror: Update signature of mirror_clip_sectors(), (continued)
- [Qemu-block] [PULL 029/100] mirror: Update signature of mirror_clip_sectors(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 027/100] mirror: Switch MirrorBlockJob to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 030/100] mirror: Switch mirror_cow_align() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 031/100] mirror: Switch mirror_do_read() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 032/100] mirror: Switch mirror_iteration() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 033/100] block: Drop unused bdrv_round_sectors_to_clusters(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 034/100] backup: Switch BackupBlockJob to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 037/100] backup: Switch backup_run() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 035/100] backup: Switch block_backup.h to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 036/100] backup: Switch backup_do_cow() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 039/100] block: Minimize raw use of bds->total_sectors,
Kevin Wolf <=
- [Qemu-block] [PULL 040/100] block: Make bdrv_is_allocated_above() byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 038/100] block: Make bdrv_is_allocated() byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 044/100] qcow: require image size to be > 1 for new images, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 042/100] block: add ability to set a prefix for opt names, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 043/100] qcow: document another weakness of qcow AES encryption, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 046/100] iotests: skip 048 with qcow which doesn't support resize, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 041/100] block: expose crypto option names / defs to other drivers, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 045/100] iotests: skip 042 with qcow which dosn't support zero sized images, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 049/100] qcow: convert QCow to use QCryptoBlock for encryption, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 047/100] block: deprecate "encryption=on" in favor of "encrypt.format=aes", Kevin Wolf, 2017/07/07