* [Qemu-devel] [PATCH v2] block: Fix bdrv_is_allocated() for short backing files
@ 2014-05-07 8:31 Kevin Wolf
2014-05-08 17:57 ` Max Reitz
0 siblings, 1 reply; 2+ messages in thread
From: Kevin Wolf @ 2014-05-07 8:31 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, pbonzini, stefanha, mreitz
bdrv_is_allocated() shouldn't return true for sectors that are
unallocated, but after the end of a short backing file, even though
such sectors are (correctly) marked as containing zeros.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
v2:
- Set BDRV_BLOCK_ALLOCATED for !drv->bdrv_co_get_block_status (Max)
block.c | 10 ++++++----
include/block/block.h | 11 +++++++----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/block.c b/block.c
index c90c71a..65e8191 100644
--- a/block.c
+++ b/block.c
@@ -3864,7 +3864,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
if (!bs->drv->bdrv_co_get_block_status) {
*pnum = nb_sectors;
- ret = BDRV_BLOCK_DATA;
+ ret = BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED;
if (bs->drv->protocol_name) {
ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE);
}
@@ -3883,6 +3883,10 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
*pnum, pnum);
}
+ if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) {
+ ret |= BDRV_BLOCK_ALLOCATED;
+ }
+
if (!(ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO)) {
if (bdrv_unallocated_blocks_are_zero(bs)) {
ret |= BDRV_BLOCK_ZERO;
@@ -3959,9 +3963,7 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num,
if (ret < 0) {
return ret;
}
- return
- (ret & BDRV_BLOCK_DATA) ||
- ((ret & BDRV_BLOCK_ZERO) && !bdrv_has_zero_init(bs));
+ return (ret & BDRV_BLOCK_ALLOCATED);
}
/*
diff --git a/include/block/block.h b/include/block/block.h
index 2fda81c..ad4c7e8 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -116,6 +116,8 @@ typedef enum {
/* BDRV_BLOCK_DATA: data is read from bs->file or another file
* BDRV_BLOCK_ZERO: sectors read as zero
* BDRV_BLOCK_OFFSET_VALID: sector stored in bs->file as raw data
+ * BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
+ * layer (as opposed to the backing file)
* BDRV_BLOCK_RAW: used internally to indicate that the request
* was answered by the raw driver and that one
* should look in bs->file directly.
@@ -137,10 +139,11 @@ typedef enum {
* f t f not allocated or unknown offset, read as zero
* f f f not allocated or unknown offset, read from backing_hd
*/
-#define BDRV_BLOCK_DATA 1
-#define BDRV_BLOCK_ZERO 2
-#define BDRV_BLOCK_OFFSET_VALID 4
-#define BDRV_BLOCK_RAW 8
+#define BDRV_BLOCK_DATA 0x01
+#define BDRV_BLOCK_ZERO 0x02
+#define BDRV_BLOCK_OFFSET_VALID 0x04
+#define BDRV_BLOCK_RAW 0x08
+#define BDRV_BLOCK_ALLOCATED 0x10
#define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASK
typedef enum {
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v2] block: Fix bdrv_is_allocated() for short backing files
2014-05-07 8:31 [Qemu-devel] [PATCH v2] block: Fix bdrv_is_allocated() for short backing files Kevin Wolf
@ 2014-05-08 17:57 ` Max Reitz
0 siblings, 0 replies; 2+ messages in thread
From: Max Reitz @ 2014-05-08 17:57 UTC (permalink / raw)
To: Kevin Wolf, qemu-devel; +Cc: pbonzini, stefanha
On 07.05.2014 10:31, Kevin Wolf wrote:
> bdrv_is_allocated() shouldn't return true for sectors that are
> unallocated, but after the end of a short backing file, even though
> such sectors are (correctly) marked as containing zeros.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> v2:
> - Set BDRV_BLOCK_ALLOCATED for !drv->bdrv_co_get_block_status (Max)
>
> block.c | 10 ++++++----
> include/block/block.h | 11 +++++++----
> 2 files changed, 13 insertions(+), 8 deletions(-)
Reviewed-by: Max Reitz <mreitz@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-08 17:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-07 8:31 [Qemu-devel] [PATCH v2] block: Fix bdrv_is_allocated() for short backing files Kevin Wolf
2014-05-08 17:57 ` Max Reitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).