[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 19/20] block: Minimize raw use of bds->total_sect
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v2 19/20] block: Minimize raw use of bds->total_sectors |
Date: |
Wed, 10 May 2017 21:20:35 -0500 |
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>
---
v2: new patch
---
block/io.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index 9ab89cb..20d3ebd 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1939,6 +1939,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,
@@ -1956,13 +1957,14 @@ int bdrv_is_allocated_above(BlockDriverState *top,
/*
* [sector_num, nb_sectors] is unallocated on top but intermediate
- * might have
- *
- * [sector_num+x, nr_sectors] allocated.
+ * might have [sector_num+x, nb_sectors-x] 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;
}
--
2.9.3
- [Qemu-devel] [PATCH v2 08/20] mirror: Switch mirror_do_zero_or_discard() to byte-based, (continued)
- [Qemu-devel] [PATCH v2 08/20] mirror: Switch mirror_do_zero_or_discard() to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 09/20] mirror: Update signature of mirror_clip_sectors(), Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 10/20] mirror: Switch mirror_cow_align() to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 11/20] mirror: Switch mirror_do_read() to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 12/20] mirror: Switch mirror_iteration() to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 13/20] block: Drop unused bdrv_round_sectors_to_clusters(), Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 14/20] backup: Switch BackupBlockJob to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 15/20] backup: Switch block_backup.h to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 16/20] backup: Switch backup_do_cow() to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 17/20] backup: Switch backup_run() to byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 19/20] block: Minimize raw use of bds->total_sectors,
Eric Blake <=
- [Qemu-devel] [PATCH v2 18/20] block: Make bdrv_is_allocated() byte-based, Eric Blake, 2017/05/10
- [Qemu-devel] [PATCH v2 20/20] block: Make bdrv_is_allocated_above() byte-based, Eric Blake, 2017/05/10