summaryrefslogtreecommitdiff
path: root/block-qcow2.c
AgeCommit message (Collapse)AuthorFilesLines
2009-02-05block: remove error handling from qemu_malloc() callers (Avi Kivity)aliguori1-57/+1
Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6527 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-22qcow2 format: keep 'num_free_bytes', and show it upon 'info blockstats' (Uri ↵aliguori1-8/+28
Lublin) 'num_free_bytes' is the number of non-allocated bytes below highest-allocation. It's useful, together with the highest-allocation, to figure out how fragmented the image is, and how likely it will run out-of-space soon. For example when the highest allocation is high (almost end-of-disk), but many bytes (clusters) are free, and can be re-allocated when neeeded, than we know it's probably not going to reach end-of-disk-space soon. Added bookkeeping to block-qcow2.c Export it using BlockDeviceInfo Show it upon 'info blockstats' if BlockDeviceInfo exists Signed-off-by: Uri Lublin <uril@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6407 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-22block-qcow2: export highest_allocated through BlockDriverInfo and get_info() ↵aliguori1-0/+1
(Uri Lublin) Signed-off-by: Uri Lublin <uril@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6405 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-22block-qcow2: keep highest allocated byte (Uri Lublin)aliguori1-0/+34
We want to know the highest written offset for qcow2 images. This gives a pretty good (and easy to calculate) estimation to how much more allocation can be done for the block device. It can be usefull for allocating more diskspace for that image (if possible, e.g. lvm) before we run out-of-disk-space Signed-off-by: Uri Lublin <uril@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6404 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-16Avoid calling qemu_mallocz with zero sizemalc1-2/+10
Currently qemu_mallocz calls malloc and handling of zero by malloc is implementation defined behaviour: http://www.opengroup.org/onlinepubs/7990989775/xsh/malloc.html malloc(0) on AIX returns NULL[1] and qcow2 images without snapshots are thus unusable [1] Unless special Linux compatibility define is used when compiling git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6359 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-08qcow2: free old snapshots array upon creation of a new one (Uri Lublin)aliguori1-0/+1
Don't leak memory Rebased for qemu tree. Signed-off-by: Uri Lublin <uril@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6245 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-07qcow2: Fix cluster allocation (Kevin Wolf)aliguori1-6/+6
When allocating multiple clusters at once, the qcow2 implementation tries to find as many physically contiguous clusters as possible to allow larger writes. This search includes allocated clusters which are in the right place and still free clusters. If the range to allocate spans clusters in patterns like "10 allocated, then 10 free, then again 10 allocated" it is only checked that the chunks of allocated clusters are contiguous for themselves. However, what is actually needed is to have _all_ allocated clusters contiguous, starting at the first cluster of the allocation and spanning multiple such chunks. This patch changes the check so that each offset is not compared to the offset of the first cluster in its own chunk but to the first cluster in the whole allocation. I haven't seen it happen, but without this fix data corruption on qcow2 images is possible. Signed-off-by: Kevin Wolf <kwolf@suse.de> Acked-by: Gleb Natapov <gleb@redhat.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6213 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-07Fix compressed qcow2 (Gleb Natapov)aliguori1-6/+9
Correctly calculate number of contiguous clusters. Acked-by: Kevin Wolf <kwolf@suse.de> Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6212 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-04Use writeback caching by default with qcow2aliguori1-0/+8
qcow2 writes a cluster reference count on every cluster update. This causes performance to crater when using anything but cache=writeback. This is most noticeable when using savevm. Right now, qcow2 isn't a reliable format regardless of the type of cache your using because metadata is not updated in the correct order. Considering this, I think it's somewhat reasonable to use writeback caching by default with qcow2 files. It at least avoids the massive performance regression for users until we sort out the issues in qcow2. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5879 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-02Change order of metadata update to prevent loosing guest data because of ↵aliguori1-63/+92
unexpected exit (Gleb Natapov) Currently the order is this (during cow since it's the interesting case): 1. Decrement refcount of old clusters 2. Increment refcount for newly allocated clusters 3. Copy content of old sectors that will not be rewritten 4. Update L2 table with pointers to new clusters 5. Write guest data into new clusters (asynchronously) There are several problems with this order. The first one is that if qemu crashes (or killed or host reboots) after new clusters are linked into L2 table but before user data is written there, then on the next reboot guest will find neither old data nor new one in those sectors and this is not what gust expects even when journaling file system is in use. The other problem is that if qemu is killed between steps 1 and 4 then refcount of old cluster will be incorrect and may cause snapshot corruption. The patch change the order to be like this: 1. Increment refcount for newly allocated clusters 2. Write guest data into new clusters (asynchronously) 3. Copy content of old sectors that were not rewritten 4. Update L2 table with pointers to new clusters 5. Decrement refcount of old clusters Unexpected crash may cause cluster leakage, but guest data should be safe. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5861 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-02Cleanup {alloc|get}_cluster_offset() (Gleb Natapov)aliguori1-89/+73
Move duplicated code into helper functions. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5860 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-02Write table offset and size in one syscall (Gleb Natapov)aliguori1-17/+9
Otherwise if VM is killed between two writes data may be lost. But if offset and size fields are at the same disk block one write should update them both simultaneously. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5859 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-02Introduce new helper function qcow_shedule_bh() (Gleb Natapov)aliguori1-27/+20
Use it to remove code duplications from qcow_aio_read_cb(). Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5858 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-02Remove tabs from qcow_aio_read_cb(). (Gleb Natapov)aliguori1-32/+32
Fix indentation. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5857 c046a42c-6fe2-441c-8c8c-71466251a162
2008-10-31fix bdrv_aio_read API breakage in qcow2 (Andrea Arcangeli)aliguori1-4/+40
I noticed the qemu_aio_flush was doing nothing at all. And a flood of cmd_writeb commands leading to a noop-invocation of qemu_aio_flush were executed. In short all 'memset;goto redo' places must be fixed to use the bh and not to call the callback in the context of bdrv_aio_read or the bdrv_aio_read model falls apart. Reading from qcow2 holes is possible with phyisical readahead (kind of breada in linux buffer cache). This is needed at least for scsi, ide is lucky (or it has been band-aided against this API breakage by fixing the symptom and not the real bug). Same bug exists in qcow of course, can be fixed later as it's less urgent. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5574 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-24fix bug in block-qcow2.c:alloc_cluster_offset() (Shahar Frank)aliguori1-1/+1
During the debugging of the new revision of the zero dedup patch I stepped on the following bug in block-qcow2.c:alloc_cluster_offset(). I am not sure what the exact damage this bug can do, but it may be very nasty because you way not notice it effects until you will do some snapshot operations or similar actions that rely on the reference counting. The bug is easy to spot using the new "check" verb I added to the qemu-img in one of the previous patches. I will resend the qemu-img patch again with the new version of the zero dedup. Signed-off-by: Shahar Frank <shaharf@qumranet.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5313 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-16Move offsetof to osdep.h, remove local defintions.balrog1-4/+0
With this container_of can actually be used without causing build errors. Reformat container_of. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5234 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-14qcow2: Try to aggregate free clusters and freed clusters (Laurent Vivier)aliguori1-18/+36
In alloc_cluster_offset(), try to aggregate free clusters and freed clusters. Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5008 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-14qcow2: Make sure to return an error when L2 table loading failsaliguori1-1/+1
This was suggested by Kevin Wolf since this is, in fact, an error condition. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5007 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-14qcow2: Aggregate same type clusters (Laurent Vivier)aliguori1-53/+181
Modify get_cluster_offset(), alloc_cluster_offset() to specify how many clusters we want. Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5006 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-14Extract compressing part from alloc_cluster_offset() (Laurent Vivier)aliguori1-45/+124
Divide alloc_cluster_offset() into alloc_cluster_offset() and alloc_compressed_cluster_offset(). Common parts are moved to free_any_clusters() and get_cluster_table(); Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5005 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-14Divide get_cluster_offset() (Laurent Vivier)aliguori1-76/+132
Divide get_cluster_offset() into get_cluster_offset() and alloc_cluster_offset(). Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5004 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-14qcow2: Extract code from get_cluster_offset() (Laurent Vivier)aliguori1-62/+153
Extract code from get_cluster_offset() into new functions: - seek_l2_table() Search an l2 offset in the l2_cache table. - l2_load() Read the l2 entry from disk - l2_allocate() Allocate a new l2 entry. Some comment fixups from Kevin Wolf Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net> Signed-off-by: Kevin Wolf <kwolf@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5003 c046a42c-6fe2-441c-8c8c-71466251a162
2008-03-11Revert fix for CVE-2008-0928. Will be fixed in a different way later.aurel321-1/+1
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4041 c046a42c-6fe2-441c-8c8c-71466251a162
2008-03-11Fix CVE-2008-0928 - insufficient block device address range checkingaurel321-1/+1
Qemu 0.9.1 and earlier does not perform range checks for block device read or write requests, which allows guest host users with root privileges to access arbitrary memory and escape the virtual machine. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4037 c046a42c-6fe2-441c-8c8c-71466251a162
2007-11-11Split block API from vl.h.pbrook1-1/+1
Remove QEMU_TOOL. Replace with QEMU_IMG and NEED_CPU_H. Avoid linking qemu-img against whole system emulatior. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3578 c046a42c-6fe2-441c-8c8c-71466251a162
2007-09-17find -type f | xargs sed -i 's/[\t ]*$//g' # Yes, again. Note the star in ↵ths1-34/+34
the regex. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3177 c046a42c-6fe2-441c-8c8c-71466251a162
2007-09-16vmdk compatibility level 6 images, by Soren Hansen.ths1-1/+1
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3175 c046a42c-6fe2-441c-8c8c-71466251a162
2007-09-16find -type f | xargs sed -i 's/[\t ]$//g' # on most filesths1-129/+129
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3173 c046a42c-6fe2-441c-8c8c-71466251a162
2007-04-02Qcow2: Release refcount table clusters after growing the refcount table,ths1-0/+5
by Juergen Keil. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2586 c046a42c-6fe2-441c-8c8c-71466251a162
2007-04-01Qcow2 corruption fix, by Juergen Keil.ths1-0/+1
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2578 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-07Dynamically allocate AIO Completion Blocks.pbrook1-130/+112
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2098 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-06handle read outside the backing filebellard1-9/+33
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2093 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-05fixed disk image creationbellard1-5/+9
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2089 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-05new qcow2 disk image formatbellard1-0/+2236
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2083 c046a42c-6fe2-441c-8c8c-71466251a162