Reorganize struct Qcow2Cache for better struct packing
Move size after the two pointers in struct Qcow2Cache to get betterpacking of struct elements on 64 bit architectures.
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
sheepdog: support creating images on remote hosts
This patch parses the input filename in sd_create(), and enables usspecifying a target server to create sheepdog images.
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>Signed-off-by: Kevin Wolf <kwolf@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.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>...
qed: Images with backing file do not require QED_F_NEED_CHECK
The consistency check on open is necessary in order to fix inconsistenttable offsets left as a result of a crash mid-operation. Images with abacking file actually flush before updating table offsets and are...
raw-win32: Fix bdrv_flush return value
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qed: Refuse to create images on block devices
QED relies on the underlying filesystem to extend the file and maintainits size. Check that images are not created on a block device.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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....
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>...
vpc: fix a file descriptor leak
Fix a file descriptor leak, reported by cppcheck:[/src/qemu/block/vpc.c:524]: (error) Resource leak: fd
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
vvfat: fix a file descriptor leak
Fix a file descriptor leak, reported by cppcheck:[/src/qemu/block/vvfat.c:759]: (error) Resource leak: dir
Add proper -errno error return values to qcow2_open()
In addition this adds missing braces to the function to be consistentwith the coding style.
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.
qed: Add QEMU Enhanced Disk image format
This patch introduces the qed on-disk layout and implements imagecreation. Later patches add read/write and other functionality.
qed: Table, L2 cache, and cluster functions
This patch adds code to look up data cluster offsets in the image viathe L1/L2 tables. The L2 tables are writethrough cached in memory forperformance (each read/write requires a lookup so it is essential tocache the tables)....
qed: Read/write support
This patch implements the read/write state machine. Operations arefully asynchronous and multiple operations may be active at any time.
Allocating writes lock tables to ensure metadata updates do notinterfere with each other. If two allocating writes need to update the...
qed: Consistency check support
This patch adds support for the qemu-img check command. It alsointroduces a dirty bit in the qed header to mark modified images asneeding a check. This bit is cleared when the image file is closedcleanly.
If an image file is opened and it has the dirty bit set, a consistency...
block: add discard support
Add a new bdrv_discard method to free blocks in a mapping image, and a newdrive property to set the granularity for these discard. If no discardgranularity support is set discard support is disabled.
Signed-off-by: Christoph Hellwig <hch@lst.de>...
raw-posix: add discard support
Add support to discard blocks in a raw image residing on an XFS filesystemby calling the XFS_IOC_UNRESVSP64 ioctl to punch holes. Support for otherhole punching mechanisms can be added when they become available.
ceph/rbd block driver for qemu-kvm
RBD is an block driver for the distributed file system Ceph(http://ceph.newdream.net/). This driver uses librados (which is partof the Ceph server) for direct access to the Ceph object store and isrunning entirely in userspace (Yehuda also wrote a driver for the...
raw-posix: raw_pwrite comment fixup
Signed-off-by: Christoph Hellwig <hch@lst.de>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Fix win32 build
Fix a return value change missed by205ef7961f781496366e0a93a4ec621ad3724bd7.
qcow2: Invalidate cache after failed read
The cache content may be destroyed after a failed read, better not use it anymore.
block: avoid a warning on 64 bit hosts with long as int64_t
When building on a 64 bit host which uses 'long' for int64_t,GCC emits a warning: CC block/blkverify.o/src/qemu/block/blkverify.c: In function `blkverify_verify_readv':/src/qemu/block/blkverify.c:304: warning: long long int format, long...
block: Allow bdrv_flush to return errors
This changes bdrv_flush to return 0 on success and -errno in case of failure.It's a requirement for implementing proper error handle in users of bdrv_flush.
vpc: Implement bdrv_flush
Merge remote branch 'kwolf/for-anthony' into staging
qemu-timer: move commonly used timer code to qemu-timer-common
Move timer init functions to a new file, qemu-timer-common.c. Make othercritical timer functions inlined to preserve performance inqemu-timer.c, also move muldiv64() (used by the inline functions)...
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: Simplify image creation
Instead of doing lots of magic for setting up initial refcount blocks and stuffcreate a minimal (inconsistent) image, open it and initialize the rest withregular qcow2 functions.
This is a complete rewrite of the image creation function. The old...
qcow2: Remove old image creation function
They have been #ifdef'd out by the previous patch.
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....
block: Use GCC_FMT_ATTR and fix a format error
Adding the gcc format attribute detects a format bugwhich is fixed here.
v2:Don't use type cast. BDRV_SECTOR_SIZE is unsigned long long,so %lld should be the correct format specifier.
Cc: Blue Swirl <blauwirbel@gmail.com>...
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]...
block/vvfat: Fix compiler warning in debug code
Fix this compiler warning:./block/vvfat.c:2285: error: comparison of unsigned expression >= 0 is always true
Cc: Blue Swirl <blauwirbel@gmail.com>Cc: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Stefan Weil <weil@mail.berlios.de>...
block-verify: fix 32-bit build
Reported-by: Peter Lemenkov <lemenkov@gmail.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
blkverify: Add block driver for verifying I/O
The blkverify block driver makes investigating image format datacorruption much easier. A raw image initialized with the same contentsas the test image (e.g. qcow2 file) must be provided. The raw imagemirrors read/write operations and is used to verify that data read from...
qcow2: Avoid bounce buffers for AIO write 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 write path. Encrypted...
vvfat: Fix segfault on write to read-only disk
vvfat tries to set the readonly flag in its open function, but nowadaysthis is overwritted with the readonly=... command line option. Check inbdrv_write if the vvfat was opened read-only and return an error in this...
vvfat: Fix double free for opening the image rw
Allocation and deallocation of bs->opaque is not in the control of ablock driver. Therefore it should not set bs->opaque to a data structureused by another bs, or closing the image will lead to a double free....
vvfat: Use cache=unsafe
The qcow file used for write support in vvfat is a temporary file,so we can use cache=unsafe there. Without this, write support is justtoo slow to be of any use.
Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
raw-posix: handle > 512 byte alignment correctly
Replace the hardcoded handling of 512 byte alignment with bs->buffer_alignmentto handle larger sector size devices correctly.
Note that we can not rely on it to be initialize in bdrv_open, so dealwith the worst case there....
nbd: correctly manage default port
block/nbd.c: use default port number when none is specifiedqemu-nbd.c: use IANA-assigned port number: 10809
Signed-off-by: Laurent Vivier <laurent@vivier.eu>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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: 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
This patch removes bounce buffers from the normal AIO read path, and constrains...
blkdebug: fix enum comparison
The signedness of enum types depend on the compiler implementation.Therefore the check for negative values may or may not be meaningful.
Fix by explicitly casting to a signed integer.
Since the values are also checked earlier against event_names...
Revert "Make default invocation of block drivers safer (v3)"
This reverts commit 79368c81bf8cf93864d7afc88b81b05d8f0a2c90.
Conflicts:
block.c
I haven't been able to come up with a solution yet for the corruption caused byunaligned requests from the IDE disk so revert until a solution can be written....
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.
raw-posix: improve detection of scsi-generic devices
Allow symbolic links which point to /dev/sgX devices.
Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
raw-posix: Don't use file name for host_cdrom detection on Linux
On Linux, we have code to detect CD-ROMs using an ioctl. We shouldn't loseanything but false positives by removing the check for a /dev/cd* path.
sheepdog: remove unnecessary includes
"qemu_socket.h" includes all necessary files andincluding <netinet/tcp.h> without <netinet/in.h>could cause errors on some systems.
Signed-off-by: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
vvfat: fat_chksum(): fix access above array bounds
Signed-off-by: Loïc Minier <loic.minier@linaro.org>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
nbd: Introduce NBD named exports.
This patch allows to connect Qemu using NBD protocol to an nbd-serverusing named exports.
For instance, if on the host "isoserver", in /etc/nbd-server/config, you have:
[generic][debian-500-ppc-netinst] exportname = /ISO/debian-500-powerpc-netinst.iso...
block: Fix bdrv_has_zero_init
Assuming that any image on a block device is not properly zero-initialized isactually wrong: Only raw images have this problem. Any other image formatshouldn't care about it, they initialize everything properly themselves....
block: Replace u_int8_t, u_int16_t, u_int32_t, u_int64_t by standard int types
There is no need to have a second set of integral types.Replace them by the standard types from stdint.h.
Signed-off-by: Stefan Weil <weil@mail.berlios.de>Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Make default invocation of block drivers safer (v3)
CVE-2008-2004 described a vulnerability in QEMU whereas a malicious user couldtrick the block probing code into accessing arbitrary files in a guest. Tomitigate this, we added an explicit format parameter to -drive which disabling...
sheepdog: fix compile error on systems without TCP_CORK
WIN32 is not only the system which doesn't have TCP_CORK (e.g. OS X).
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
block: add sheepdog driver for distributed storage support
Sheepdog is a distributed storage system for QEMU. It provides highlyavailable block level storage volumes to VMs like Amazon EBS. Thispatch adds a qemu block driver for Sheepdog.
Sheepdog features are:...
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.
raw-posix: Fix test for host CD-ROM
raw_pread_aligned() retries up to two times if the block device backsa virtual CD-ROM (a drive with media=cdrom and if=ide, scsi, xen ornone). This makes no sense. Whether retrying reads can correct readerrors can only depend on what we're reading, not on how the result...
blkdebug: Fix set_state_opts definition
The list head was initialized to point to the wrong list, so all actions endedup being handled as inject-error even if they were set-state in fact.
blkdebug: Free QemuOpts after having read the config
Forgetting to free them means that the next instance inherits all rules andgets its own rules only additionally.
blkdebug: Initialize state as 1
state = 0 in rules means that the rule is valid for any state. Therefore it'simpossible to have a rule that works only in the initial state. This changesthe initial state from 0 to 1 to make this possible.
qcow2: Fix error handling during metadata preallocation
People were wondering why qemu-img check failed after they tried to preallocatea large qcow2 file and ran out of disk space.
cow: Use bdrv_(p)write_sync for metadata writes
Use bdrv_(p)write_sync to ensure metadata integrity in case of a crash.While at it, correct the wrong usage of errno.
qcow: Use bdrv_(p)write_sync for metadata writes
Use bdrv_(p)write_sync to ensure metadata integrity in case of a crash.
qcow2: Use bdrv_(p)write_sync for metadata writes
vmdk: Use bdrv_(p)write_sync for metadata writes
vpc: Use bdrv_(p)write_sync for metadata writes
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
cow: use pread/pwrite
Use pread/pwrite instead of lseek + read/write in preparation of using theqemu block API.
cow: stop using mmap
We don't have an equivalent to mmap in the qemu block API, so read andwrite the bitmap directly. At least in the dumb implementation addedin this patch this is a lot less efficient, but it means cow can alsowork on windows, and over nbd or curl. And it fixes qemu-iotests testcase...
cow: use qemu block API
Use bdrv_pwrite to access the backing device instead of pread, andconvert the driver to implementing the bdrv_open method which givesit an already opened BlockDriverState for the underlying device.
vpc: Read/write multiple sectors at once
This changes the vpc block driver (for VHD) to read/write multiple sectors atonce instead of doing a request for each single sector.
Before this, running qemu-iotests for VPC took ages, now it's actually quitereasonable to run it always (down from ~1 hour to 40 seconds for me)....
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: 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>
Conflicts: hw/pc.c
Move stdbool.h
Move inclusion of stdbool.h to common header files, instead of includingin an ad-hoc manner.
Signed-off-by: Paul Brook <paul@codesourcery.com>
Cleanup: raw-posix.c: Be more consistent using BDRV_SECTOR_SIZE instead of 512
Clean up raw-posix.c to be more consistent using BDRV_SECTOR_SIZEinstead of hard coded 512 values.
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: Change l2_load to return 0/-errno
Provide the error code to the caller instead of just indicating success/error.
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: Clear L2 table cache after write error
If the L2 table was already updated in cache, but writing it to disk hasfailed, we must not continue using the changed version in the cache to stayconsistent with what's on the disk.
qcow2: Fix error handling in l2_allocate
l2_allocate has some intermediate states in which the image is inconsistent.Change the order to write to the L1 table only after the new L2 table hassuccessfully been initialized.
Also reset the L2 cache in failure case, it's very likely wrong....
Fix %lld or %llx printf format use
vvfat: Fix compilation with DEBUG defined
gcc does not like passing a NULL where an int value is expected:
block/vvfat.c: In function ‘checkpoint’:block/vvfat.c:2868: error: passing argument 2 of ‘remove_mapping’ makes integer from pointer without a cast...
vvfat: More build fixes with DEBUG
Casting a pointer to an int doesn't work on 64 bit platforms. Use the %p printfconversion specifier instead.
dmg: use qemu block API
Dmg actually does an lseek to a negative offset in the open routine,...
block/vdi: Fix image opening and creation for odd disk sizes
The fix is based on a patch from Kevin Wolf. Here his comment:
"The number of blocks needs to be rounded up to cover all of the virtual harddisk. Without this fix, we can't even open our own images if their size is not...