[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH stable-0.15 21/36] Teach block/vdi about "discarded"
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PATCH stable-0.15 21/36] Teach block/vdi about "discarded" (no longer allocated) blocks |
Date: |
Wed, 28 Mar 2012 14:52:24 +0200 |
From: Eric Sunshine <address@hidden>
An entry in the VDI block map will hold an offset to the actual block if
the block is allocated, or one of two specially-interpreted values if
not allocated. Using VirtualBox terminology, value VDI_IMAGE_BLOCK_FREE
(0xffffffff) represents a never-allocated block (semantically arbitrary
content). VDI_IMAGE_BLOCK_ZERO (0xfffffffe) represents a "discarded"
block (semantically zero-filled). block/vdi knows only about
VDI_IMAGE_BLOCK_FREE. Teach it about VDI_IMAGE_BLOCK_ZERO.
Signed-off-by: Eric Sunshine <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
(cherry picked from commit c794b4e0fd9ef8d72b068614dcdb2418c105d5cc)
Signed-off-by: Bruce Rogers <address@hidden>
Signed-off-by: Andreas Färber <address@hidden>
---
block/vdi.c | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index 261cf9b..1be0cdc 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -114,8 +114,13 @@ void uuid_unparse(const uuid_t uu, char *out);
*/
#define VDI_TEXT "<<< QEMU VM Virtual Disk Image >>>\n"
-/* Unallocated blocks use this index (no need to convert endianness). */
-#define VDI_UNALLOCATED UINT32_MAX
+/* A never-allocated block; semantically arbitrary content. */
+#define VDI_UNALLOCATED 0xffffffffU
+
+/* A discarded (no longer allocated) block; semantically zero-filled. */
+#define VDI_DISCARDED 0xfffffffeU
+
+#define VDI_IS_ALLOCATED(X) ((X) < VDI_DISCARDED)
#if !defined(CONFIG_UUID)
void uuid_generate(uuid_t out)
@@ -307,10 +312,10 @@ static int vdi_check(BlockDriverState *bs,
BdrvCheckResult *res)
/* Check block map and value of blocks_allocated. */
for (block = 0; block < s->header.blocks_in_image; block++) {
uint32_t bmap_entry = le32_to_cpu(s->bmap[block]);
- if (bmap_entry != VDI_UNALLOCATED) {
+ if (VDI_IS_ALLOCATED(bmap_entry)) {
if (bmap_entry < s->header.blocks_in_image) {
blocks_allocated++;
- if (bmap[bmap_entry] == VDI_UNALLOCATED) {
+ if (!VDI_IS_ALLOCATED(bmap[bmap_entry])) {
bmap[bmap_entry] = bmap_entry;
} else {
fprintf(stderr, "ERROR: block index %" PRIu32
@@ -472,7 +477,7 @@ static int vdi_is_allocated(BlockDriverState *bs, int64_t
sector_num,
n_sectors = nb_sectors;
}
*pnum = n_sectors;
- return bmap_entry != VDI_UNALLOCATED;
+ return VDI_IS_ALLOCATED(bmap_entry);
}
static void vdi_aio_cancel(BlockDriverAIOCB *blockacb)
@@ -603,7 +608,7 @@ static void vdi_aio_read_cb(void *opaque, int ret)
/* prepare next AIO request */
acb->n_sectors = n_sectors;
bmap_entry = le32_to_cpu(s->bmap[block_index]);
- if (bmap_entry == VDI_UNALLOCATED) {
+ if (!VDI_IS_ALLOCATED(bmap_entry)) {
/* Block not allocated, return zeros, no need to wait. */
memset(acb->buf, 0, n_sectors * SECTOR_SIZE);
ret = vdi_schedule_bh(vdi_aio_rw_bh, acb);
@@ -685,7 +690,7 @@ static void vdi_aio_write_cb(void *opaque, int ret)
if (acb->header_modified) {
VdiHeader *header = acb->block_buffer;
logout("now writing modified header\n");
- assert(acb->bmap_first != VDI_UNALLOCATED);
+ assert(VDI_IS_ALLOCATED(acb->bmap_first));
*header = s->header;
vdi_header_to_le(header);
acb->header_modified = 0;
@@ -699,7 +704,7 @@ static void vdi_aio_write_cb(void *opaque, int ret)
goto done;
}
return;
- } else if (acb->bmap_first != VDI_UNALLOCATED) {
+ } else if (VDI_IS_ALLOCATED(acb->bmap_first)) {
/* One or more new blocks were allocated. */
uint64_t offset;
uint32_t bmap_first;
@@ -749,7 +754,7 @@ static void vdi_aio_write_cb(void *opaque, int ret)
/* prepare next AIO request */
acb->n_sectors = n_sectors;
bmap_entry = le32_to_cpu(s->bmap[block_index]);
- if (bmap_entry == VDI_UNALLOCATED) {
+ if (!VDI_IS_ALLOCATED(bmap_entry)) {
/* Allocate new block and write to it. */
uint64_t offset;
uint8_t *block;
--
1.7.7
- [Qemu-devel] [PATCH stable-0.15 25/36] block: Fix vpc initialization of the Dynamic Disk Header, (continued)
- [Qemu-devel] [PATCH stable-0.15 25/36] block: Fix vpc initialization of the Dynamic Disk Header, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 15/36] ac97: don't override the pci subsystem id, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 08/36] vmdk: vmdk_read_cid returns garbage if p_name is NULL, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 14/36] hw/lan9118.c: Add missing 'break' to fix buffer overrun, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 18/36] block/curl: Implement a flush function on the fd handlers, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 05/36] e1000: bounds packet size against buffer size, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 20/36] hda: do not mix output and input stream states, RHBZ #740493, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 23/36] block: set bs->read_only before .bdrv_open(), Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 12/36] migration: flush migration data to disk., Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 27/36] block: reinitialize across bdrv_close()/bdrv_open(), Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 21/36] Teach block/vdi about "discarded" (no longer allocated) blocks,
Andreas Färber <=
- [Qemu-devel] [PATCH stable-0.15 17/36] vns/tls: don't use depricated gnutls functions, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 06/36] compatfd.c: Don't pass NULL pointer to SYS_signalfd, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 29/36] vmdk: Fix possible segfaults, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 22/36] vmdk: Improve error handling, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 28/36] qxl: stride fixup, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 19/36] hda: do not mix output and input streams, RHBZ #740493, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 26/36] qcow: Fix bdrv_write_compressed error handling, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 33/36] pc: add pc-0.15, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 32/36] Error check find_ram_offset, Andreas Färber, 2012/03/28
- [Qemu-devel] [PATCH stable-0.15 31/36] cpu-common: Have a ram_addr_t of uint64 with Xen., Andreas Färber, 2012/03/28