History | View | Annotate | Download (44.5 kB)
qcow2: Add refcount update reason to all callers
This adds a refcount update reason to all callers of update_refcounts(),so that a follow-up patch can use this information to decide whetherclusters that reach a refcount of 0 should be discarded in the image...
qcow2: Options to enable discard for freed clusters
Deleted snapshots are discarded in the image file by default, discardrequests take their default from the -drive discard=... option and otherplaces that free clusters must always be enabled explicitly....
qcow2: Batch discards
This optimises the discard operation for freed clusters by batchingdiscard requests (both snapshot deletion and bdrv_discard end upupdating the refcounts cluster by cluster).
Note that we don't discard asynchronously, but keep s->lock held. This...
qcow2: Return real error in qcow2_update_snapshot_refcount
This fixes the error message triggered by the following script:
cat > /tmp/blkdebug.cfg <<EOF [inject-error] event = "cluster_free" errno = "28" immediately = "off" EOF
$qemu_img create -f qcow2 test.qcow2 10G...
qcow2: Fix L1 write error handling in qcow2_update_snapshot_refcount
It ignored the error code, and at least the 'goto fail' is obviousnonsense as it creates an endless loop (if the next attempt doesn'tmagically succeed) and leaves the in-memory L1 table in big-endian...
qcow2: Fix "total clusters" number in bdrv_check
This should be based on the virtual disk size, not on the size of theimage.
Interesting observation: With some VM state stored in the image file,percentages higher than 100% are possible, even though snapshots...
qcow2: set L2 cache dependency in qcow2_alloc_bytes()
Compressed writes use qcow2_alloc_bytes() to allocate space with bytegranularity. The affected clusters' refcounts will be incremented butwe do not need to flush yet.
Set a L2 cache dependency on the refcount block cache, so that the...
qcow2: flush in qcow2_update_snapshot_refcount()
Users of qcow2_update_snapshot_refcount() do not flush consistently.qcow2_snapshot_create() flushes but qcow2_snapshot_goto() andqcow2_snapshot_delete() do not.
Solve this by moving the bdrv_flush() into...
qcow2: drop flush in update_cluster_refcount()
The update_cluster_refcount() function increments/decrements a cluster'srefcount and then returns the new refcount value.
There is no need to flush since both update_cluster_refcount() callersalready take care of this:...
qcow2: drop unnecessary flush in qcow2_update_snapshot_refcount()
We already flush when the function completes. There is no need to flushafter every compressed cluster.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: flush refcount cache correctly in alloc_refcount_block()
update_refcount() affects the refcount cache, it does not write to disk.Therefore bdrv_flush(bs->file) does nothing. We need to flush therefcount cache in order to write out the refcount updates!...
qcow2: introduce check_refcounts_l1/l2() flags
The check_refcounts_l1/l2() functions have a check_copied argument tocheck that the QCOW_O_COPIED flag is consistent with refcount == 1.This should be a bool, not an int.
However, the next patch introduces qcow2 fragmentation statistics and...
qcow2: record fragmentation statistics during check
The qemu-img check command can display fragmentation statistics: * Total number of clusters in virtual disk * Number of allocated clusters * Number of fragmented clusters
This patch adds fragmentation statistics support to qcow2....
qcow2: support compressed clusters in BlockFragInfo
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
qemu-img: find the image end offset during check
This patch adds the support for reporting the image end offset (inbytes). This is particularly useful after a conversion (or a rebase)where the destination is a block device in order to find the firstunused byte at the end of the image....
g_malloc(0) and g_malloc0(0) return NULL; simplify
Once upon a time, it was decided that qemu_malloc(0) should abort.Switching to glib retired that bright idea. Some code that was addedto cope with it (e.g. in commits 702ef63, b76b6e9) is still around....
block: move include files to include/block/
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qcow2: Fix refcount table size calculation
A missing factor for the refcount table entry size in the calculationcould mean that too little memory was allocated for the in-memoryrepresentation of the table, resulting in a buffer overflow.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>...
qcow2: preserve free_byte_offset when qcow2_alloc_bytes() fails
When qcow2_alloc_clusters() error handling code was introduced in commit5d757b563d59142ca81e1073a8e8396750a0ad1a, the value of free_byte_offsetwas clobbered in the error case. This patch keeps free_byte_offset at 0...
qcow2: always operate caches in writeback mode
Writethrough does not need special-casing anymore in the qcow2 caches.The block layer adds flushes after every guest-initiated data write,and these will also flush the qcow2 caches to the OS.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>...
qcow2: fix endianness conversion
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: Support for fixing refcount inconsistencies
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: Ignore reserved bits in refcount table entries
qcow2: Ignore reserved bits in check_refcounts
Also don't infer the cluster type directly from the L2 entries, but useqcow2_get_cluster_type() to keep everything in a single place.
qcow2: Support reading zero clusters
This adds support for reading zero clusters in version 3 images.
qcow2: Ignore reserved bits in L1/L2 entries
This changes the still existing places that assume that the only flagsare QCOW_OFLAG_COPIED and QCOW_OFLAG_COMPRESSED to properly mask outreserved bits.
It does not convert bdrv_check yet.
qcow2: Refactor qcow2_free_any_clusters
Zero clusters will add another cluster type. Refactor the open-codedcluster type detection into a switch of QCOW2_CLUSTER_* options so thatthe detection is in a single place. This makes it easier to add newcluster types....
qcow2: Fix refcount block allocation during qcow2_alloc_cluster_at()
Refcount block allocation and refcount table growth rely ons->free_cluster_index pointing to somewhere after the currentallocation. Change qcow2_alloc_cluster_at() to fulfill thisassumption....
qcow2: Fix return value of alloc_refcount_block
Someone forgot something in commit 29c1a730... Documenting the rightreturn value is not enough, you also need to actually return it in thecode.
This bug sometimes causes error return values even when everything has...
qcow2: Add qcow2_alloc_clusters_at()
This function allows to allocate clusters at a given offset in the imagefile. This is useful if you want to allocate the second part of an areathat must be contiguous.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
qcow2: Fix order of refcount updates in qcow2_snapshot_goto
The refcount updates must be moved so that in the worst case we can getcluster leaks, but refcounts may never be too low.
qcow2: remove unused qcow2_create_refcount_update function
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: use always stderr for debugging
let all DEBUG_ALLOC2 printf goes to stderr
Use glib memory allocation and free functions
qemu_malloc/qemu_free no longer exist after this commit.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qcow2: Use Qcow2Cache in writeback mode during loadvm/savevm
In snapshotting there is no guest involved, so we can safely use a writebackmode and do the flushes in the right place (i.e. at the very end). Thisimproves the time that creating/restoring an internal snapshot takes with an...
qcow2: Fix memory leaks in error cases
This fixes memory leaks that may be caused by I/O errors during L1 table growth(can happen during save_vm) and in qemu-img check.
Fix typos in comments and code (occured -> occurred and related)
The code changed here is an unused data type name (evt_flush_occurred).
Signed-off-by: Stefan Weil <weil@mail.berlios.de>Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
qcow2-refcount: remove write-only variables
Variables l2_modified and l2_size are not really used, remove them.Spotted by GCC 4.6.0: CC block/qcow2-refcount.o/src/qemu/block/qcow2-refcount.c: In function 'qcow2_update_snapshot_refcount':/src/qemu/block/qcow2-refcount.c:708:37: error: variable 'l2_modified' set but not used [-Werror=unused-but-set-variable]...
qcow2: Use QcowCache
Use the new functions of qcow2-cache.c for everything that works on refcountblock and L2 tables.
qcow2: Invalidate cache after failed read
The cache content may be destroyed after a failed read, better not use it anymore.
block: avoid a write only variable
Compiling with GCC 4.6.0 20100925 produced a warning:/src/qemu/block/qcow2-refcount.c: In function 'update_refcount':/src/qemu/block/qcow2-refcount.c:552:13: error: variable 'dummy' set but not used [-Werror=unused-but-set-variable]...
qcow2: Move sync out of write_refcount_block_entries
qcow2: Move sync out of update_refcount
Note that the flush is omitted intentionally in qcow2_free_clusters. Ifanything, we can leak clusters here if we lose the writes.
qcow2: Move sync out of qcow2_alloc_clusters
qcow2/vdi: Change check to distinguish error cases
This distinguishes between harmless leaks and real corruption. Hopefully usersbetter understand what qemu-img check wants to tell them.
qcow2: Use bdrv_(p)write_sync for metadata writes
Use bdrv_(p)write_sync to ensure metadata integrity in case of a crash.
qcow2: Fix qemu-img check segfault on corrupted images
With corrupted images, we can easily get an cluster index that exceeds thearray size of the temporary refcount table.
qcow2: Don't try to check tables that couldn't be loaded
Trying to check them leads to a second error message which is more confusingthan helpful:
Can't get refcount for cluster 0: Invalid argument ERROR cluster 0 refcount=-22 reference=1
qcow2: Allow get_refcount to return errors
get_refcount might need to load a refcount block from disk, so errors mayhappen. Return the error code instead of assuming a refcount of 1 and changethe callers to respect error return values.
qcow2: Allow alloc_clusters_noref to return errors
Currently it would consider blocks for which get_refcount fails used. However,it's unlikely that get_refcount would succeed for the next cluster, so it's notreally helpful. Return an error instead.
qcow2: Return real error code in load_refcount_block
This fixes load_refcount_block which completely ignored the return value ofwrite_refcount_block and always returned -EIO for bdrv_pwrite failure.
qcow2: Fix corruption after error in update_refcount
After it is done with updating refcounts in the cache, update_refcount writesall changed entries to disk. If a refcount block allocation fails, however,there was no change yet and therefore first_index = last_index = -1. Don't...
qcow2: Fix corruption after refblock allocation
Refblock allocation code needs to take into consideration that update_refcountwill load a different refcount block into the cache, so it must initialize thecache for a new refcount block only afterwards. Not doing this means that not...
qcow2: Return right error code in write_refcount_block_entries
write_refcount_block_entries used to return -EIO for any errors. Change this toreturn the real error code.
qcow2: Remove abort on free_clusters failure
While it's true that during regular operation free_clusters failure would be abug, an I/O error can always happen. There's no need to kill the VM, the worstthing that can happen (and it will) is that we leak some clusters....
qcow2: Avoid shadowing variable in alloc_clusters_noref()
The i loop iterator is shadowed by the next free cluster index. Bothusing the variable name 'i' makes the code harder to read.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Open the underlying image file in generic code
Format drivers shouldn't need to bother with things like file names, but ratherjust get an open BlockDriverState for the underlying protocol. This patchintroduces this behaviour for bdrv_open implementation. For protocols which...
qcow2: Trigger blkdebug events
This adds blkdebug events to qcow2 to allow injecting I/O errors in specificplaces.
qcow2: Factor next_refcount_table_size out
When the refcount table grows, it doesn't only grow by one entry but reservessome space for future refcount blocks. The algorithm to calculate the number ofentries stays the same with the fixes, so factor it out before replacing the...
qcow2: Rewrite alloc_refcount_block/grow_refcount_table
The current implementation of alloc_refcount_block and grow_refcount_table hasfundamental problems regarding error handling. There are some places where anI/O error means that the image is going to be corrupted. I have found that the...
qcow2: More checks for qemu-img check
Implement some more refcount block related checks
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qcow2: Fix error handling in grow_refcount_table
Return the appropriate error code instead of -EIO.
qcow2: Improve error handling in update_refcount
If update_refcount fails, try to undo any changes made so far to avoidinconsistencies in the image file.
qcow2: Allow updating no refcounts
There's absolutely no problem with updating the refcounts of 0 clusters.At least snapshot code is doing this and would fail once the result ofupdate_refcount isn't ignored any more.
qcow2: Don't ignore update_refcount return value
update_refcount can return errors that need to be handled by the callers.
qcow2: Don't ignore qcow2_alloc_clusters return value
Now that qcow2_alloc_clusters can return error codes, we must handle them inthe callers of qcow2_alloc_clusters.
qcow2-refcount: remove dead assignment
clang-analyzer points out a redundant assignment.
Signed-off-by: Amit Shah <amit.shah@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qcow2: Fix some more qemu_malloc fallout
Oh joy...
qcow2: Fix grow_refcount_table error handling
In case of failure, we haven't increased the refcount for the newly allocatedcluster yet. Therefore we must not free the cluster or its refcount will becomenegative (and endless recursion is possible).
qcow2: Increase maximum cluster size to 2 MB
This patch increases the maximum qcow2 cluster size to 2 MB. Starting with 128kclusters, L2 tables span 2 GB or more of virtual disk space, causing 32 bittruncation and wraparound of signed integers. Therefore some variables need to...
Fix most warnings (errors with -Werror) when debugging is enabled
I used the following command to enable debugging:perl -p -i -e 's/^\/\/#define DEBUG/#define DEBUG/g' * /* *//*
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
qcow2: Fix L1 table memory allocation
Contrary to what one could expect, the size of L1 tables is not clusteraligned. So as we're writing whole sectors now instead of single entries,we need to ensure that the L1 table in memory is large enough; otherwise...
qcow2: Cache refcount blocks during snapshot creation
The really time consuming part of snapshotting is to adjust the reference countof all clusters. Currently after each adjusted cluster the refcount block iswritten to disk.
Don't write each single byte immediately to disk but cache all writes to the...
update_refcount: Write complete sectors
When updating the refcount blocks in update_refcount(), write complete sectorsinstead of updating single entries.
qcow2: Split out refcount handling
qcow2-refcount.c contains all functions which are related to clusterallocation and management in the image file. A large part of this is thereference counting of these clusters.
Also a header file qcow2.h is introduced which will contain the interface of...
qcow2: Split out guest cluster functions
qcow2-cluster.c contains all functions related to the management of guestclusters, i.e. what the guest sees on its virtual disk. This code is aboutmapping these guest clusters to host clusters in the image file using the...
qcow2: Rename global functions
The qcow2 source is now split into several more manageable files. During theconversion quite some functions that were static before needed to be changed tobe global to make the source compile again.
We were lucky enough not to get name conflicts with these additional global...