summaryrefslogtreecommitdiffstats
path: root/block.c
Commit message (Collapse)AuthorAgeFilesLines
* block: add bdrv_find_backing_imageMarcelo Tosatti2012-01-261-0/+18
| | | | | | | | | Add bdrv_find_backing_image: given a BlockDriverState pointer, and an id, traverse the backing image chain to locate the id. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add BlockJob interface for long-running operationsStefan Hajnoczi2012-01-261-0/+48
| | | | | Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: make copy-on-read a per-request flagStefan Hajnoczi2012-01-261-11/+38
| | | | | | | | | | | | | | | | | | | | | Previously copy-on-read could only be enabled for all requests to a block device. This means requests coming from the guest as well as QEMU's internal requests would perform copy-on-read when enabled. For image streaming we want to support finer-grained behavior than just populating the image file from its backing image. Image streaming supports partial streaming where a common backing image is preserved. In this case guest requests should not perform copy-on-read because they would indiscriminately copy data which should be left in a backing image from the backing chain. Introduce a per-request flag for copy-on-read so that a block device can process both regular and copy-on-read requests. Overlapping reads and writes still need to be serialized for correctness when copy-on-read is happening, so add an in-flight reference count to track this. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: check bdrv_in_use() before blockdev operationsStefan Hajnoczi2012-01-261-0/+4
| | | | | | | | | | | | | Long-running block operations like block migration and image streaming must have continual access to their block device. It is not safe to perform operations like hotplug, eject, change, resize, commit, or external snapshot while a long-running operation is in progress. This patch adds the missing bdrv_in_use() checks so that block migration and image streaming never have the rug pulled out from underneath them. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: avoid useless checks on acb->bhPaolo Bonzini2011-12-151-3/+1
| | | | | | | | | Coverity is confused by this "if" and reports leaks on acb->bh. The bottom half is always deleted before releasing the AIOCB, in either bdrv_aio_cancel_em or bdrv_aio_bh_cb. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: simplify failure handling for bdrv_aio_multiwritePaolo Bonzini2011-12-151-26/+2
| | | | | | | | Now that early failure of bdrv_aio_writev is not possible anymore, mcb->num_requests can be set before the loop starts. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: bdrv_aio_* do not return NULLPaolo Bonzini2011-12-151-23/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Initially done with the following semantic patch: @ rule1 @ expression E; statement S; @@ E = ( bdrv_aio_readv | bdrv_aio_writev | bdrv_aio_flush | bdrv_aio_discard | bdrv_aio_ioctl ) (...); ( - if (E == NULL) { ... } | - if (E) { <... S ...> } ) which however missed the occurrence in block/blkverify.c (as it should have done), and left behind some unused variables. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: convert qemu_aio_flush() calls to bdrv_drain_all()Stefan Hajnoczi2011-12-051-0/+19
| | | | | | | | | | | | | Many places in QEMU call qemu_aio_flush() to complete all pending asynchronous I/O. Most of these places actually want to drain all block requests but there is no block layer API to do so. This patch introduces the bdrv_drain_all() API to wait for requests across all BlockDriverStates to complete. As a bonus we perform checks after qemu_aio_wait() to ensure that requests really have finished. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: wait_for_overlapping_requests() deadlock detectionStefan Hajnoczi2011-12-051-0/+8
| | | | | | | | | | Debugging a reentrant request deadlock was fun but in the future we need a quick and obvious way of detecting such bugs. Add an assert that checks we are not about to deadlock when waiting for another request. Suggested-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: implement bdrv_co_is_allocated() boundary casesStefan Hajnoczi2011-12-051-8/+18
| | | | | | | | | | | Cases beyond the end of the disk image are only implemented for block drivers that do not provide .bdrv_co_is_allocated(). It's worth making these cases generic so that block drivers that do implement .bdrv_co_is_allocated() also get them for free. Suggested-by: Mark Wu <wudxw@linux.vnet.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: core copy-on-read logicStefan Hajnoczi2011-12-051-0/+72
| | | | | Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: request overlap detectionStefan Hajnoczi2011-12-051-2/+43
| | | | | | | | | Detect overlapping requests and remember to align to cluster boundaries if the image format uses them. This assumes that allocating I/O is performed in cluster granularity - which is true for qcow2, qed, etc. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: wait for overlapping requestsStefan Hajnoczi2011-12-051-0/+35
| | | | | | | | | When copy-on-read is enabled it is necessary to wait for overlapping requests before issuing new requests. This prevents races between the copy-on-read and a write request. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add interface to toggle copy-on-readStefan Hajnoczi2011-12-051-0/+22
| | | | | | | | | The bdrv_enable_copy_on_read()/bdrv_disable_copy_on_read() functions can be used to programmatically enable or disable copy-on-read for a block device. Later patches add the actual copy-on-read logic. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add request trackingStefan Hajnoczi2011-12-051-1/+47
| | | | | | | | | | | | | | | | The block layer does not know about pending requests. This information is necessary for copy-on-read since overlapping requests must be serialized to prevent races that corrupt the image. The BlockDriverState gets a new tracked_request list field which contains all pending requests. Each request is a BdrvTrackedRequest record with sector_num, nb_sectors, and is_write fields. Note that request tracking is always enabled but hopefully this extra work is so small that it doesn't justify adding an enable/disable flag. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add bdrv_co_is_allocated() interfaceStefan Hajnoczi2011-12-051-13/+24
| | | | | | | | This patch introduces the public bdrv_co_is_allocated() interface which can be used to query image allocation status while the VM is running. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: drop .bdrv_is_allocated() interfaceStefan Hajnoczi2011-12-051-20/+18
| | | | | | | | | | | Now that all block drivers have been converted to .bdrv_co_is_allocated() we can drop .bdrv_is_allocated(). Note that the public bdrv_is_allocated() interface is still available but is in fact a synchronous wrapper around .bdrv_co_is_allocated(). Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add .bdrv_co_is_allocated()Stefan Hajnoczi2011-12-051-0/+37
| | | | | | | | | | | | | | | | | | | | This patch adds the .bdrv_co_is_allocated() interface which is identical to .bdrv_is_allocated() but runs in coroutine context. Running in coroutine context implies that other coroutines might be performing I/O at the same time. Therefore it must be safe to run while the following BlockDriver functions are in-flight: .bdrv_co_readv() .bdrv_co_writev() .bdrv_co_flush() .bdrv_co_is_allocated() The new .bdrv_co_is_allocated() interface is useful because it can be used when a VM is running, whereas .bdrv_is_allocated() is a synchronous interface that does not cope with parallel requests. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: use public bdrv_is_allocated() interfaceStefan Hajnoczi2011-12-051-1/+1
| | | | | | | | | | There is no need for bdrv_commit() to use the BlockDriver .bdrv_is_allocated() interface directly. Converting to the public interface gives us the freedom to drop .bdrv_is_allocated() entirely in favor of a new .bdrv_co_is_allocated() in the future. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* hmp/qmp: add block_set_io_throttleZhi Yong Wu2011-12-051-0/+15
| | | | | | Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add I/O throttling algorithmZhi Yong Wu2011-12-051-0/+234
| | | | | | Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add the blockio limits command line supportZhi Yong Wu2011-12-051-0/+39
| | | | | | Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: allow migration to work with image files (v3)Anthony Liguori2011-11-211-0/+16
| | | | | | | | | | | | | | | | | | | | Image files have two types of data: immutable data that describes things like image size, backing files, etc. and mutable data that includes offset and reference count tables. Today, image formats aggressively cache mutable data to improve performance. In some cases, this happens before a guest even starts. When dealing with live migration, since a file is open on two machines, the caching of meta data can lead to data corruption. This patch addresses this by introducing a mechanism to invalidate any cached mutable data a block driver may have which is then used by the live migration code. NB, this still requires coherent shared storage. Addressing migration without coherent shared storage (i.e. NFS) requires additional work. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* block: Make cache=unsafe flush to the OSKevin Wolf2011-11-111-3/+7
| | | | | | | | | | | | | | | cache=unsafe completely ignored bdrv_flush, because flushing the host disk costs a lot of performance. However, this means that qcow2 images (and potentially any other format) can lose data even after the guest has issued a flush if the qemu process crashes/is killed. In case of a host crash, data loss is certainly expected with cache=unsafe, but if just the qemu process dies this is a bit too unsafe. Now that we have two separate flush functions, we can choose to flush everythign to the OS, but don't enforce that it's physically written to the disk. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: Introduce bdrv_co_flush_to_osKevin Wolf2011-11-111-1/+12
| | | | | | | | | | qcow2 has a writeback metadata cache, so flushing a qcow2 image actually consists of writing back that cache to the protocol and only then flushes the protocol in order to get everything stable on disk. This introduces a separate bdrv_co_flush_to_os to reflect the split. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: Rename bdrv_co_flush to bdrv_co_flush_to_diskKevin Wolf2011-11-111-2/+2
| | | | | | | | | There are two different types of flush that you can do: Flushing one level up to the OS (i.e. writing data to the host page cache) or flushing it all the way down to the disk. The existing functions flush to the disk, reflect this in the function name. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add eject request callbackPaolo Bonzini2011-11-111-0/+7
| | | | | | | | | | | | | | | | | | Recent versions of udev always keep the tray locked so that the kernel can observe "eject request" events (aka tray button presses) even on discs that aren't mounted. Add support for these events in the ATAPI and SCSI cd drive device models. To let management cope with the behavior of udev, an event should also be added for "tray opened/closed". This way, after issuing an "eject" command, management can poll until the guests actually reacts to the command. They can then issue the "change" command after the tray has been opened, or try with "eject -f" after a (configurable?) timeout. However, with this patch and the corresponding support in the device models, at least it is possible to do a manual two-step eject+change sequence. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Merge remote-tracking branch 'kwolf/for-anthony' into stagingAnthony Liguori2011-10-311-10/+8
|\ | | | | | | | | Conflicts: block/vmdk.c
| * block: reinitialize across bdrv_close()/bdrv_open()Stefan Hajnoczi2011-10-281-2/+4
| | | | | | | | | | | | | | | | | | Several BlockDriverState fields are not being reinitialized across bdrv_close()/bdrv_open(). Make sure they are reset to their default values. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
| * block: set bs->read_only before .bdrv_open()Stefan Hajnoczi2011-10-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Several block drivers set bs->read_only in .bdrv_open() but block.c:bdrv_open_common() clobbers its value. Additionally, QED uses bdrv_is_read_only() in .bdrv_open() to decide whether to perform consistency checks. The correct ordering is to initialize bs->read_only from the open flags before calling .bdrv_open(). This way block drivers can override it if necessary and can use bdrv_is_read_only() in .bdrv_open(). Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
| * block: Fix bdrv_open use after freeKevin Wolf2011-10-281-1/+1
| | | | | | | | | | | | | | tmp_filename was used outside the block it was defined in, i.e. after it went out of scope. Move its declaration to the top level. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
| * block: Remove dead codeKevin Wolf2011-10-281-5/+1
| | | | | | | | Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* | Drop qemu-objects.h from modules that don't require itLuiz Capitulino2011-10-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | Previous commits dropped most qobjects usage from qemu modules (now they are a low level interface used by the QAPI). However, some modules still include the qemu-objects.h header file. This commit drops qemu-objects.h from some of those modules and includes qjson.h instead, which is what they actually need. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* | qapi: Convert query-blockstatsLuiz Capitulino2011-10-271-74/+37
| | | | | | | | | | Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* | qapi: Convert query-blockLuiz Capitulino2011-10-271-82/+30
| | | | | | | | | | Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* | block: Rename the BlockIOStatus enum valuesLuiz Capitulino2011-10-271-8/+10
| | | | | | | | | | | | | | | | | | | | The biggest change is to rename its prefix from BDRV_IOS to BLOCK_DEVICE_IO_STATUS. Next commit will convert the query-block command to the QAPI and that's how the enumeration is going to be generated. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* | block: iostatus: Drop BDRV_IOS_INVALLuiz Capitulino2011-10-271-2/+3
|/ | | | | | | | | | A future commit will convert bdrv_info() to the QAPI and it won't provide IOS_INVAL. Luckily all we have to do is to add a new 'iostatus_enabled' member to BlockDriverState and use it instead. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* block: change discard to co_discardPaolo Bonzini2011-10-211-2/+0
| | | | | | | | | | | | Since coroutine operation is now mandatory, convert both bdrv_discard implementations to coroutines. For qcow2, this means taking the lock around the operation. raw-posix remains synchronous. The bdrv_discard callback is then unused and can be eliminated. Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: change flush to co_flushPaolo Bonzini2011-10-211-2/+0
| | | | | | | | | | | | Since coroutine operation is now mandatory, convert all bdrv_flush implementations to coroutines. For qcow2, this means taking the lock. Other implementations are simpler and just forward bdrv_flush to the underlying protocol, so they can avoid the lock. The bdrv_flush callback is then unused and can be eliminated. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: add bdrv_co_discard and bdrv_aio_discard supportPaolo Bonzini2011-10-211-11/+91
| | | | | | | This similarly adds support for coroutine and asynchronous discard. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: unify flush implementationsPaolo Bonzini2011-10-211-90/+74
| | | | | | | | | Add coroutine support for flush and apply the same emulation that we already do for read/write. bdrv_aio_flush is simplified to always go through a coroutine. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: rename bdrv_co_rw_bhPaolo Bonzini2011-10-211-2/+2
| | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: drop bdrv_has_async_rw()Stefan Hajnoczi2011-10-141-6/+0
| | | | | | | | | | Commit cd74d83345e0e3b708330ab8c4cd9111bb82cda6 ("block: switch bdrv_read()/bdrv_write() to coroutines") removed the bdrv_has_async_rw() callers. This patch removes bdrv_has_async_rw() since it is no longer used. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: drop .bdrv_read()/.bdrv_write() emulationStefan Hajnoczi2011-10-141-72/+3
| | | | | | | | | | There is no need to emulate .bdrv_read()/.bdrv_write() since these interfaces are only called if aio and coroutine interfaces are not present. All valid BlockDrivers must implement either sync, aio, or coroutine interfaces. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: drop emulation functions that use coroutinesStefan Hajnoczi2011-10-141-54/+7
| | | | | | | | | | Block drivers that implement coroutine functions used to get sync and aio wrappers. This is no longer necessary since all request processing now happens in a coroutine. If a block driver implements the coroutine interface then none of the other interfaces will be invoked. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: switch bdrv_aio_writev() to coroutinesStefan Hajnoczi2011-10-131-64/+2
| | | | | | | | | | | More sync, aio, and coroutine unification. Make bdrv_aio_writev() go through coroutine request processing. Remove the dirty block callback mechanism which was needed only for aio processing and can be done more naturally in coroutine context. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: mark blocks dirty on coroutine write completionStefan Hajnoczi2011-10-131-1/+4
| | | | | | | | | | | | | | | The aio write operation marks blocks dirty when the write operation completes. The coroutine write operation marks blocks dirty before issuing the write operation. It seems safest to mark the block dirty when the operation completes so that anything tracking dirty blocks will not act before the change has been made to the image file. Make the coroutine write operation dirty blocks on write completion. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: switch bdrv_aio_readv() to coroutinesStefan Hajnoczi2011-10-131-13/+35
| | | | | | | | More sync, aio, and coroutine unification. Make bdrv_aio_readv() go through coroutine request processing. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: switch bdrv_read()/bdrv_write() to coroutinesStefan Hajnoczi2011-10-131-50/+62
| | | | | | | | | | | The bdrv_read()/bdrv_write() functions call .bdrv_read()/.bdrv_write(). They should go through bdrv_co_do_readv() and bdrv_co_do_writev() instead in order to unify request processing code across sync, aio, and coroutine interfaces. This is also an important step towards removing BlockDriverState .bdrv_read()/.bdrv_write() in the future. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: split out bdrv_co_do_readv() and bdrv_co_do_writev()Stefan Hajnoczi2011-10-131-7/+27
| | | | | | | | | | The public interface for I/O in coroutine context is bdrv_co_readv() and bdrv_co_writev(). Split out the request processing code into bdrv_co_do_readv() and bdrv_co_writev() so that it can be called internally when we refactor all request processing to use coroutines. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
OpenPOWER on IntegriCloud