History | View | Annotate | Download (54.6 kB)
qcow2: Set zero flag for discarded clusters
Instead of making the backing file contents visible again after a discardrequest, set the zero flag if possible (i.e. on version >= 3).
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Eric Blake <eblake@redhat.com>
qcow2: remove n_start and n_end of qcow2_alloc_cluster_offset()
n_start can be actually calculated from offset. The number ofsectors to be allocated(n_end - n_start) can be passed in innum. By removing n_start and n_end, we can save two parameters.
The side effect is there is a bug in qcow2.c:preallocate() that...
qcow2: use start_of_cluster() and offset_into_cluster() everywhere
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>Reviewed-by: Fam Zheng <famz@redhat.com>Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block: add flags to bdrv_*_write_zeroes
Reviewed-by: Eric Blake <eblake@redhat.com>Signed-off-by: Peter Lieven <pl@kamp.de>Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
qcow2: fix possible corruption when reading multiple clusters
if multiple sectors spanning multiple clusters are read thefunction count_contiguous_clusters should ensure that thecluster type should not change between the clusters.
Especially the for-loop should break when we have one...
bswap.h: Remove cpu_to_be64wu()
Replace the legacy cpu_to_be64wu() with stq_be_p().
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>Reviewed-by: Richard Henderson <rth@twiddle.net>Reviewed-by: Michael S. Tsirkin <mst@redhat.com>Message-id: 1383669517-25598-9-git-send-email-peter.maydell@linaro.org...
qcow2: Use negated overflow check mask
In qcow2_check_metadata_overlap and qcow2_pre_write_overlap_check,change the parameter signifying the checks to perform from its currentpositive form to a negative one, i.e., it will no longer explicitlyspecify every check to perform but rather a mask of checks not to...
qcow2: Free allocated L2 cluster on error
If an error occurs in l2_allocate, the allocated (but unused) L2 clustershould be freed.
Signed-off-by: Max Reitz <mreitz@redhat.com>Reviewed-by: Benoit Canet <benoit@irqsave.net>Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
qcow2: Switch L1 table in a single sequence
Switching the L1 table in memory should be an atomic operation, as faras possible. Calling qcow2_free_clusters on the old L1 table on disk isnot a good idea when the old L1 table is no longer valid and the address...
qcow2: Always use error path in l2_allocate
Just returning -errno in some cases preventstrace_qcow2_l2_allocate_done from being executed (and, in one case, alsothe unused allocated L2 table from being freed). Always going down theerror path fixes this....
qcow2: Free only newly allocated clusters on error
In expand_zero_clusters_in_l1, a new cluster is only allocated if it wasnot already preallocated. On error, such preallocated clusters shouldnot be freed, but only the newly allocated ones.
Signed-off-by: Max Reitz <mreitz@redhat.com>...
qcow2: count_contiguous_clusters and compression
The function is not intended to be used on compressed clusters and willnot work correctly, if used anyway, since L2E_OFFSET_MASK is not theright mask for determining the offset of compressed clusters. Therefore,...
qcow2: COMPRESSED on count_contiguous_clusters
Compressed clusters can never be contiguous, therefore the correspondingflag does not need to be given explicitly to count_contiguous_clusters.
Signed-off-by: Max Reitz <mreitz@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: Remove useless count_contiguous_clusters() parameter
All callers pass start = 0, and it's doubtful if any other value wouldactually do what you expect. Remove the parameter.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Jeff Cody <jcody@redhat.com>
qcow2: Don't put invalid L2 table into cache
In l2_allocate, the fail path is executed if qcow2_cache_flush fails.However, the L2 table has not yet been fetched from the L2 table cache.The qcow2_cache_put in the fail path therefore basically gives anundefined argument as the L2 table address (in this case)....
qcow2: Correct bitmap size in zero expansion
Since the expanded_clusters bitmap is addressed using host offsets inthe underlying image file, the correct size to use for allocating thebitmap is not determined by the guest disk image but by the underlying...
qcow2: Assert against currently impossible overflow
If qcow2_alloc_cluster_link_l2 is called with a QCowL2Meta describing arequest crossing L2 boundaries, a buffer overflow will occur. This isimpossible right now since such requests are never generated (every...
qcow2: Pass discard type to qcow2_discard_clusters()
The function will be used internally instead of only being called forguest discard requests.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Max Reitz <mreitz@redhat.com>
qcow2-cluster: Expand zero clusters
Add functionality for expanding zero clusters. This is necessary fordowngrading the image version to one without zero cluster support.
For non-backed images, this function may also just discard zero clustersinstead of truly expanding them....
qcow2-refcount: Repair OFLAG_COPIED errors
Since the OFLAG_COPIED checks are now executed after the refcounts havebeen repaired (if repairing), it is safe to assume that they are correctbut the OFLAG_COPIED flag may be not. Therefore, if its value differs...
qcow2: Employ metadata overlap checks
The pre-write overlap check function is now called before most of theqcow2 writes (aborting it on collision or other error).
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: 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: Catch some L1 table index overflows
This catches the situation that is described in the bug report athttps://bugs.launchpad.net/qemu/+bug/865518 and goes like this:
$ qemu-img create -f qcow2 huge.qcow2 $((1024*1024))T Formatting 'huge.qcow2', fmt=qcow2 size=1152921504606846976 encryption=off cluster_size=65536 lazy_refcounts=off...
qcow2: Use byte granularity in qcow2_alloc_cluster_offset()
This gets rid of the nb_clusters and keep_clusters and the associatedcomplicated calculations. Just advance the number of bytes that havebeen processed and everything is fine.
This patch advances the variables even after the last operation even...
qcow2: Allow requests with multiple l2metas
Instead of expecting a single l2meta, have a list of them. This allowsto still have a single I/O request for the guest data, even thoughmultiple l2meta may be needed in order to describe both a COW overwriteand a new cluster allocation (typical sequential write case)....
qcow2: Move cluster gathering to a non-looping loop
This patch is mainly to separate the indentation change from thesemantic changes. All that really changes here is that everything movesinto a while loop, all 'goto done' become 'break' and at the end of the...
qcow2: Gather clusters in a looping loop
Instead of just checking once in exactly this order if there aredependendies, non-COW clusters and new allocation, this starts loopingaround these. This way we can, for example, gather non-COW clusters afternew allocations as long as the host cluster offsets stay contiguous....
qcow2: Improve check for overlapping allocations
The old code detected an overlapping allocation even when theallocations didn't actually overlap, but were only adjacent.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Eric Blake <eblake@redhat.com>...
qcow2: Change handle_dependency to byte granularity
This is a more precise description of what really constitutes adependency. The behaviour doesn't change at this point because the COWarea of the old request is still aligned to cluster boundaries andtherefore an overlap is detected wheneven the requests touch any part of...
qcow2: Decouple cluster allocation from cluster reuse code
This moves some code that prepares the allocation of new clusters towhere the actual allocation happens. This is the minimum required to beable to move it to a separate function in the next patch....
qcow2: Factor out handle_alloc()
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
qcow2: handle_alloc(): Get rid of nb_clusters parameter
We already communicate the same information in *bytes.
qcow2: handle_alloc(): Get rid of keep_clusters parameter
handle_alloc() is now called with the offset at which the actual newallocation starts instead of the offset at which the whole write requeststarts, part of which may already be processed.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>...
qcow2: Finalise interface of handle_alloc()
The interface works completely on a byte granularity now and duplicatedparameters are removed.
qcow2: Clean up handle_alloc()
Things can be simplified a bit now. No semantic changes.
qcow2: Factor out handle_copied()
qcow2: handle_copied(): Get rid of nb_clusters parameter
handle_copied() uses its bytes parameter now to determine how manyclusters it should try to find.
qcow2: handle_copied(): Get rid of keep_clusters parameter
Now *bytes is used to return the length of the area that can be writtento without performing an allocation or COW.
qcow2: handle_copied(): Implement non-zero host_offset
Look only for clusters that start at a given physical offset.
qcow2: Prepare handle_alloc/copied() for byte granularity
This makes handle_alloc() and handle_copied() return byte-granularityhost offsets instead of returning always the cluster start. This isrequired so that qcow2_alloc_cluster_offset() can stop aligning...
qcow2: Handle dependencies earlier
Handling overlapping allocations isn't just a detail of clusterallocation. It is rather one of three ways to get the host clusteroffset for a write request:
1. If a request overlaps an in-flight allocations, the cluster offset...
qcow2: make is_allocated return true for zero clusters
Otherwise, live migration of the top layer will miss zero clusters andlet the backing file show through. This also matches what is done in qed.
QCOW2_CLUSTER_ZERO clusters are invalid in v2 image files. Check this...
qcow2: Allow lazy refcounts to be enabled on the command line
qcow2 images now accept a boolean lazy_refcounts options. Use it likethis:
-drive file=test.qcow2,lazy_refcounts=on
If the option is specified on the command line, it overrides the default...
block: move include files to include/block/
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qcow2: Round QCowL2Meta.offset down to cluster boundary
The offset within the cluster is already present as n_start and this iswhat the code uses. QCowL2Meta.offset is only needed at a clustergranularity.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: Introduce Qcow2COWRegion
This makes it easier to address the areas for which a COW must beperformed. As a nice side effect, the COW code inqcow2_alloc_cluster_link_l2 becomes really trivial.
qcow2: Drop l2meta.cluster_offset
There's no real reason to have an l2meta for normal requests that don'tallocate anything. Before we can get rid of it, we must return the hostcluster offset in a different way.
qcow2: Allocate l2meta only for cluster allocations
Even for writes to already allocated clusters, an l2meta is allocated,though it stays effectively unused. After this patch, only allocatingrequests still have one. Each l2meta now describes an in-flight request...
qcow2: Enable dirty flag in qcow2_alloc_cluster_link_l2
This is closer to where the dirty flag is really needed, and it avoidshaving checks for special cases related to cluster allocation directlyin the writev loop.
qcow2: Factor out handle_dependencies()
qcow2: implement lazy refcounts
Lazy refcounts is a performance optimization for qcow2 that postponesrefcount metadata updates and instead marks the image dirty. In thecase of crash or power failure the image will be left in a dirty stateand repaired next time it is opened....
qcow2: Simplify calculation for COW area at the end
copy_sectors() always uses the sum (cluster_offset + n_start) or(start_sect + n_start), so if some value is added to both cluster_offsetand start_sect, and subtracted from n_start, it's cancelled out anyway....
qcow2: Fix avail_sectors in cluster allocation code
avail_sectors should really be the number of sectors from the start ofthe allocation, not from the start of the write request.
We're lucky enough that this mistake didn't cause any real bug.avail_sectors is only used in the intialiser of QCowL2Meta:...
qcow2: remove a line of unnecessary code
Commit 3948d1d4 removed the pointer argument we filled in with l2_offsetbut forgot to remove the unnecessary l2_offset assignment.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>...
qcow2: Silence false warning
Some gcc versions seem not to be able to figure out that the switchstatement covers all possible values and that c is therefore alwaysinitialised. Add a default branch for them.
Reported-by: malc <av1474@comtv.ru>Signed-off-by: Kevin Wolf <kwolf@redhat.com>...
qcow2: Check qcow2_alloc_clusters_at() return value
When using qcow2_alloc_clusters_at(), the cluster allocation codechecked the wrong variable for an error code.
qcow2: Limit COW to where it's needed
This fixes a regression introduced in commit 250196f1. The bug leads todata corruption, found during an Autotest run with a Fedora 8 guest.
Consider a write request whose first part is covered by an alreadyallocated cluster, but additional clusters need to be newly allocated....
qcow2: Remove unused parameter in do_alloc_cluster_offset
qcow2: Don't hold cache references across yield
If cache references are held while the coroutine has yielded, the cachemay get used up and abort() when it can't find a free entry.
qcow2: Zero write support
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: Simplify count_cow_clusters
count_cow_clusters() tries to reuse existing functions, and all itachieves is to make things much more complicated than they really are:Everything needs COW, unless it's a normal cluster with refcount 1.
This patch implements the obvious way of doing this, and by using...
qcow2: Ignore reserved bits in get_cluster_offset
With this change, reading from a qcow2 image ignores all reserved bitsthat are set in an L1 or L2 table entry.
Now get_cluster_offset() assigns *cluster_offset only the offset withoutany other flags. The cluster type is not longer encoded in the offset,...
qcow2: Ignore reserved bits in count_contiguous_clusters()
Until now, count_contiguous_clusters() has an argument that allowed tospecify flags that should be ignored in the comparison, i.e. that areallowed to change between contiguous clusters.
This patch changes the function so that it ignores all flags by default...
qcow2: Fail write_compressed when overwriting data
qcow2_alloc_compressed_cluster_offset() already fails if the copied flagis set, because qcow2_write_compressed() doesn't perform COW as it wouldhave to do to allow this.
However, what we really want to check here is whether the cluster is...
qcow2: Fix error handling in qcow2_alloc_cluster_offset
If do_alloc_cluster_offset() fails, the error handling code tried toremove the request from the in-flight queue, to which it wasn't addedyet, resulting in a NULL pointer dereference.
m->nb_clusters really only becomes != 0 when the request is in the list....
qcow2: Remove unused parameter in get_cluster_table()
Since everything goes through the cache, callers don't use the L2 tableoffset any more.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
qcow2: Factor out count_cow_clusters
qcow2: Reduce number of I/O requests
If the first part of a write request is allocated, but the second isn'tand it can be allocated so that the resulting area is contiguous, handleit at once. This is a common case for sequential writes.
After this patch, alloc_cluster_offset() only checks if the clusters are...
qcow2: Add some tracing
qcow2: avoid reentrant bdrv_read() in copy_sectors()
A BlockDriverState should not issue requests on itself through thepublic block layer interface. Nested, or reentrant, requests areproblematic because they do I/O throttling and request tracking twice....
qcow2: Unlock during COW
Unlocking during COW allows for more parallelism. One change it requires isthat buffers are dynamically allocated instead of just using a per-imagebuffer.
While touching the code, drop the synchronous qcow2_read() function and replace...
qcow2: Fix bdrv_write_compressed error handling
If during allocation of compressed clusters the cluster was already allocateduncompressed, fail and properly release the l2_table (the latter avoids afailed assertion).
While at it, make it return some real error numbers instead of -1....
qcow2: initialize metadata before inserting in cluster_allocs
QCow2Meta structure was inserted into list before many fields areinitialized. Currently is not a problem cause all occur in a lockbut if qcow2_alloc_clusters would in a future unlock this lock...
qcow2: fix range check
QCowL2Meta::offset is not cluster aligned but only sector alignedhowever nb_clusters count cluster from cluster start.This fix range check. Note that old code have no corruption issuesrelated to this check cause it only cause intersection to occur...
qcow2: removed unused depends_on field
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
qcow2: fix typo in documentation for qcow2_get_cluster_offset()
Documentation states the num is measured in clusters, but itsactually measured in sectors
Signed-off-by: Devin Nakamura <devin122@gmail.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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 coroutines
qcow2: Fix in-flight list after qcow2_cache_put failure
If qcow2_cache_put returns an error during cluster allocation and theallocation fails, it must be removed from the list of in-flight allocations.Otherwise we'd get a loop in the list when the ACB is used for the next...
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.
qcow2: Fix order in L2 table COW
When copying L2 tables (this happens only with internal snapshots), the orderwasn't completely safe, so that after a crash you could end up with a L2 tablethat has too low refcount, possibly leading to corruption in the long run....
qcow2: Fix error handling for reading compressed clusters
When reading a compressed cluster failed, qcow2 falsely returned success.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Markus Armbruster <armbru@redhat.com>
qcow2: Add bdrv_discard support
This adds a bdrv_discard function to qcow2 that frees the discarded clusters.It does not yet pass the discard on to the underlying file system driver, butthe space can be reused by future writes to the image.
qcow2: Use QcowCache
Use the new functions of qcow2-cache.c for everything that works on refcountblock and L2 tables.
qcow2: Batch flushes for COW
qcow2 calls bdrv_flush() after performing COW in order to ensure that theL2 table change is never written before the copy is safe on disk. Now that theL2 table is cached, we can wait with flushing until we write out the next L2...
qcow2: fix unaligned access
cpu_to_be64w() is called with an obviously non-aligned pointer. Usecpu_to_be64wu() instead. It fixes unaligned accesses errors on IA64hosts.
Cc: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>...
block/qcow2.c: rename qcow_ functions to qcow2_
It doesn't really make sense for functions in qcow2.c to be namedqcow_ so convert the names to match correctly.
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: Invalidate cache after failed read
The cache content may be destroyed after a failed read, better not use it anymore.
qcow2: Support exact L1 table growth
The L1 table grow operation includes a size calculation that bumps upthe new L1 table size in order to anticipate the size needs of vmstatedata. This helps reduce the number of times that the L1 table has to begrown when vmstate data is appended....
qcow2: Move sync out of qcow2_alloc_clusters
qcow2: Get rid of additional sync on COW
We always have a sync for the refcount update when a new cluster isallocated. If we move this past the COW, we can save an additional sync.
qcow2: Avoid bounce buffers for AIO read requests
qcow2 used to use bounce buffers for any AIO requests. This does not only implyunnecessary copying, but also unbounded allocations which should be avoided.
This patch removes bounce buffers from the normal AIO read path, and constrains...
qcow2: Remove unnecessary flush after L2 write
When a new cluster was allocated, we only need a flush after the write to theL2 table if it was a COW and we need to decrease the refcounts of the oldclusters.
qcow2: Use bdrv_(p)write_sync for metadata writes
Use bdrv_(p)write_sync to ensure metadata integrity in case of a crash.
qcow2: Restore L1 entry on l2_allocate failure
If writing the L1 table to disk failed, we need to restore its old content inmemory to avoid inconsistencies.
Reported-by: Juan Quintela <quintela@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: Change l2_load to return 0/-errno
Provide the error code to the caller instead of just indicating success/error.