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...
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.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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>
Merge remote branch 'kwolf/for-anthony' into staging
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
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
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
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>...
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.
Conflicts:
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...
Fix OpenBSD build
GCC 3.3.5 generates warnings for static forward declarations of data, sorearrange code to use static forward declarations of functions instead.
qcow2: Use QLIST_FOREACH_SAFE macro
blkdebug: Add events and rules
Block drivers can trigger a blkdebug event whenever they reach a place where itcould be useful to inject an error for testing/debugging purposes.
Rules are read from a blkdebug config file and describe which action is taken...
qcow2: Trigger blkdebug events
This adds blkdebug events to qcow2 to allow injecting I/O errors in specificplaces.
qcow2: Fix creation of large images
qcow_create2 assumes that the new image will only need one cluster for itsrefcount table initially. Obviously that's not true any more when the image isbig enough (exact value depends on the cluster size).
This patch calculates the refcount table size dynamically....
Replace calls of old bdrv_open
What is known today as bdrv_open2 becomes the new bdrv_open. All remainingcallers of the old function are converted to the new one. In some places theyeven know the right format, so they should have used bdrv_open2 from the...
block: split raw_getlength
Split up the raw_getlength into separate generic, solaris and BSDversions to reduce the ifdef maze a bit. The BSD variant stillis a complete maze, but to clean it up properly we'd need somepeople using the BSD variants to figure out what code is used...
qcow2: Return 0/-errno in write_l2_entries
Change write_l2_entries to return the real error code instead of -1.
qcow2: Fix error return code in qcow2_alloc_cluster_link_l2
Fix qcow2_alloc_cluster_link_l2 to return the real error code like it does inall other error cases.
qcow2: Return 0/-errno in write_l1_entry
Change write_l1_entry to return the real error code instead of -1.
qcow2: Return 0/-errno in l2_allocate
Returning NULL on error doesn't allow distinguishing between different errors.Change the interface to return an integer for -errno.
blkdebug: Basic request passthrough
This isn't doing anything interesting. It creates the blkdebug block driver asa protocol which just passes everything through to raw.
blkdebug: Inject errors
Add a mechanism to inject errors instead of passing requests on. With nofurther patches applied, you can use it by setting inject_errno in gdb.
raw-posix: don't assign bs->read_only
bdrv_open already takes care of this for us.
Signed-off-by: Christoph Hellwig <hch@lst.de>Acked-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
qcow2: Remove request from in-flight list after error
If we complete a request with a failure we need to remove it from the list ofrequests that are in flight. If we don't do it, the next time the same AIOCB isused for a cluster allocation it will create a loop in the list and qemu will...
qcow2: Don't ignore immediate read/write failures
Returning -EIO is far from optimal, but at least it's an error code.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
raw-posix: Better error return values for hdev_create
Now that we output an error message according to the returned error code inqemu-img, let's return the real error codes. "Input/output error" foreverything isn't helpful.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>...
Replace assert(0) with abort() or cpu_abort()
When building with -DNDEBUG, assert(0) will not stop executionso it must not be used for abnormal termination.
Use cpu_abort() when in CPU context, abort() otherwise.
Fix build with -DNDEBUG in CFLAGS
qcow2: return errno instead of -1
Signed-off-by: Juan Quintela <quintela@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qcow: return errno instead of -1
vmdk: return errno instead of -1
vmdk: make vmdk_snapshot_create return -errno
vmdk: fix double free
fail_gd error case would also free rgd_buf that was already freed
vmdk: share cleanup code
cleanup code is identical for error/success cases. Only differenceare goto labels.
cow: return errno instead of -1
Remove not needed ret = 0 assignment.
qcow2: Factor next_refcount_table_size out
When the refcount table grows, it doesn't only grow by one entry but reservessome space for future refcount blocks. The algorithm to calculate the number ofentries stays the same with the fixes, so factor it out before replacing the...
qcow2: Rewrite alloc_refcount_block/grow_refcount_table
The current implementation of alloc_refcount_block and grow_refcount_table hasfundamental problems regarding error handling. There are some places where anI/O error means that the image is going to be corrupted. I have found that the...
qcow2: More checks for qemu-img check
Implement some more refcount block related checks
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qcow2: Fix image creation regression
When checking for errors, commit db89119d compares with the wrong values,failing image creation even when there was no error. Additionally, if anerror has occured, we can't preallocate the image (it's likely broken)....
qcow2: Fix access after end of array
If a write requests crosses a L2 table boundary and all clusters until theend of the L2 table are usable for the request, we must not look at the nextL2 entry because we already have arrived at the end of the array....
don't dereference NULL after failed strdup
Most of these are obvious NULL-deref bug fixes, for example,the ones in these files:
block/curl.c net.c slirp/misc.c
and the first one in block/vvfat.c.The others in block/vvfat.c may not lead to an immediate segfault, but I...
qcow2: Fix signedness bugs
Checking for return codes < 0 isn't really going to work with unsignedtypes. Use signed types instead.
block/curl: %Z is not a valid conversion specifier
Signed-off-by: malc <av1474@comtv.ru>
Do not use dprintf
dprintf is already claimed by POSIX1, and on at least one systemis implemented as a macro
[1] http://www.opengroup.org/onlinepubs/9699919799/functions/dprintf.html
block/raw-posix: Abort on pread beyond end of non-growable file
This shouldn't happen under any normal circumstances. However, it looks likeit's possible to achieve this with corrupted images. Without this patchraw_pread is hanging in an endless loop in such cases....
win32: pair qemu_memalign() with qemu_vfree()
Win32 suffers from a very big memory leak when dealing with SCSI devices.Each read/write request allocates memory with qemu_memalign (ieVirtualAlloc) but frees it with qemu_free (ie free).Pair all qemu_memalign() calls with qemu_vfree() to prevent such leaks....
qcow2: rename two QCowAIOCB members
The n member is not very descriptive and very hard to grep, rename it tocur_nr_sectors to better indicate what it is used for. Also renamenb_sectors to remaining_sectors as that is what it is used for.
block: kill BDRV_O_CREAT
The BDRV_O_CREAT option is unused inside qemu and partially duplicatesthe bdrv_create method. Remove it, and the -C option to qemu-io whichisn't used in qemu-iotests anyway.
Signed-off-by: Christoph Hellwig <hch@lst.de>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Ask for read-write permissions when opening files
Found some places that seems needs this explicitly, now thatread-write is not the default.
Signed-off-by: Naphtali Sprei <nsprei@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Read-only device changed to opens it's file for read-only.
block/cow.c: fix warnings with _FORTIFY_SOURCE
CC block/cow.occ1: warnings being treated as errorsblock/cow.c: In function 'cow_create':block/cow.c:251: error: ignoring return value of 'write', declared with attribute warn_unused_resultblock/cow.c:253: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result...
block/qcow.c: fix warnings with _FORTIFY_SOURCE
CC block/qcow.occ1: warnings being treated as errorsblock/qcow.c: In function 'qcow_create':block/qcow.c:804: error: ignoring return value of 'write', declared with attribute warn_unused_resultblock/qcow.c:806: error: ignoring return value of 'write', declared with attribute warn_unused_result...
block/vmdk.o: fix warnings with _FORTIFY_SOURCE
CC block/vmdk.occ1: warnings being treated as errorsblock/vmdk.c: In function 'vmdk_snapshot_create':block/vmdk.c:236: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result...
block/vvfat.c: fix warnings with _FORTIFY_SOURCE
CC block/vvfat.occ1: warnings being treated as errorsblock/vvfat.c: In function 'commit_one_file':block/vvfat.c:2259: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result...
block/qcow2.c: fix warnings with _FORTIFY_SOURCE
CC block/qcow2.occ1: warnings being treated as errorsblock/qcow2.c: In function 'qcow_create2':block/qcow2.c:829: error: ignoring return value of 'write', declared with attribute warn_unused_resultblock/qcow2.c:838: error: ignoring return value of 'write', declared with attribute warn_unused_result...
qcow2: Fix error handling in qcow_save_vmstate
Don't assume success but pass the bdrv_pwrite return value on.
qcow2: Return 0/-errno in get_cluster_table
Switching to 0/-errno allows it to distinguish different error cases.
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.
qcow2: Fix error handling in grow_refcount_table
Return the appropriate error code instead of -EIO.
qcow2: Improve error handling in update_refcount
If update_refcount fails, try to undo any changes made so far to avoidinconsistencies in the image file.
qcow2: Allow updating no refcounts
There's absolutely no problem with updating the refcounts of 0 clusters.At least snapshot code is doing this and would fail once the result ofupdate_refcount isn't ignored any more.
qcow2: Don't ignore update_refcount return value
update_refcount can return errors that need to be handled by the callers.
qcow2: Don't ignore qcow2_alloc_clusters return value
Now that qcow2_alloc_clusters can return error codes, we must handle them inthe callers of qcow2_alloc_clusters.