History | View | Annotate | Download (125.6 kB)
qemu-io: Add AIO debugging commands
This makes the blkdebug suspend/resume functionality available inqemu-io. Use it like this:
$ ./qemu-io blkdebug::/tmp/test.qcow2 qemu-io> break write_aio req_a qemu-io> aio_write 0 4k qemu-io> blkdebug: Suspended request 'req_a'...
block: bdrv_img_create(): add Error ** argument
This commit adds an Error ** argument to bdrv_img_create() and set itappropriately on error.
Callers of bdrv_img_create() pass NULL for the new argument and stillrely on bdrv_img_create()'s return value. Next commits will change...
block: bdrv_img_create(): drop unused error handling code
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Improve bdrv_aio_co_cancel_em
Instead of waiting for all requests to complete, wait just for thespecific request that should be cancelled.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Factor out bdrv_open_flags
block: Avoid second open for format probing
This fixes problems that are caused by the additional open/close cycleof the existing format probing, for example related to qemu-nbd without-t option or file descriptor passing.
block: Fix regression for MinGW (assertion caused by short string)
The local string tmp_filename is passed to function get_tmp_filenamewhich expects a string with minimum size MAX_PATH for w32 hosts.
MAX_PATH is 260 and PATH_MAX is 259, so tmp_filename was too short....
aio: use g_slice_alloc() for AIOCB pooling
AIO control blocks are frequently acquired and released because each aiorequest involves at least one AIOCB. Therefore, we pool them to avoidheap allocation overhead.
The problem with the freelist approach in AIOPool is thread-safety. If...
aio: rename AIOPool to AIOCBInfo
Now that AIOPool no longer keeps a freelist, it isn't really a "pool" anymore. Rename it to AIOCBInfo and make it const since it no longerneeds to be modified.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Merge remote-tracking branch 'kwolf/for-anthony' into staging
iostatus: forward block_job_iostatus_reset to block job
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: bdrv_create(): don't leak cco.filename on error
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: add bdrv_query_info
Extract it out of the implementation of "info block".
block: add bdrv_query_stats
qmp_query_blockstat cannot have errors, remove the Error argument andcreate a new public function bdrv_query_stats out of it.
block: add bdrv_open_backing_file
Mirroring runs without the backing file so that it can be copied outsideQEMU. However, we need to add it at the time the job is completed andQEMU switches to the target. Factor out the common bits of opening animage and completing a mirroring operation....
block: introduce new dirty bitmap functionality
Assert that write_compressed is never used with the dirty bitmap.Setting the bits early is wrong, because a coroutine might concurrentlyexamine them and copy incomplete data from the source.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>...
block: export dirty bitmap information in query-block
block: make bdrv_find_backing_image compare canonical filenames
Currently, bdrv_find_backing_image compares bs->backing_file withwhat is passed in as a backing_file name. Mismatches may occur,however, when bs->backing_file and backing_file are not both...
block: prepare code for adding block notifiers
There is no reason in principle to skip job cancellation and drainingof pending I/O when there is no medium in the disk. Do these unconditionally,which also prepares the code for the next patch.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: add close notifiers
The first user of close notifiers will be the embedded NBD server.It would be possible to use them to do some of the ad hoc processing(e.g. for block jobs and I/O limits) that is currently done bybdrv_close.
Acked-by: Kevin Wolf <kwolf@redhat.com>...
block: avoid buffer overrun by using pstrcpy, not strncpy
Also, use PATH_MAX, rather than the arbitrary 1024.Using PATH_MAX is more consistent with other filename-relatedvariables in this file, like backing_filename and tmp_filename.
iostatus: change is_read to a bool
Do this while we are touching this part of the code, before introducingmore uses of "int is_read".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Reviewed-by: Eric Blake <eblake@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
iostatus: reorganize io error code
Move the common part of IDE/SCSI/virtio error handling to the blocklayer. The new function bdrv_error_action subsumes all three ofbdrv_emit_qmp_error_event, vm_stop, bdrv_iostatus_set_err.
The same scheme will be used for errors in block jobs....
block: introduce block job error
The following behaviors are possible:
'report': The behavior is the same as in 1.1. An I/O error,respectively during a read or a write, will complete the job immediatelywith an error code.
'ignore': An I/O error, respectively during a read or a write, will be...
iostatus: move BlockdevOnError declaration to QAPI
This will let block-stream reuse the enum. Places that used the enumsare renamed accordingly.
iostatus: rename BlockErrorAction, BlockQMPEventAction
We want to remove knowledge of BLOCK_ERR_STOP_ENOSPC from drivers;drivers should only be told whether to stop/report/ignore the error.On the other hand, we want to keep using the nicer BlockErrorAction...
block: move job APIs to separate files
block: helper function, to find the base image of a chain
This is a simple helper function, that will return the base imageof a given image chain.
Signed-off-by: Jeff Cody <jcody@redhat.com>Reviewed-by: Eric Blake <eblake@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: add support functions for live commit, to find and delete images.
Add bdrv_find_overlay(), and bdrv_drop_intermediate().
bdrv_find_overlay(): given 'bs' and the active (topmost) BDS of an image chain, find the image that is the immediate top of 'bs'...
block: remove keep_read_only flag from BlockDriverState struct
The keep_read_only flag is no longer used, in favor of the bdrvflag BDRV_O_ALLOW_RDWR.
Signed-off-by: Jeff Cody <jcody@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: convert bdrv_commit() to use bdrv_reopen()
Currently, bdrv_commit() reopens images r/w itself, via risky_delete() and _open() calls. Use the new safe method for drive reopen.
block: correctly set the keep_read_only flag
I believe the bs->keep_read_only flag is supposed to reflectthe initial open state of the device. If the device is initiallyopened R/O, then commit operations, or reopen operations changingto R/W, are prohibited....
block: make bdrv_set_enable_write_cache() modify open_flags
bdrv_set_enable_write_cache() sets the bs->enable_write_cache flag,but without the flag recorded in bs->open_flags, then next timea reopen() is performed the enable_write_cache setting may beinadvertently lost....
block: Framework for reopening files safely
This is based on Supriya Kannery's bdrv_reopen() patch series.
This provides a transactional method to reopen multipleimages files safely.
Image files are queue for reopen via bdrv_reopen_queue(), and thereopen occurs when bdrv_reopen_multiple() is called. Changes are...
block: fix block tray status
The tray status should change also if you eject empty block device.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Don't forget to delete temporary file
The caller would not delete temporary file after failed get_tmp_filename().
Signed-off-by: Dunrong Huang <riegamaths@gmail.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Flush parent to OS with cache=unsafe
Commit 29cdb251 already added a comment that no unnecessary flushes todisk will occur, this patch makes the code even get to the point of thecomment. This is mostly theoretical because in practice we only stack...
qmp: query-block: add 'encryption_key_missing' field
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>Reviewed-by: Markus Armbruster <armbru@redhat.com>
block: Use bdrv_get_backing_file_depth()
Use the dedicated counting function in qmp_query_block in order topropagate the backing file depth to HMP and add backing_file_depthto qmp-commands.hx
Signed-off-by: Benoit Canet <benoit@irqsave.net>Reviewed-by: Eric Blake <eblake@redhat.com>...
block: create bdrv_get_backing_file_depth()
Create bdrv_get_backing_file_depth() in order to be able to showin QMP and HMP how many ancestors backing an image a block devicehave.
Avoid returning void
It's silly and non-conforming to standards to return void,don't do it.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
block: Geometry and translation hints are now useless, purge them
There are two producers of these hints: drive_init() on behalf of-drive, and hd_geometry_guess().
The only consumer of the hint is hd_geometry_guess().
The callers of hd_geometry_guess() call it only when drive_init()...
hd-geometry: Move disk geometry guessing back from block.c
Commit f3d54fc4 factored it out of hw/ide.c for reuse. Sensible,except it was put into block.c. Device-specific functionality shouldbe kept in device code, not the block layer. Move it tohw/hd-geometry.c, and make stylistic changes required to keep...
fdc: Move floppy geometry guessing back from block.c
Commit 5bbdbb46 moved it to block.c because "other geometry guessingfunctions already reside in block.c". Device-specific functionalityshould be kept in device code, not the block layer. Move it back....
Merge remote-tracking branch 'mjt/mjt-iov2' into staging
block: Factor bdrv_read_unthrottled() out of guess_disk_lchs()
To prepare move of guess_disk_lchs() into hw/, where it pokingBlockDriverState member io_limits_enabled directly would be unclean.
Signed-off-by: Markus Armbruster <armbru@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
fdc: Drop broken code for user-defined floppy geometry
bdrv_get_floppy_geometry_hint() fails to store through its parameterdrive when bs has a geometry hint. Makes fd_revalidate() assignrandom crap to drv->drive.
Has been broken that way for ages. Harmless, because:...
block: copy over job and dirty bitmap fields in bdrv_append
While these should not be in use at the time a transaction is started,a command in the prepare phase of a transaction might have added them,so they need to be brought over.
block: introduce bdrv_swap, implement bdrv_append on top of it
The new function can be made a bit nicer than bdrv_append. It swaps thewhole contents, and then swaps back (using the usual t=a;a=b;b=t idiom)the fields that need to stay on top. Thus, it does not need explicit...
block: New bdrv_get_flags()
Signed-off-by: Markus Armbruster <armbru@redhat.com>Acked-by: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: flush in writethrough mode after writes
We want to make the formats handle their own flushesautonomously, while keeping for guests the ability to use a writethroughcache. Since formats will write metadata via bs->file, bdrv_co_do_writevis the only place where we need to add a flush....
block: copy enable_write_cache in bdrv_append
Because the guest will be able to flip enable_write_cache, the actualstate may not match what is used to open the new snapshot.
block: add bdrv_set_enable_write_cache
block: always open drivers in writeback mode
Formats are entirely in charge of flushes for metadata writes. Forguest-initiated writes, a writethrough cache is faked in the block layer.So we can always open in writeback mode.
block: Replace bdrv_get_format() by bdrv_get_format_name()
So callers don't need to know anything about maximum name length.Returning a pointer is safe, because the name string lives as long asthe block driver it names, and block drivers don't die.
Requested by Peter Maydell....
stream: move is_allocated_above to block.c
qemu-img check -r for repairing images
The QED block driver already provides the functionality to not onlydetect inconsistencies in images, but also fix them. However, thisfunctionality cannot be manually invoked with qemu-img, but thecheck happens only automatically during bdrv_open()....
allow qemu_iovec_from_buffer() to specify offset from which to start copying
Similar to qemu_iovec_memset(QEMUIOVector *qiov, size_t offset, int c, size_t bytes);the new prototype is: qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset,...
consolidate qemu_iovec_copy() and qemu_iovec_concat() and make them consistent
qemu_iovec_concat() is currently a wrapper forqemu_iovec_copy(), use the former (with extra"0" arg) in a few places where it is used.
Change skip argument of qemu_iovec_copy() from...
change qemu_iovec_to_buf() to match other to,from_buf functions
It now allows specifying offset within qiov to start from andamount of bytes to copy. Actual implementation is just a callto iov_to_buf().
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
block: prevent snapshot mode $TMPDIR symlink attack
In snapshot mode, bdrv_open creates an empty temporary file withoutchecking for mkstemp or close failure, and ignoring the possibilityof a buffer overrun given a surprisingly long $TMPDIR.Change the get_tmp_filename function to return int (not void),...
block: fix snapshot on QED
QED's opaque data includes a pointer back to the BlockDriverState.This breaks when bdrv_append shuffles data between bs_new and bs_top.To avoid this, add a "rebind" function that tells the driver aboutthe new relationship between the BlockDriverState and its opaque....
block: another bdrv_append fix
bdrv_append must also copy open_flags to the top, because the snapshothas BDRV_O_NO_BACKING set. This causes interesting results if youlater use drive-reopen (not upstream) to reopen the image, and losethe backing file in the process....
block: do not reuse the backing file across bdrv_close/bdrv_open
This is another bug caused by not doing a full cleanup of the BDSacross close/open. This was found with mirroring by Shaolong Hu,but it can probably be reproduced also with eject or change....
block: fully delete bs->file when closing
We are reusing bs->file across close/open, which may not cause anyknown bugs but is a recipe for trouble. Prefer bdrv_delete, andenjoy the new invariant in the implementation of bdrv_delete.
block: add block_job_sleep_ns
This function abstracts the pretty complex semantics of the "busy" member of BlockJob.
block: wait for job callback in block_job_cancel_sync
The limitation on not having I/O after cancellation cannot really bekept. Even streaming has a very small race window where you couldcancel a job and have it report completion. If this window is hit,...
block: simplify path_is_absolute
On Windows, all the logic is already in is_windows_drive andis_windows_drive_prefix. On POSIX, there is no need to lookout for colons.
The win32 code changes the behaviour in some cases, we could havesomething like "d:foo.img". The old code would treat it as relative...
block: protect path_has_protocol from filenames with colons
path_has_protocol will erroneously return "true" if the colon is partof a filename. These names are common with stable device names producedby udev. We cannot fully protect against this in case the filename...
block: move field reset from bdrv_open_common to bdrv_close
bdrv_close should leave fields in the same state as bdrv_new. It isnot up to bdrv_open_common to fix the mess.
Also, backing_format was not being re-initialized.
qemu-img: make "info" backing file output correct and easier to use
qemu-img info should use the same logic as qemu when printing thebacking file path, or debugging becomes quite tricky. We can alsosimplify the output in case the backing file has an absolute path...
block: add the support to drain throttled requests
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>[ Iterate until all block devices have processed all requests, add comments. - Paolo ]Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: push bdrv_change_backing_file error checking up from drivers
This check applies to all drivers, but QED lacks it.
Reviewed-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: update in-memory backing file and format
These are needed to print "info block" output correctly. QCOW2 does thisbecause it needs it to write the header, but QED does not, and common codeis the right place to do it.
Reviewed-by: Kevin Wolf <kwolf@redhat.com>...
block: open backing file as read-only when probing for size
bdrv_img_create will temporarily open the backing file to probe its size.However, this could be done with a read-write open if the wrong flags arepassed to bdrv_img_create. Since there is really no documentation on...
block: fix allocation size for dirty bitmap
Also reuse elsewhere the new constant for sizeof(unsigned long) * 8.
The dirty bitmap is allocated in bits but declared as unsigned long.Thus, its memory block is accessed beyond its end unless the imageis a multiple of 64 chunks (i.e. a multiple of 64 MB)....
block: make bdrv_create adopt coroutine
The current qemu.git introduces failure with preallocation and somesizes:
qemu-img create f qcow2 new.img 976563K -o preallocation=metadataqemu-img: qemu-coroutine-lock.c:111: qemu_co_mutex_unlock: Assertion`mutex>locked == 1' failed....
block: use Error mechanism instead of -errno for block_job_create()
The block job API uses -errno return values internally and we convertthese to Error in the QMP functions. This is ugly because the Errorshould be created at the point where we still have all the relevant...
block: use Error mechanism instead of -errno for block_job_set_speed()
There are at least two different errors that can occur inblock_job_set_speed(): the job might not support setting speeds or thevalue might be invalid.
Use the Error mechanism to report the error where it occurs....
block: change block-job-set-speed argument from 'value' to 'speed'
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>Acked-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
block: add 'speed' optional parameter to block-stream
Allow streaming operations to be started with an initial speed limit.This eliminates the window of time between starting streaming andissuing block-job-set-speed. Users should use the new optional 'speed'...
qcow2: Zero write support
qemu-img: let 'qemu-img convert' flush data
The 'qemu-img convert -h' advertise that the default cache mode is'writeback', while in fact it is 'unsafe'.
This patch 1) fix the help manual and 2) let bdrv_close() call bdrv_flush()
2) is needed because some backend storage doesn't have a self-flush...
block: Drain requests in bdrv_close
If an AIO request is in flight that refers to a BlockDriverState thathas been closed and possibly even freed, more or less anything couldhappen. I have seen segfaults, -EBADF return values and qcow2 sometimesactually catches the situation in bdrv_close() and abort()s....
block: add a function to clear incoming live migration flags
This function will clear all BDRV_O_INCOMING flags.
Signed-off-by: Benoit Canet <benoit.canet@gmail.com>Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: bdrv_append() fixes
A few fixups for bdrv_append():
The new bs (bs_new) passed into bdrv_append() should be anonymous. Ratherthan call bdrv_make_anon() to enforce this, use an assert to catch when a calleris passing in a bs_new that is not anonymous....
block: disable I/O throttling on sync api
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: fix streaming/closing race
Streaming can issue I/O while qcow2_close is running. This causes theL2 caches to become very confused or, alternatively, could cause asegfault when the streaming coroutine is reentered after closing itsblock device. The fix is to cancel streaming jobs when closing their...
block: set job->speed in block_set_speed
There is no need to do this in every implementation of set_speed(even though there is only one right now).
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>...
block: push recursive flushing up from drivers
block: handle -EBUSY in bdrv_commit_all()
Monitor operations that manipulate image files must not execute while abackground job (like image streaming) is in progress. This preventscorruptions from happening when two pieces of code are manipulating the...
qapi: Introduce blockdev-group-snapshot-sync command
This is a QAPI/QMP only command to take a snapshot of a group ofdevices. This is similar to the blockdev-snapshot-sync command, exceptblockdev-group-snapshot-sync accepts a list devices, filenames, and...
block: drop aio_multiwrite in BlockDriver
These were never used.
block: add a transfer rate for floppy types
Floppies must be read at a specific transfer rate, depending of its own format.Update floppy description table to include required transfer rate.
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qmp: add DEVICE_TRAY_MOVED event
It's emitted whenever the tray is moved by the guest or by HMP/QMPcommands.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>Reviewed-by: Markus Armbruster <armbru@redhat.com>Acked-by: Kevin Wolf <kwolf@redhat.com>
block: bdrv_eject(): Make eject_flag a real bool
block: Rename bdrv_mon_event() & BlockMonEventAction
They are QMP events, not monitor events. Rename them accordingly.
Also, move bdrv_emit_qmp_error_event() up in the file. A new event willbe added soon and it's good to have them next each other.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>...
block: add .bdrv_co_write_zeroes() interface
The ability to zero regions of an image file is a useful primitive forhigher-level features such as image streaming or zero write detection.
Image formats may support an optimized metadata representation instead...
block: perform zero-detection during copy-on-read
Copy-on-Read populates the image file with data read from a backingimage. In order to avoid bloating the image file when all zeroes areread we should scan the buffer and perform an optimized zero write...
block: add bdrv_find_backing_image
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>...