History | View | Annotate | Download (16.4 kB)
qcow2: fix wrong value of L1E_OFFSET_MASK, L2E_OFFSET_MASK and REFT_OFFSET_MASK
Accoring to qcow spec, the offset fields in l1e, l2e and ref table entrystart at bit 9. The offset is cluster offset, and the smallest possiblecluster size is 512 bytes.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>...
snapshot: distinguish id and name in load_tmp
Since later this function will be used so improve it. The only caller of itnow is qemu-img, and it is not impacted by introduce functionbdrv_snapshot_load_tmp_by_id_or_name() that call bdrv_snapshot_load_tmp()...
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: Make overlap check mask variable
Replace the QCOW2_OL_DEFAULT macro by a variable overlap_check inBDRVQcowState.
Signed-off-by: Max Reitz <mreitz@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: Add overlap-check options
Add runtime options to tune the overlap checks to be performed beforewrite accesses.
qcow2: Add more overlap check bitmask macros
Introduces the macros QCOW2_OL_CONSTANT and QCOW2_OL_ALL in addition tothe already existing QCOW2_OL_CACHED, signifying all metadata overlapchecks that can be performed in constant time (regardless of image size...
block: qcow2 - used QEMU_PACKED for on-disk structures
QCowHeader and QCowExtension are structs that reside in the on-diskimage format, and are read and written directly via bdrv_pread()/write(),and as such should be packed to avoid any unintentional struct padding....
snapshot: distinguish id and name in snapshot delete
Snapshot creation actually already distinguish id and name since it takea structured parameter *sn, but delete can't. Later an accurate deleteis needed in qmp_transaction abort and blockdev-snapshot-delete-sync,...
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: Discard VM state in active L1 after creating snapshot
During savevm, the VM state is written to the active L1 of the image andthen a snapshot is taken. After that, the VM state isn't needed any morein the active L1 and should be discarded. This is implemented by this...
qcow2-cache: Empty cache
Add a function for emptying a cache, i.e., flushing it and marking allelements invalid.
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: Save refcount order in BDRVQcowState
Save the image refcount order in BDRVQcowState. This will be relevantfor future code supporting different refcount orders than four and alsofor code that needs to verify a certain refcount order for an opened...
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: Add corrupt bit
This adds an incompatible bit indicating corruption to qcow2. Any imagewith this bit set may not be written to unless for repairing (andsubsequently clearing the bit if the repair has been successful).
Signed-off-by: Max Reitz <mreitz@redhat.com>...
qcow2: Metadata overlap checks
Two new functions are added; the first one checks a given range in theimage file for overlaps with metadata (main header, L1 tables, L2tables, refcount table and blocks).
The second one should be used immediately before writing to the image...
block/qcow2.h: Avoid "1LL << 63" (shifts into sign bit)
The expression "1LL << 63" tries to shift the 1 into the sign bit of a'long long', which provokes a clang sanitizer warning:
runtime error: left shift of 1 by 63 places cannot be represented in type 'long long'...
qcow2: Use dashes instead of underscores in options
This is what QMP wants to use. The options haven't been enabled in anyrelease yet, so we're still free to change them.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Eric Blake <eblake@redhat.com>
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: 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...
aes: move aes.h from include/block to include/qemu
Move aes.h from include/block to include/qemu to show it can be reusedby other subsystems.
Cc: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>Reviewed-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>...
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: 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: 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.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
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: Fix segfault in qcow2_invalidate_cache
Need to pass an options QDict to qcow2_open() now. This fixes a segfaulton the migration target with qcow2.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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.
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: introduce dirty bit
This patch adds an incompatible feature bit to mark images that have notbeen closed cleanly. When a dirty image file is opened a consistencycheck and repair is performed.
Update qemu-iotests 031 and 036 since the extension header size changes...
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: 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: Support for fixing refcount inconsistencies
qcow2: Zero write support
qcow2: Ignore reserved bits in refcount table entries
qcow2: Version 3 images
This adds the basic infrastructure to qcow2 to handle version 3 images.It includes code to create v3 images, allow header updates for v3 imagesand checks feature bits.
It still misses support for zero clusters, so this is not a fully...
qcow2: Support reading zero clusters
This adds support for reading zero clusters in version 3 images.
qcow2: Support for feature table header extension
Instead of printing an ugly bitmask, qemu can now print a more helpfulstring even for yet unknown features.
qcow2: Save disk size in snapshot header
This allows that different snapshots of an image can have differentsizes, which is a requirement for enabling image resizing even withimages that have internal snapshots.
We don't do the actual support for it now, but make sure that the...
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: 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: 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: Update whole header at once
In order to switch the backing file, qcow2 issues multiple writerequests that only changed a part of the image header. Any failure afterthe first one would leave the header in an corrupted state. With thispatch, the whole header is written at once, so we can't fail in the...
qcow2: Keep unknown header extension when rewriting header
If we want header extensions to work as compatible extensions, we can'tdestroy yet unknown header extensions when rewriting the header (e.g.for changing the backing file). Save all unknown header extensions in a...
qcow2: Allow >4 GB VM state
This is a compatible extension to the snapshot header format that allowssaving a 64 bit VM state size.
qcow2: implement bdrv_invalidate_cache (v2)
We don't reopen the actual file, but instead invoke the close and open routines.We specifically ignore the backing file since it's contents are read-only andtherefore immutable.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qcow2: removed unused depends_on field
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qcow2: remove unused qcow2_create_refcount_update function
qcow2: Use coroutines
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...
qemu-img create: Fix displayed default cluster size
When not specifying a cluster size on the command line, qemu-img printeda cluster size of 0:
Formatting '/tmp/test.qcow2', fmt=qcow2 size=67108864 encryption=off cluster_size=0
This patch adds the default cluster size to the QEMUOptionParameter list, so...
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: Add QcowCache
This adds some new cache functions to qcow2 which can be used for cachingrefcount blocks and L2 tables. When used with cache=writethrough they worklike the old caching code which is spread all over qcow2, so for this case wehave merely a cleanup....
block: Remove unused s->hd in various drivers
All drivers use bs->file instead of s->hd for quite a while now, so it's timeto remove s->hd.
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....
Copy snapshots out of QCOW2 disk
In order to backup snapshots, created from QCOW2 iamge, we want to copy snapshots out of QCOW2 disk to a seperate storage.The following patch adds a new option in "qemu-img": qemu-img convert -f qcow2 -O qcow2 -s snapshot_name src_img bck_img....
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/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: Allow qcow2_get_cluster_offset to return errors
qcow2_get_cluster_offset() looks up a given virtual disk offset and returns theoffset of the corresponding cluster in the image file. Errors (e.g. L2 tablecan't be read) are currenctly indicated by a return value of 0, which is...
qcow2: Implement bdrv_truncate() for growing images
This patch adds the ability to grow qcow2 images in-place usingbdrv_truncate(). This enables qemu-img resize command support forqcow2.
Snapshots are not supported and bdrv_truncate() will return -ENOTSUP....
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: Fix signedness bugs
Checking for return codes < 0 isn't really going to work with unsignedtypes. Use signed types instead.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qcow2: Return 0/-errno in qcow2_alloc_cluster_offset
Returning 0/-errno allows it to distingush different errors classes. Thecluster offset of newly allocated clusters is now returned in the QCowL2Metastruct.
Revert "qcow2: Bring synchronous read/write back to life"
It was merely a workaround and the real fix is done now.This reverts commit ef845c3bf421290153154635dc18eaa677cecb43.
qcow2: Bring synchronous read/write back to life
When the synchronous read and write functions were dropped, they were replacedby generic emulation functions. Unfortunately, these emulation functions don'tprovide the same semantics as the original functions did....
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 sys-queue.h conflict for good
Problem: Our file sys-queue.h is a copy of the BSD file, but there aresome additions and it's not entirely compatible. Because of that, there havebeen conflicts with system headers on BSD systems. Some hacks have beenintroduced in the commits 15cc9235840a22c289edbe064a9b3c19c5f49896,...
qcow2: Order concurrent AIO requests on the same unallocated cluster
When two AIO requests write to the same cluster, and this cluster isunallocated, currently both requests allocate a new cluster and the second onemerges the first one when it is completed. This means an cluster allocation, a...
Fix QCOW2 debugging code to compile again
Updated to use C99 comments.
Signed-off-by: Filip Navara <filip.navara@gmail.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
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: Split out snapshot functions
qcow2-snapshot.c contains the code related to snapshotting.
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...