Fix win32 build
Fix a return value change missed by205ef7961f781496366e0a93a4ec621ad3724bd7.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
qcow2: Invalidate cache after failed read
The cache content may be destroyed after a failed read, better not use it anymore.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
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
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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.
Signed-off-by: Christoph Hellwig <hch@lst.de>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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.
Signed-off-by: Christoph Hellwig <hch@lst.de>...
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.
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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.
bochs: use qemu block API
block: Avoid unchecked casts for AIOCBs
Use container_of for one direction and &acb->common for the other one.
block/vdi: Allow disk images of size 0
Even it is not very useful, users may create images of size 0.
Without the special option CONFIG_ZERO_MALLOC, qemu_malloczaborts execution when it is told to allocate 0 bytes,so avoid this kind of call.
Cc: Kevin Wolf <kwolf@redhat.com>...
parallels: use pread
Use pread instead of lseek + read in preparation of using the qemublock API.
parallels: use qemu block API
block/vpc: Fix conversion from size to disk geometry
The VHD algorithm calculates a disk geometrywhich is usually smaller than the requested size.
QEMU tried to round up but failed for certain sizes:
qemu-img create -f vpc disk.vpc 9437184would create an image with 9435136 bytes...
dmg: fix reading of uncompressed chunks
When dmg_read_chunk encounters an uncompressed chunk it currentlycalls read without any previous adjustment of the file postion.
This seems very wrong, and the "reference" implementation indmg2img does a search to the same offset as done in the various...
dmg: use pread
Use pread instead of lseek + read in preparation of using the qemublock API. Note that dmg actually uses the implicit file offseta lot in dmg_open, and we had to replace it with an offset variable.
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...
cloop: use pread
cloop: use qemu block API
bochs: use pread
qcow2: Remove static forward declaration
OpenBSDs gcc is said to generate warnings for this declaration, so don'treference bdrv_qcow2 directly, but look it up using bdrv_find_format.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Revert "Fix OpenBSD build"
This reverts commit 20d97356c9df6d68fbd37d6334fdb7063f24eab6.The BlockDriver definition should stay at the end of source files.
block/qcow2.c
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: 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....
vmdk: Fix COW
When trying to do COW, VMDK wrote the data back to the backing file. Thisproblem was revealed by the patch that made backing files read-only. This patchdoes not only fix the problem, but also simplifies the VMDK code a bit.
This fixes the backing file qemu-iotests cases for VMDK....
vmdk: Clean up backing file handling
VMDK is doing interesting things when it needs to open a backing file. Thispatch changes that part to look more like in other drivers. The nice sideeffect is that the file name isn't needed any more in the open function....
vmdk: Convert to bdrv_open
It's a format driver, so implement bdrv_open instead of bdrv_file_open.
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>
raw-posix: Use pread/pwrite instead of lseek+read/write
This patch combines the lseek+read/write calls to use pread/pwriteinstead. This will result in fewer system calls and is already used byAIO.
Thanks to Jan Kiszka <jan.kiszka@siemens.com> for identifying excessive...
block: separate raw images from the file protocol
We're running into various problems because the "raw" file access, whichis used internally by the various image formats is entangled with the"raw" image format, which maps the VM view 1:1 to a file system....
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...
Fix dead initialization, spotted by clang analyzer
Fix clang warnings:/src/qemu/block/vvfat.c:1102:9: warning: Value stored to 'index3' during its initialization is never read int index3=index1+1;/src/qemu/cmd.c:290:15: warning: Value stored to 'p' during its initialization is never read...