block: Rework bdrv_close_all()
PATCH v2 1/22 iotests: Move _filter_nbd into common.filter
In reply to Max Reitz_filter_nbd can be useful for other NBD tests, too, therefore it should reside in common.filter, and it should support URLs of the "nbd://" format and export names.
The NBD log lines ("/your/source/dir/nbd.c:function():line: error") should not be converted to empty lines but removed altogether.
--- tests/qemu-iotests/083 | 13 +------------ tests/qemu-iotests/083.out | 10 ---------- tests/qemu-iotests/common.filter | 12 ++++++++++++ 3 files changed, 13 insertions(+), 22 deletions(-)
tests/qemu-iotests/083 +1 -12
@@ -49,17 +49,6 @@ wait_for_tcp_port() { done } -filter_nbd() { - # nbd.c error messages contain function names and line numbers that are prone - # to change. Message ordering depends on timing between send and receive - # callbacks sometimes, making them unreliable. - # - # Filter out the TCP port number since this changes between runs. - sed -e 's#^.*nbd\.c:.*##g' \ - -e 's#nbd:127\.0\.0\.1:[^:]*:#nbd:127\.0\.0\.1:PORT:#g' \ - -e 's#\(exportname=foo\|PORT\): Failed to .*$#\1#' -} - check_disconnect() { event=$1 when=$2
@@ -84,7 +73,7 @@ EOF $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nbd-fault-injector.conf" 2>&1 >/dev/null & wait_for_tcp_port "127\\.0\\.0\\.1:$port" - $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | filter_nbd + $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd echo }
tests/qemu-iotests/083.out +0 -10
@@ -51,7 +51,6 @@ no file open, try 'help open' === Check disconnect after neg2 === - read failed: Input/output error === Check disconnect 8 neg2 ===
@@ -66,42 +65,34 @@ no file open, try 'help open' === Check disconnect before request === - read failed: Input/output error === Check disconnect after request === - read failed: Input/output error === Check disconnect before reply === - read failed: Input/output error === Check disconnect after reply === - read failed: Input/output error === Check disconnect 4 reply === - read failed: Input/output error === Check disconnect 8 reply === - read failed: Input/output error === Check disconnect before data === - read failed: Input/output error === Check disconnect after data === - read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
@@ -132,7 +123,6 @@ no file open, try 'help open' === Check disconnect after neg-classic === - read failed: Input/output error *** done
tests/qemu-iotests/common.filter +12 -0
@@ -224,5 +224,17 @@ _filter_qemu_img_map() -e 's/Mapped to *//' | _filter_testdir | _filter_imgfmt } +_filter_nbd() +{ + # nbd.c error messages contain function names and line numbers that are + # prone to change. Message ordering depends on timing between send and + # receive callbacks sometimes, making them unreliable. + # + # Filter out the TCP port number since this changes between runs. + sed -e '/^.*nbd\.c:.*/d' \ + -e 's#nbd:\(//\)\?127\.0\.0\.1:[0-9]*#nbd:\1127.0.0.1:PORT#g' \ + -e 's#\(exportname=foo\|PORT\): Failed to .*$#\1#' +} + # make sure this script returns success true
Signature · 1 line
2.1.0
PATCH v2 5/22 block: Move BDS close notifiers into BB
In reply to Max ReitzThe only remaining user of the BDS close notifiers is NBD which uses them to determine when a BDS tree is being ejected. This patch removes the BDS-level close notifiers and adds a notifier list to the BlockBackend structure that is invoked whenever a BDS is removed. While it might make sense to have a similar list for the "insert BDS tree" event, there would be no users so far, so no such list is added here.
Note that the mixture of "eject" and "close" in the new NBD code is intentional; notifiers to be called on bdrv_close_all() will be added later, and those will reuse the BDRVCloseNotifier type.
--- block.c | 7 ------- block/block-backend.c | 11 +++++++---- blockdev-nbd.c | 36 +----------------------------------- include/block/block.h | 1 - include/block/block_int.h | 2 -- include/sysemu/block-backend.h | 2 +- nbd.c | 35 +++++++++++++++++++++++++++++++++++ 7 files changed, 44 insertions(+), 50 deletions(-)
block.c +0 -7
@@ -371,7 +371,6 @@ BlockDriverState *bdrv_new(void)for (i =0 ; i <BLOCK_OP_TYPE_MAX ; i++) {QLIST_INIT (&bs->op_blockers[i]); } -notifier_list_init (&bs->close_notifiers);notifier_with_return_list_init (&bs->before_write_notifiers);qemu_co_queue_init (&bs->throttled_reqs[0 ]);qemu_co_queue_init (&bs->throttled_reqs[1 ]);
@@ -381,11 +380,6 @@ BlockDriverState *bdrv_new(void)return bs; } -void bdrv_add_close_notifier (BlockDriverState *bs,Notifier *notify) -{ -notifier_list_add (&bs->close_notifiers, notify); -} -BlockDriver *bdrv_find_format (const char *format_name) {BlockDriver *drv1;
@@ -1864,7 +1858,6 @@ void bdrv_close(BlockDriverState *bs)bdrv_drain_all ();/* complete I/O */ bdrv_flush (bs);bdrv_drain_all ();/* in case flush left pending I/O */ -notifier_list_notify (&bs->close_notifiers, bs);if (bs->drv) {if (bs->backing_hd) {
block/block-backend.c +7 -4
@@ -47,6 +47,8 @@ struct BlockBackend {BlockdevOnError on_read_error, on_write_error;bool iostatus_enabled;BlockDeviceIoStatus iostatus; + +NotifierList remove_bs_notifiers; }; typedef struct BlockBackendAIOCB {
@@ -97,6 +99,7 @@ BlockBackend *blk_new(const char *name, Error **errp) blk =g_new0 (BlockBackend,1 ); blk->name =g_strdup (name); blk->refcnt =1 ; +notifier_list_init (&blk->remove_bs_notifiers);QTAILQ_INSERT_TAIL (&blk_backends, blk, link);return blk; }
@@ -320,6 +323,8 @@ void blk_remove_bs(BlockBackend *blk)return ; } +notifier_list_notify (&blk->remove_bs_notifiers, blk); +blk_update_root_state (blk);bdrv_unref (blk->bs);
@@ -1067,11 +1072,9 @@ void blk_remove_aio_context_notifier(BlockBackend *blk, } } -void blk_add_close_notifier (BlockBackend *blk,Notifier *notify) +void blk_add_remove_bs_notifier (BlockBackend *blk,Notifier *notify) { -if (blk->bs) { -bdrv_add_close_notifier (blk->bs, notify); - } +notifier_list_add (&blk->remove_bs_notifiers, notify); }void blk_io_plug (BlockBackend *blk)
blockdev-nbd.c +1 -35
@@ -47,36 +47,11 @@ void qmp_nbd_server_start(SocketAddress *addr, Error **errp) } } -/* Hook into the BlockDriverState notifiers to close the export when -* the file is closed. -*/ -typedef struct NBDCloseNotifier { -Notifier n; -NBDExport *exp; -QTAILQ_ENTRY (NBDCloseNotifier) next; -}NBDCloseNotifier ; - -static QTAILQ_HEAD(, NBDCloseNotifier) close_notifiers = -QTAILQ_HEAD_INITIALIZER (close_notifiers); - -static void nbd_close_notifier (Notifier *n,void *data) -{ -NBDCloseNotifier *cn =DO_UPCAST (NBDCloseNotifier, n, n); - -notifier_remove (&cn->n); -QTAILQ_REMOVE (&close_notifiers, cn, next); - -nbd_export_close (cn->exp); -nbd_export_put (cn->exp); -g_free (cn); -} -void qmp_nbd_server_add (const char *device,bool has_writable,bool writable,Error **errp) {BlockBackend *blk;NBDExport *exp; -NBDCloseNotifier *n;if (server_fd ==-1 ) {error_setg (errp,"NBD server not running" );
@@ -108,20 +83,11 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, exp =nbd_export_new (blk,0 ,-1 , writable ?0 :NBD_FLAG_READ_ONLY ,NULL );nbd_export_set_name (exp, device); - - n =g_new0 (NBDCloseNotifier,1 ); - n->n.notify = nbd_close_notifier; - n->exp = exp; -blk_add_close_notifier (blk, &n->n); -QTAILQ_INSERT_TAIL (&close_notifiers, n, next); }void qmp_nbd_server_stop (Error **errp) { -while (!QTAILQ_EMPTY (&close_notifiers)) { -NBDCloseNotifier *cn =QTAILQ_FIRST (&close_notifiers); -nbd_close_notifier (&cn->n,nbd_export_get_blockdev (cn->exp)); - } +nbd_export_close_all ();if (server_fd !=-1 ) {qemu_set_fd_handler2 (server_fd,NULL ,NULL ,NULL ,NULL );
include/block/block.h +0 -1
@@ -196,7 +196,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state,void bdrv_reopen_commit (BDRVReopenState *reopen_state);void bdrv_reopen_abort (BDRVReopenState *reopen_state);void bdrv_close (BlockDriverState *bs); -void bdrv_add_close_notifier (BlockDriverState *bs,Notifier *notify);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors); int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
include/block/block_int.h +0 -2
@@ -350,8 +350,6 @@ struct BlockDriverState {BlockDriverState *backing_hd;BlockDriverState *file; -NotifierList close_notifiers; -/* Callback before write request is processed */ NotifierWithReturnList before_write_notifiers;
include/sysemu/block-backend.h +1 -1
@@ -158,7 +158,7 @@ void blk_remove_aio_context_notifier(BlockBackend *blk, void *), void (*detach_aio_context)(void *), void *opaque); -void blk_add_close_notifier (BlockBackend *blk,Notifier *notify); +void blk_add_remove_bs_notifier (BlockBackend *blk,Notifier *notify);void blk_io_plug (BlockBackend *blk);void blk_io_unplug (BlockBackend *blk);BlockAcctStats *blk_get_stats (BlockBackend *blk);
nbd.c +35 -0
@@ -964,9 +964,25 @@ static void blk_aio_detach(void *opaque) exp->ctx =NULL ; } +typedef struct NBDCloseNotifier { +Notifier n; +NBDExport *exp; +QTAILQ_ENTRY (NBDCloseNotifier) next; +}NBDCloseNotifier ; + +static QTAILQ_HEAD(, NBDCloseNotifier) eject_notifiers = +QTAILQ_HEAD_INITIALIZER (eject_notifiers); + +static void nbd_close_notifier (Notifier *n,void *data) +{ +NBDCloseNotifier *cn =DO_UPCAST (NBDCloseNotifier, n, n); +nbd_export_close (cn->exp); +} +NBDExport *nbd_export_new (BlockBackend *blk,off_t dev_offset,off_t size,uint32_t nbdflags,void (*close)(NBDExport *)) { +NBDCloseNotifier *eject_notifier =g_new0 (NBDCloseNotifier,1 );NBDExport *exp =g_malloc0 (sizeof (NBDExport)); exp->refcount =1 ;QTAILQ_INIT (&exp->clients);
@@ -978,6 +994,13 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size, exp->ctx =blk_get_aio_context (blk);blk_ref (blk);blk_add_aio_context_notifier (blk, blk_aio_attached, blk_aio_detach, exp); + + eject_notifier->n.notify = nbd_close_notifier; + eject_notifier->exp = exp; +QTAILQ_INSERT_TAIL (&eject_notifiers, eject_notifier, next); + +blk_add_remove_bs_notifier (blk, &eject_notifier->n); +/* * NBD exports are used for non-shared storage migration. Make sure * that BDRV_O_INCOMING is cleared and the image is ready for write
@@ -1022,6 +1045,7 @@ void nbd_export_set_name(NBDExport *exp, const char *name)void nbd_export_close (NBDExport *exp) { +NBDCloseNotifier *eject_notifier;NBDClient *client, *next;nbd_export_get (exp);
@@ -1031,6 +1055,17 @@ void nbd_export_close(NBDExport *exp)nbd_export_set_name (exp,NULL );nbd_export_put (exp);if (exp->blk) { + QTAILQ_FOREACH(eject_notifier, &eject_notifiers, next) { +if (eject_notifier->exp == exp) { +break ; + } + } +assert (eject_notifier); + +notifier_remove (&eject_notifier->n); +QTAILQ_REMOVE (&eject_notifiers, eject_notifier, next); +g_free (eject_notifier); +blk_remove_aio_context_notifier (exp->blk, blk_aio_attached, blk_aio_detach, exp);blk_unref (exp->blk);
Signature · 1 line
2.1.0
PATCH v2 2/22 iotests: Do not redirect qemu's stderr
In reply to Max ReitzRedirecting qemu's stderr to stdout makes working with the stderr output difficult due to the other file descriptor magic performed in _launch_qemu ("ambiguous redirect").
There is no harm in leaving stderr on stderr, so do it.
---
If someone has a better solution, especially regarding the redirection to a subshell here (test 091) and in the next patch, I'd be very grateful. All of my efforts to pipe the output of the _launch_qemu function resulted in said error ("ambiguous redirect"), so I had to keep it on stderr and I did not find another way to pipe stderr to another program.
--- tests/qemu-iotests/091 | 3 ++- tests/qemu-iotests/common.qemu | 1 - 2 files changed, 2 insertions(+), 2 deletions(-)
tests/qemu-iotests/091 +2 -1
@@ -68,7 +68,8 @@ echo echo === Starting QEMU VM2 === echo _launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},id=disk \ - -incoming "exec: cat '${MIG_FIFO}'" + -incoming "exec: cat '${MIG_FIFO}'" \ + 2> >(grep -v 'cat: write error') h2=$QEMU_HANDLE echo
tests/qemu-iotests/common.qemu +0 -1
@@ -155,7 +155,6 @@ function _launch_qemu() "${QEMU}" -nographic -serial none ${comm} -machine accel=qtest "${@}" \ >"${fifo_out}" \ - 2>&1 \ <"${fifo_in}" & QEMU_PID[${_QEMU_HANDLE}]=$!
Signature · 1 line
2.1.0
PATCH v2 3/22 iotests: Add test for eject under NBD server
In reply to Max ReitzThis patch adds a test for ejecting the BlockBackend an NBD server is connected to (the NBD server is supposed to stop).
--- tests/qemu-iotests/096 | 89 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/096.out | 16 +++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 106 insertions(+) create mode 100755 tests/qemu-iotests/096 create mode 100644 tests/qemu-iotests/096.out
tests/qemu-iotests/096 new file +89 -0
@@ -0,0 +1,89 @@ +#!/bin/bash +# +# Test case for ejecting a BB with an NBD server attached to it +# +# Copyright (C) 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.qemu + +_supported_fmt generic +_supported_proto file +_supported_os Linux + +_make_test_img 64k + +$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io + +_launch_qemu -drive if=ide,media=cdrom,id=drv,file="$TEST_IMG",format=$IMGFMT \ + 2> >(_filter_nbd) + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'qmp_capabilities' }" \ + 'return' + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'nbd-server-start', + 'arguments': { 'addr': { 'type': 'inet', + 'data': { 'host': '127.0.0.1', + 'port': '10809' }}}}" \ + 'return' + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'nbd-server-add', + 'arguments': { 'device': 'drv' }}" \ + 'return' + +$QEMU_IO_PROG -f raw -c 'read -P 42 0 64k' 'nbd://127.0.0.1:10809/drv' 2>&1 \ + | _filter_qemu_io | _filter_nbd + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'eject', + 'arguments': { 'device': 'drv' }}" \ + 'return' + +$QEMU_IO_PROG -f raw -c close 'nbd://127.0.0.1:10809/drv' 2>&1 \ + | _filter_qemu_io | _filter_nbd + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'quit' }" \ + 'return' + +wait=1 _cleanup_qemu + +# success, all done +echo '*** done' +rm -f $seq.full +status=0
tests/qemu-iotests/096.out new file +16 -0
@@ -0,0 +1,16 @@ +QA output created by 096 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536 +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +{"return": {}} +{"return": {}} +{"return": {}} +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "drv", "tray-open": true}} +{"return": {}} +qemu-io: can't open device nbd://127.0.0.1:PORT/drv: Failed to read export length +no file open, try 'help open' +{"return": {}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"} +*** done
tests/qemu-iotests/group +1 -0
@@ -101,6 +101,7 @@ 092 rw auto quick 094 rw auto quick 095 rw auto quick +096 rw auto quick 097 rw auto backing 098 rw auto backing quick 099 rw auto quick
Signature · 1 line
2.1.0
PATCH v2 8/22 block: Use blk_remove_bs() in blk_delete()
In reply to Max Reitz--- block/block-backend.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
block/block-backend.c +3 -6
@@ -167,12 +167,7 @@ static void blk_delete(BlockBackend *blk) {assert (!blk->refcnt);assert (!blk->dev); -if (blk->bs) { -assert (blk->bs->blk == blk); - blk->bs->blk =NULL ; -bdrv_unref (blk->bs); - blk->bs =NULL ; - } +blk_remove_bs (blk);/* Avoid double-remove after blk_hide_on_behalf_of_do_drive_del() */ if (blk->name[0 ]) {QTAILQ_REMOVE (&blk_backends, blk, link);
@@ -336,6 +331,8 @@ void blk_remove_bs(BlockBackend *blk)return ; } +assert (blk->bs->blk == blk); +notifier_list_notify (&blk->remove_bs_notifiers, blk);blk_update_root_state (blk);
Signature · 1 line
2.1.0
v2 cover block: Rework bdrv_close_all()
Currently, bdrv_close_all() force-closes all BDSs with a BlockBackend, which can lead to data corruption (see the iotest added in the final patch of this series) and is most certainly very ugly.
This series reworks bdrv_close_all() to notify all owners of a BlockBackend that they should release their reference (and additionally the monitor releases all its references to BB-less BDSs). This way, force-closing becomes unnecessary.
Also, blk_hide_on_behalf_of_do_drive_del() is removed. Yay!
This series depends on v2 of my series
"blockdev: BlockBackend and media" (or any later version), and on my series "nbd: Drop BDS backpointer" (on the patch "iotests: Add 'wait' functionality to _cleanup_qemu").
v2:
- Dropped old patches 1 (squashed into
"blockdev: BlockBackend and media") and 20 (put into
"nbd: Drop BDS backpointer")
- Patch 1: Added (required for patch 3)
- Patch 2: Added (required for patch 3); if someone has a better solution, I'd be very grateful
- Patch 3: Added a test which ensures that if the BDS an NBD server is attached to through a BB is ejected, that NBD server is stopped
- Patch 5: Replaces the old patch 5 (which removed the BDS close notifiers completely); as pointed out by Paolo, we do need the notifiers as eject notifiers for NBD, so this patch replaces the per-BDS close notifiers by an eject notifier for the BB which is called whenever blk_remove_bs() is called and removes a BDS tree from the BB
- Patch 7: Fixed up to fit onto patch 5
- Patch 11: s/namespaces/namespace/ [Eric]
- Patch 14: Rebase conflict due to the new bdrv_add_key() function
git-backport-diff against v1:
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/22:[down] 'iotests: Move _filter_nbd into common.filter' 002/22:[down] 'iotests: Do not redirect qemu's stderr' 003/22:[down] 'iotests: Add test for eject under NBD server' 004/22:[----] [-C] 'quorum: Fix close path'
005/22:[down] 'block: Move BDS close notifiers into BB' 006/22:[----] [--] 'block: Add bdrv_close_all() notifiers' 007/22:[0075] [FC] 'block: Add bdrv_close_all() handlers' 008/22:[----] [-C] 'block: Use blk_remove_bs() in blk_delete()' 009/22:[----] [--] 'blockdev: Use blk_remove_bs() in do_drive_del()' 010/22:[----] [--] 'block: Make bdrv_close() static'
011/22:[0002] [FC] 'block: Add blk_name_taken()'
012/22:[----] [--] 'block: Add blk_next_inserted()'
013/22:[----] [--] 'block: Add blk_commit_all() and blk_invalidate_cache_all()' 014/22:[0009] [FC] 'block: Use BlockBackend more'
015/22:[----] [--] 'blockdev: Add list of monitor-owned BlockBackends' 016/22:[----] [--] 'blockdev: Remove blk_hide_on_behalf_of_do_drive_del()' 017/22:[----] [--] 'block: Make bdrv_drain_one() public' 018/22:[----] [-C] 'block: Move some bdrv_*_all() functions to BB' 019/22:[----] [--] 'block: Remove bdrv_states'
020/22:[----] [--] 'blockdev: Keep track of monitor-owned BDS' 021/22:[----] [--] 'block: Strip down bdrv_close_all()' 022/22:[----] [--] 'iotests: Add test for multiple BB on BDS tree'
Max Reitz (22):
iotests: Move _filter_nbd into common.filter
iotests: Do not redirect qemu's stderr
iotests: Add test for eject under NBD server
quorum: Fix close path
block: Move BDS close notifiers into BB
block: Add bdrv_close_all() notifiers
block: Add bdrv_close_all() handlers
block: Use blk_remove_bs() in blk_delete()
blockdev: Use blk_remove_bs() in do_drive_del()
block: Make bdrv_close() static
block: Add blk_name_taken()
block: Add blk_next_inserted()
block: Add blk_commit_all() and blk_invalidate_cache_all()
block: Use BlockBackend more
blockdev: Add list of monitor-owned BlockBackends
blockdev: Remove blk_hide_on_behalf_of_do_drive_del()
block: Make bdrv_drain_one() public
block: Move some bdrv_*_all() functions to BB
block: Remove bdrv_states
blockdev: Keep track of monitor-owned BDS
block: Strip down bdrv_close_all()
iotests: Add test for multiple BB on BDS tree
block.c | 168 ++++------------------ block/block-backend.c | 301 +++++++++++++++++++++++++++++++-------- block/qapi.c | 13 +- block/quorum.c | 3 +- block/snapshot.c | 3 +- blockdev-nbd.c | 36 +---- blockdev.c | 121 +++++++++++++--- cpus.c | 7 +- device-hotplug.c | 2 +- hw/block/xen_disk.c | 16 ++- hw/ide/piix.c | 1 - include/block/block.h | 9 +- include/block/block_int.h | 8 +- include/sysemu/block-backend.h | 24 ++-- include/sysemu/blockdev.h | 3 + migration/block.c | 10 +- migration/migration.c | 4 +- monitor.c | 13 +- nbd.c | 59 +++++++- qemu-char.c | 3 +- qemu-img.c | 39 ++--- qemu-io.c | 8 +- qemu-nbd.c | 6 +- qmp.c | 9 +- savevm.c | 66 +++++---- stubs/Makefile.objs | 2 +- stubs/bdrv-commit-all.c | 7 - stubs/blk-commit-all.c | 7 + tests/qemu-iotests/083 | 13 +- tests/qemu-iotests/083.out | 10 -- tests/qemu-iotests/091 | 3 +- tests/qemu-iotests/096 | 89 ++++++++++++ tests/qemu-iotests/096.out | 16 +++ tests/qemu-iotests/117 | 86 +++++++++++ tests/qemu-iotests/117.out | 14 ++ tests/qemu-iotests/common.filter | 12 ++ tests/qemu-iotests/common.qemu | 1 - tests/qemu-iotests/group | 2 + xen-mapcache.c | 3 +- 39 files changed, 807 insertions(+), 390 deletions(-) delete mode 100644 stubs/bdrv-commit-all.c create mode 100644 stubs/blk-commit-all.c create mode 100755 tests/qemu-iotests/096 create mode 100644 tests/qemu-iotests/096.out create mode 100755 tests/qemu-iotests/117 create mode 100644 tests/qemu-iotests/117.out
Signature · 1 line
2.1.0
PATCH v2 4/22 quorum: Fix close path
bdrv_unref() can lead to bdrv_close(), which in turn will result in bdrv_drain_all(). This function will later be called blk_drain_all() and iterate only over the BlockBackends for which blk_is_inserted() holds true; therefore, bdrv_is_inserted() and thus quorum_is_inserted() will probably be called.
This patch makes quorum_is_inserted() aware of the fact that some children may have been closed already.
--- block/quorum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/quorum.c +2 -1
@@ -1005,6 +1005,7 @@ static void quorum_close(BlockDriverState *bs)for (i =0 ; i < s->num_children; i++) {bdrv_unref (s->bs[i]); + s->bs[i] =NULL ; }g_free (s->bs);
@@ -1070,7 +1071,7 @@ static bool quorum_is_inserted(BlockDriverState *bs)int i;for (i =0 ; i < s->num_children; i++) { -if (!bdrv_is_inserted (s->bs[i])) { +if (s->bs[i] && !bdrv_is_inserted (s->bs[i])) {return false; } }
Signature · 1 line
2.1.0
PATCH v2 9/22 blockdev: Use blk_remove_bs() in do_drive_del()
In reply to Max Reitz--- blockdev.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
blockdev.c +1 -5
@@ -2281,11 +2281,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) }/* quiesce block driver; prevent further io */ -bdrv_drain_all (); -if (bs) { -bdrv_flush (bs); -bdrv_close (bs); - } +blk_remove_bs (blk);/* if we have a device attached to this BlockDriverState * then we need to make the drive anonymous until the device
Signature · 1 line
2.1.0
PATCH v2 10/22 block: Make bdrv_close() static
In reply to Max ReitzThere are no users of bdrv_close() left, except for one of bdrv_open()'s failure paths, bdrv_close_all() and bdrv_delete(), and that is good. Make bdrv_close() static so nobody makes the mistake of directly using bdrv_close() again.
--- block.c | 4 +++- include/block/block.h | 1 - 2 files changed, 3 insertions(+), 2 deletions(-)
block.c +3 -1
@@ -107,6 +107,8 @@ static int use_bdrv_whitelist;static NotifierList close_all_notifiers =NOTIFIER_LIST_INITIALIZER (close_all_notifiers); +static void bdrv_close (BlockDriverState *bs); +#ifdef _WIN32static int is_windows_drive_prefix (const char *filename) {
@@ -1851,7 +1853,7 @@ void bdrv_reopen_abort(BDRVReopenState *reopen_state) } -void bdrv_close (BlockDriverState *bs) +static void bdrv_close (BlockDriverState *bs) {BdrvAioNotifier *ban, *ban_next;
include/block/block.h +0 -1
@@ -195,7 +195,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp);void bdrv_reopen_commit (BDRVReopenState *reopen_state);void bdrv_reopen_abort (BDRVReopenState *reopen_state); -void bdrv_close (BlockDriverState *bs);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors); int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
Signature · 1 line
2.1.0
PATCH v2 7/22 block: Add bdrv_close_all() handlers
In reply to Max ReitzEvery time a reference to a BlockBackend is taken, a notifier for bdrv_close_all() has to be deposited so the reference holder can relinquish its reference when bdrv_close_all() is called. That notifier should be revoked on a bdrv_unref() call.
Add a Notifier * parameter to all the functions changing the reference count of a BlockBackend: blk_new(), blk_new_with_bs(), blk_new_open(), blk_ref() and blk_unref().
By dropping the manual reference handling in hw/block/xen_disk.c, the blk_unref() in hw/ide/piix.c can be dropped as well.
--- block/block-backend.c | 69 ++++++++++++++++++++++++++++++++++++------ blockdev.c | 62 ++++++++++++++++++++++++++++++++++--- device-hotplug.c | 2 +- hw/block/xen_disk.c | 16 +++++++--- hw/ide/piix.c | 1 - include/sysemu/block-backend.h | 13 +++++--- include/sysemu/blockdev.h | 3 ++ nbd.c | 26 ++++++++++++++-- qemu-img.c | 39 ++++++++++++------------ qemu-io.c | 6 ++-- qemu-nbd.c | 6 ++-- 11 files changed, 189 insertions(+), 54 deletions(-)
block/block-backend.c +59 -10
@@ -76,7 +76,8 @@ static QTAILQ_HEAD(, BlockBackend) blk_backends =* Store an error through @errp on failure, unless it's null. * Return the new BlockBackend on success, null on failure. */ -BlockBackend *blk_new (const char *name,Error **errp) +BlockBackend *blk_new (const char *name,Notifier *close_all_notifier, +Error **errp) {BlockBackend *blk;
@@ -100,6 +101,9 @@ BlockBackend *blk_new(const char *name, Error **errp) blk->name =g_strdup (name); blk->refcnt =1 ;notifier_list_init (&blk->remove_bs_notifiers); +if (close_all_notifier) { +bdrv_add_close_all_notifier (close_all_notifier); + }QTAILQ_INSERT_TAIL (&blk_backends, blk, link);return blk; }
@@ -108,12 +112,13 @@ BlockBackend *blk_new(const char *name, Error **errp)* Create a new BlockBackend with a new BlockDriverState attached. * Otherwise just like blk_new(), which see. */ -BlockBackend *blk_new_with_bs (const char *name,Error **errp) +BlockBackend *blk_new_with_bs (const char *name,Notifier *close_all_notifier, +Error **errp) {BlockBackend *blk;BlockDriverState *bs; - blk =blk_new (name, errp); + blk =blk_new (name, close_all_notifier, errp);if (!blk) {return NULL ; }
@@ -138,12 +143,12 @@ BlockBackend *blk_new_with_bs(const char *name, Error **errp)*/ BlockBackend *blk_new_open (const char *name,const char *filename,const char *reference,QDict *options,int flags, -Error **errp) +Notifier *close_all_notifier,Error **errp) {BlockBackend *blk;int ret; - blk =blk_new_with_bs (name, errp); + blk =blk_new_with_bs (name, close_all_notifier, errp);if (!blk) {QDECREF (options);return NULL ;
@@ -151,7 +156,7 @@ BlockBackend *blk_new_open(const char *name, const char *filename, ret =bdrv_open (&blk->bs, filename, reference, options, flags,NULL , errp);if (ret <0 ) { -blk_unref (blk); +blk_unref (blk, close_all_notifier);return NULL ; }
@@ -191,9 +196,13 @@ static void drive_info_del(DriveInfo *dinfo)* Increment @blk's reference count. * @blk must not be null. */ -void blk_ref (BlockBackend *blk) +void blk_ref (BlockBackend *blk,Notifier *close_all_notifier) { blk->refcnt++; + +if (close_all_notifier) { +bdrv_add_close_all_notifier (close_all_notifier); + } }/*
@@ -201,8 +210,12 @@ void blk_ref(BlockBackend *blk)* If this drops it to zero, destroy @blk. * For convenience, do nothing if @blk is null. */ -void blk_unref (BlockBackend *blk) +void blk_unref (BlockBackend *blk,Notifier *close_all_notifier) { +if (close_all_notifier) { +notifier_remove (close_all_notifier); + } +if (blk) {assert (blk->refcnt >0 );if (!--blk->refcnt) {
@@ -352,6 +365,21 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) bs->blk = blk; } +typedef struct DevCloseAllNotifier { +Notifier n; +BlockBackend *blk; +QTAILQ_ENTRY (DevCloseAllNotifier) next; +}DevCloseAllNotifier ; + +static QTAILQ_HEAD(, DevCloseAllNotifier) close_all_notifiers = +QTAILQ_HEAD_INITIALIZER (close_all_notifiers); + +static void dev_close_all_notifier (Notifier *n,void *data) +{ +DevCloseAllNotifier *can =DO_UPCAST (DevCloseAllNotifier, n, n); +blk_detach_dev (can->blk, can->blk->dev); +} +/* * Attach device model @dev to @blk. * Return 0 on success, -EBUSY when a device model is attached already.
@@ -359,10 +387,19 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)int blk_attach_dev (BlockBackend *blk,void *dev)/* TODO change to DeviceState *dev when all users are qdevified */ { +DevCloseAllNotifier *can; +if (blk->dev) {return -EBUSY ; } -blk_ref (blk); + + can =g_new0 (DevCloseAllNotifier,1 ); + can->n.notify = dev_close_all_notifier; + can->blk = blk; + +QTAILQ_INSERT_TAIL (&close_all_notifiers, can, next); + +blk_ref (blk, &can->n); blk->dev = dev;blk_iostatus_reset (blk);return 0 ;
@@ -387,12 +424,24 @@ void blk_attach_dev_nofail(BlockBackend *blk, void *dev)void blk_detach_dev (BlockBackend *blk,void *dev)/* TODO change to DeviceState *dev when all users are qdevified */ { +DevCloseAllNotifier *can; +assert (blk->dev == dev); blk->dev =NULL ; blk->dev_ops =NULL ; blk->dev_opaque =NULL ; blk->guest_block_size =512 ; -blk_unref (blk); + + QTAILQ_FOREACH(can, &close_all_notifiers, next) { +if (can->blk == blk) { +break ; + } + } +assert (can); + +blk_unref (blk, &can->n); +QTAILQ_REMOVE (&close_all_notifiers, can, next); +g_free (can); }/*
blockdev.c +57 -5
122 lines not on this page · raw message
device-hotplug.c +1 -1
@@ -77,6 +77,6 @@ void drive_hot_add(Monitor *mon, const QDict *qdict) err:if (dinfo) { -blk_unref (blk_by_legacy_dinfo (dinfo)); +monitor_blk_unref (blk_by_legacy_dinfo (dinfo)); } }
hw/block/xen_disk.c +11 -5
@@ -908,8 +908,10 @@ static int blk_connect(struct XenDevice *xendev)/* setup via xenbus -> create new block driver instance */ xen_be_printf (&blkdev->xendev,2 ,"create new bdrv (xenbus setup)\n" ); +/* No need to give a close_all_notifier because blk_attach_dev_nofail() +* and blk_detach_dev() will keep track of our reference */ blkdev->blk =blk_new_open (blkdev->dev, blkdev->filename,NULL , options, - qflags, &local_err); + qflags,NULL , &local_err);if (!blkdev->blk) {xen_be_printf (&blkdev->xendev,0 ,"error: %s\n" ,error_get_pretty (local_err));
@@ -925,11 +927,16 @@ static int blk_connect(struct XenDevice *xendev) blkdev->blk =NULL ;return -1 ; } -/* blkdev->blk is not create by us, we get a reference -* so we can blk_unref() unconditionally */ -blk_ref (blkdev->blk); } +blk_attach_dev_nofail (blkdev->blk, blkdev); +if (!blkdev->dinfo) { +/* blkdev->blk has just been created; blk_attach_dev_nofail() counts +* the reference blkdev->blk, so we do not have to keep track (which +* allows us to ignore bdrv_close_all()) */ +blk_unref (blkdev->blk,NULL ); + } + blkdev->file_size =blk_getlength (blkdev->blk);if (blkdev->file_size <0 ) {BlockDriverState *bs =blk_bs (blkdev->blk);
@@ -1032,7 +1039,6 @@ static void blk_disconnect(struct XenDevice *xendev)if (blkdev->blk) {blk_detach_dev (blkdev->blk, blkdev); -blk_unref (blkdev->blk); blkdev->blk =NULL ; }xen_be_unbind_evtchn (&blkdev->xendev);
hw/ide/piix.c +0 -1
@@ -184,7 +184,6 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev)blk_detach_dev (blk, ds); } pci_ide->bus[di->bus].ifs[di->unit].blk =NULL ; -blk_unref (blk); } }qdev_reset_all (DEVICE (dev));
include/sysemu/block-backend.h +8 -5
@@ -13,6 +13,7 @@#ifndef BLOCK_BACKEND_H #define BLOCK_BACKEND_H +#include "qemu/notify.h" #include "qemu/typedefs.h" #include "qapi/error.h"
@@ -60,13 +61,15 @@ typedef struct BlockDevOps {void (*resize_cb)(void *opaque); } BlockDevOps; -BlockBackend *blk_new (const char *name,Error **errp); -BlockBackend *blk_new_with_bs (const char *name,Error **errp); +BlockBackend *blk_new (const char *name,Notifier *close_all_notifier, +Error **errp); +BlockBackend *blk_new_with_bs (const char *name,Notifier *close_all_notifier, +Error **errp);BlockBackend *blk_new_open (const char *name,const char *filename,const char *reference,QDict *options,int flags, -Error **errp); -void blk_ref (BlockBackend *blk); -void blk_unref (BlockBackend *blk); +Notifier *close_all_notifier,Error **errp); +void blk_ref (BlockBackend *blk,Notifier *close_all_notifier); +void blk_unref (BlockBackend *blk,Notifier *close_all_notifier);const char *blk_name (BlockBackend *blk);BlockBackend *blk_by_name (const char *name);BlockBackend *blk_next (BlockBackend *blk);
include/sysemu/blockdev.h +3 -0
@@ -67,4 +67,7 @@ DriveInfo *add_init_drive(const char *opts);void do_commit (Monitor *mon,const QDict *qdict);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data); + +void monitor_blk_unref (BlockBackend *blk); +#endif
nbd.c +23 -3
@@ -973,6 +973,9 @@ typedef struct NBDCloseNotifier { static QTAILQ_HEAD(, NBDCloseNotifier) eject_notifiers =QTAILQ_HEAD_INITIALIZER (eject_notifiers); +static QTAILQ_HEAD(, NBDCloseNotifier) close_notifiers = +QTAILQ_HEAD_INITIALIZER (close_notifiers); +static void nbd_close_notifier (Notifier *n,void *data) {NBDCloseNotifier *cn =DO_UPCAST (NBDCloseNotifier, n, n);
@@ -983,6 +986,7 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size, uint32_t nbdflags, void (*close)(NBDExport *)) { NBDCloseNotifier *eject_notifier = g_new0(NBDCloseNotifier, 1); +NBDCloseNotifier *close_notifier =g_new0 (NBDCloseNotifier,1 );NBDExport *exp =g_malloc0 (sizeof (NBDExport)); exp->refcount =1 ;QTAILQ_INIT (&exp->clients);
@@ -992,7 +996,12 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size, exp->size = size ==-1 ?blk_getlength (blk) : size; exp->close = close; exp->ctx =blk_get_aio_context (blk); -blk_ref (blk); + + close_notifier->n.notify = nbd_close_notifier; + close_notifier->exp = exp; +QTAILQ_INSERT_TAIL (&close_notifiers, close_notifier, next); + +blk_ref (blk, &close_notifier->n);blk_add_aio_context_notifier (blk, blk_aio_attached, blk_aio_detach, exp); eject_notifier->n.notify = nbd_close_notifier;
@@ -1045,7 +1054,7 @@ void nbd_export_set_name(NBDExport *exp, const char *name)void nbd_export_close (NBDExport *exp) { -NBDCloseNotifier *eject_notifier; +NBDCloseNotifier *eject_notifier, *close_notifier;NBDClient *client, *next;nbd_export_get (exp);
@@ -1054,6 +1063,7 @@ void nbd_export_close(NBDExport *exp) }nbd_export_set_name (exp,NULL );nbd_export_put (exp); +if (exp->blk) { QTAILQ_FOREACH(eject_notifier, &eject_notifiers, next) {if (eject_notifier->exp == exp) {
@@ -1066,10 +1076,20 @@ void nbd_export_close(NBDExport *exp)QTAILQ_REMOVE (&eject_notifiers, eject_notifier, next);g_free (eject_notifier); + QTAILQ_FOREACH(close_notifier, &close_notifiers, next) { +if (close_notifier->exp == exp) { +break ; + } + } +assert (close_notifier); +blk_remove_aio_context_notifier (exp->blk, blk_aio_attached, blk_aio_detach, exp); -blk_unref (exp->blk); +blk_unref (exp->blk, &close_notifier->n); exp->blk =NULL ; + +QTAILQ_REMOVE (&close_notifiers, close_notifier, next); +g_free (close_notifier); } }
qemu-img.c +20 -19
@@ -302,7 +302,7 @@ static BlockBackend *img_open(const char *id, const char *filename,qdict_put (options,"driver" ,qstring_from_str (fmt)); } - blk =blk_new_open (id, filename,NULL , options, flags, &local_err); + blk =blk_new_open (id, filename,NULL , options, flags,NULL , &local_err);if (!blk) {error_report ("Could not open '%s': %s" , filename,error_get_pretty (local_err));
@@ -324,7 +324,7 @@ static BlockBackend *img_open(const char *id, const char *filename, }return blk; fail: -blk_unref (blk); +blk_unref (blk,NULL );return NULL ; }
@@ -713,7 +713,7 @@ static int img_check(int argc, char **argv) fail:qapi_free_ImageCheck (check); -blk_unref (blk); +blk_unref (blk,NULL );return ret; }
@@ -880,7 +880,7 @@ unref_backing: done:qemu_progress_end (); -blk_unref (blk); +blk_unref (blk,NULL );if (local_err) {qerror_report_err (local_err);
@@ -1292,9 +1292,9 @@ static int img_compare(int argc, char **argv) out:qemu_vfree (buf1);qemu_vfree (buf2); -blk_unref (blk2); +blk_unref (blk2,NULL ); out2: -blk_unref (blk1); +blk_unref (blk1,NULL ); out3:qemu_progress_end ();return ret;
@@ -1862,11 +1862,11 @@ out:qemu_opts_free (create_opts);qemu_vfree (buf);qemu_opts_del (sn_opts); -blk_unref (out_blk); +blk_unref (out_blk,NULL );g_free (bs);if (blk) {for (bs_i =0 ; bs_i < bs_n; bs_i++) { -blk_unref (blk[bs_i]); +blk_unref (blk[bs_i],NULL ); }g_free (blk); }
@@ -2001,7 +2001,7 @@ static ImageInfoList *collect_image_info_list(const char *filename,if (err) {error_report ("%s" ,error_get_pretty (err));error_free (err); -blk_unref (blk); +blk_unref (blk,NULL ); goto err; }
@@ -2010,7 +2010,7 @@ static ImageInfoList *collect_image_info_list(const char *filename, *last = elem; last = &elem->next; -blk_unref (blk); +blk_unref (blk,NULL ); filename = fmt =NULL ;if (chain) {
@@ -2298,7 +2298,7 @@ static int img_map(int argc, char **argv)dump_map_entry (output_format, &curr,NULL ); out: -blk_unref (blk); +blk_unref (blk,NULL );return ret <0 ; }
@@ -2422,7 +2422,7 @@ static int img_snapshot(int argc, char **argv) }/* Cleanup */ -blk_unref (blk); +blk_unref (blk,NULL );if (ret) {return 1 ; }
@@ -2546,7 +2546,7 @@ static int img_rebase(int argc, char **argv)bdrv_get_backing_filename (bs, backing_name,sizeof (backing_name)); blk_old_backing =blk_new_open ("old_backing" , backing_name,NULL , - options, src_flags, &local_err); + options, src_flags,NULL , &local_err);if (!blk_old_backing) {error_report ("Could not open old backing file '%s': %s" , backing_name,error_get_pretty (local_err));
@@ -2563,7 +2563,8 @@ static int img_rebase(int argc, char **argv) } blk_new_backing =blk_new_open ("new_backing" , out_baseimg,NULL , - options, src_flags, &local_err); + options, src_flags,NULL , + &local_err);if (!blk_new_backing) {error_report ("Could not open new backing file '%s': %s" , out_baseimg,error_get_pretty (local_err));
@@ -2736,11 +2737,11 @@ out:qemu_progress_end ();/* Cleanup */ if (!unsafe) { -blk_unref (blk_old_backing); -blk_unref (blk_new_backing); +blk_unref (blk_old_backing,NULL ); +blk_unref (blk_new_backing,NULL ); } -blk_unref (blk); +blk_unref (blk,NULL );if (ret) {return 1 ; }
@@ -2863,7 +2864,7 @@ static int img_resize(int argc, char **argv)break ; } out: -blk_unref (blk); +blk_unref (blk,NULL );if (ret) {return 1 ; }
@@ -3001,7 +3002,7 @@ static int img_amend(int argc, char **argv) out:qemu_progress_end (); -blk_unref (blk); +blk_unref (blk,NULL );qemu_opts_del (opts);qemu_opts_free (create_opts);g_free (options);
qemu-io.c +3 -3
@@ -37,7 +37,7 @@ static ReadLineState *readline_state;static int close_f (BlockBackend *blk,int argc,char **argv) { -blk_unref (qemuio_blk); +blk_unref (qemuio_blk,NULL ); qemuio_blk =NULL ;return 0 ; }
@@ -59,7 +59,7 @@ static int openfile(char *name, int flags, QDict *opts)return 1 ; } - qemuio_blk =blk_new_open ("hda" , name,NULL , opts, flags, &local_err); + qemuio_blk =blk_new_open ("hda" , name,NULL , opts, flags,NULL , &local_err);if (!qemuio_blk) { fprintf(stderr, "%s: can't open%s%s: %s\n", progname, name ? " device " : "", name ?: "",
@@ -474,7 +474,7 @@ int main(int argc, char **argv)*/ bdrv_drain_all (); -blk_unref (qemuio_blk); +blk_unref (qemuio_blk,NULL );g_free (readline_state);return 0 ; }
qemu-nbd.c +4 -2
@@ -694,7 +694,8 @@ int main(int argc, char **argv) } srcpath = argv[optind]; - blk =blk_new_open ("hda" , srcpath,NULL , options, flags, &local_err); +/* the reference will be passed on nbd_export_new() */ + blk =blk_new_open ("hda" , srcpath,NULL , options, flags,NULL , &local_err);if (!blk) {errx (EXIT_FAILURE ,"Failed to blk_new_open '%s': %s" , argv[optind],error_get_pretty (local_err));
@@ -728,7 +729,9 @@ int main(int argc, char **argv) } } +/* nbd_export_new() takes the reference to blk */ exp =nbd_export_new (blk, dev_offset, fd_size, nbdflags, nbd_export_closed); +blk_unref (blk,NULL );if (sockpath) { fd =unix_socket_incoming (sockpath);
@@ -773,7 +776,6 @@ int main(int argc, char **argv) } }while (state !=TERMINATED ); -blk_unref (blk);if (sockpath) {unlink (sockpath); }
Signature · 1 line
2.1.0
PATCH v2 6/22 block: Add bdrv_close_all() notifiers
In reply to Max ReitzThis adds a list of notifiers to be invoked on bdrv_close_all().
--- block.c | 10 ++++++++++ include/block/block.h | 2 ++ 2 files changed, 12 insertions(+)
block.c +10 -0
@@ -104,6 +104,9 @@ static void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; +static NotifierList close_all_notifiers = +NOTIFIER_LIST_INITIALIZER (close_all_notifiers); +#ifdef _WIN32static int is_windows_drive_prefix (const char *filename) {
@@ -1907,6 +1910,8 @@ void bdrv_close_all(void) {BlockDriverState *bs; +notifier_list_notify (&close_all_notifiers,NULL ); + QTAILQ_FOREACH(bs, &bdrv_states, device_list) {AioContext *aio_context =bdrv_get_aio_context (bs);
@@ -1916,6 +1921,11 @@ void bdrv_close_all(void) } } +void bdrv_add_close_all_notifier (Notifier *notifier) +{ +notifier_list_add (&close_all_notifiers, notifier); +} +/* Check if any requests are in-flight (including throttled requests) */ static bool bdrv_requests_pending (BlockDriverState *bs) {
include/block/block.h +2 -0
@@ -543,4 +543,6 @@ void bdrv_io_plug(BlockDriverState *bs);void bdrv_io_unplug (BlockDriverState *bs);void bdrv_flush_io_queue (BlockDriverState *bs); +void bdrv_add_close_all_notifier (Notifier *notifier); +#endif
Signature · 1 line
2.1.0
PATCH v2 11/22 block: Add blk_name_taken()
In reply to Max ReitzThere may be BlockBackends which are not returned by blk_by_name(), but do exist and have a name. blk_name_taken() allows testing whether a specific name is in use already, independent of whether the BlockBackend with that name is accessible through blk_by_name().
--- block.c | 4 ++-- block/block-backend.c | 19 ++++++++++++++++++- include/sysemu/block-backend.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-)
block.c +2 -2
@@ -899,8 +899,8 @@ static void bdrv_assign_node_name(BlockDriverState *bs,return ; } -/* takes care of avoiding namespaces collisions */ -if (blk_by_name (node_name)) { +/* takes care of avoiding namespace collisions */ +if (blk_name_taken (node_name)) {error_setg (errp,"node-name=%s is conflicting with a device id" , node_name);return ;
block/block-backend.c +18 -1
@@ -86,7 +86,7 @@ BlockBackend *blk_new(const char *name, Notifier *close_all_notifier,error_setg (errp,"Invalid device name" );return NULL ; } -if (blk_by_name (name)) { +if (blk_name_taken (name)) {error_setg (errp,"Device with id '%s' already exists" , name);return NULL ; }
@@ -262,6 +262,23 @@ BlockBackend *blk_by_name(const char *name) }/* +* This function should be used to check whether a certain BlockBackend name is +* already taken; blk_by_name() will only search in the list of monitor-owned +* BlockBackends which is not necessarily complete. +*/ +bool blk_name_taken (const char *name) +{ +BlockBackend *blk; + + QTAILQ_FOREACH(blk, &blk_backends, link) { +if (!strcmp (name, blk->name)) { +return true; + } + } +return false; +} + +/* * Return the BlockDriverState attached to @blk if any, else null. */ BlockDriverState *blk_bs (BlockBackend *blk)
include/sysemu/block-backend.h +1 -0
@@ -72,6 +72,7 @@ void blk_ref(BlockBackend *blk, Notifier *close_all_notifier);void blk_unref (BlockBackend *blk,Notifier *close_all_notifier);const char *blk_name (BlockBackend *blk);BlockBackend *blk_by_name (const char *name); +bool blk_name_taken (const char *name);BlockBackend *blk_next (BlockBackend *blk);BlockDriverState *blk_bs (BlockBackend *blk);
Signature · 1 line
2.1.0
PATCH v2 12/22 block: Add blk_next_inserted()
In reply to Max ReitzThis function skips to the next BlockBackend for which blk_is_inserted() is true.
--- block/block-backend.c | 15 +++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 16 insertions(+)
block/block-backend.c +15 -0
@@ -235,6 +235,21 @@ BlockBackend *blk_next(BlockBackend *blk) }/* +* Like blk_next(), but skips all non-inserted BlockBackends (that is, +* BlockBackends for which blk_is_inserted() returns false) +*/ +BlockBackend *blk_next_inserted (BlockBackend *blk) +{ +while ((blk =blk_next (blk)) !=NULL ) { +if (blk_is_inserted (blk)) { +break ; + } + } + +return blk; +} + +/* * Return @blk's name, a non-null string. * Wart: the name is empty iff @blk has been hidden with * blk_hide_on_behalf_of_do_drive_del().
include/sysemu/block-backend.h +1 -0
@@ -74,6 +74,7 @@ const char *blk_name(BlockBackend *blk);BlockBackend *blk_by_name (const char *name);bool blk_name_taken (const char *name);BlockBackend *blk_next (BlockBackend *blk); +BlockBackend *blk_next_inserted (BlockBackend *blk);BlockDriverState *blk_bs (BlockBackend *blk);void blk_remove_bs (BlockBackend *blk);
Signature · 1 line
2.1.0
PATCH v2 14/22 block: Use BlockBackend more
In reply to Max ReitzReplace bdrv_drain_all(), bdrv_commmit_all(), bdrv_flush_all(), bdrv_invalidate_cache_all(), bdrv_next() and occurrences of bdrv_states by their BlockBackend equivalents.
--- block.c | 22 ++++++++--------- block/block-backend.c | 8 +++---- block/qapi.c | 13 ++++++++-- block/snapshot.c | 3 ++- blockdev.c | 14 ++++++----- cpus.c | 7 +++--- migration/block.c | 10 +++++--- migration/migration.c | 4 ++-- monitor.c | 13 ++++++---- qemu-char.c | 3 ++- qemu-io.c | 2 +- qmp.c | 9 ++++--- savevm.c | 66 ++++++++++++++++++++++++++++++--------------------- xen-mapcache.c | 3 ++- 14 files changed, 105 insertions(+), 72 deletions(-)
block.c +11 -11
@@ -1690,7 +1690,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)assert (bs_queue !=NULL ); -bdrv_drain_all (); +blk_drain_all (); QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {if (bdrv_reopen_prepare (&bs_entry->state, bs_queue, &local_err)) {
@@ -1860,9 +1860,9 @@ static void bdrv_close(BlockDriverState *bs)if (bs->job) {block_job_cancel_sync (bs->job); } -bdrv_drain_all ();/* complete I/O */ +blk_drain_all ();/* complete I/O */ bdrv_flush (bs); -bdrv_drain_all ();/* in case flush left pending I/O */ +blk_drain_all ();/* in case flush left pending I/O */ if (bs->drv) {if (bs->backing_hd) {
@@ -1910,15 +1910,15 @@ static void bdrv_close(BlockDriverState *bs)void bdrv_close_all (void ) { -BlockDriverState *bs; +BlockBackend *blk =NULL ;notifier_list_notify (&close_all_notifiers,NULL ); - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { -AioContext *aio_context =bdrv_get_aio_context (bs); +while ((blk =blk_next_inserted (blk)) !=NULL ) { +AioContext *aio_context =blk_get_aio_context (blk);aio_context_acquire (aio_context); -bdrv_close (bs); +bdrv_close (blk_bs (blk));aio_context_release (aio_context); } }
@@ -5718,7 +5718,7 @@ void bdrv_attach_aio_context(BlockDriverState *bs,void bdrv_set_aio_context (BlockDriverState *bs,AioContext *new_context) { -bdrv_drain_all ();/* ensure there are no in-flight requests */ +blk_drain_all ();/* ensure there are no in-flight requests */ bdrv_detach_aio_context (bs);
@@ -5821,14 +5821,14 @@ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,*/ bool bdrv_is_first_non_filter (BlockDriverState *candidate) { -BlockDriverState *bs; +BlockBackend *blk =NULL ;/* walk down the bs forest recursively */ - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { +while ((blk =blk_next_inserted (blk)) !=NULL ) {bool perm;/* try to recurse in this top level bs */ - perm =bdrv_recurse_is_first_non_filter (bs, candidate); + perm =bdrv_recurse_is_first_non_filter (blk_bs (blk), candidate);/* candidate is the first non filter */ if (perm) {
block/block-backend.c +4 -4
@@ -265,10 +265,10 @@ const char *blk_name(BlockBackend *blk)*/ BlockBackend *blk_by_name (const char *name) { -BlockBackend *blk; +BlockBackend *blk =NULL ;assert (name); - QTAILQ_FOREACH(blk, &blk_backends, link) { +while ((blk =blk_next (blk)) !=NULL ) {if (!strcmp (name, blk->name)) {return blk; }
@@ -326,9 +326,9 @@ DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo)*/ BlockBackend *blk_by_legacy_dinfo (DriveInfo *dinfo) { -BlockBackend *blk; +BlockBackend *blk =NULL ; - QTAILQ_FOREACH(blk, &blk_backends, link) { +while ((blk =blk_next (blk)) !=NULL ) {if (blk->legacy_dinfo == dinfo) {return blk; }
block/qapi.c +11 -2
@@ -395,15 +395,24 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes, {BlockStatsList *head =NULL , **p_next = &head;BlockDriverState *bs =NULL ; +BlockBackend *blk =NULL ;/* Just to be safe if query_nodes is not always initialized */ query_nodes = has_query_nodes && query_nodes; -while ((bs = query_nodes ?bdrv_next_node (bs) :bdrv_next (bs))) { +while (query_nodes ? (bs =bdrv_next_node (bs)) !=NULL + : (blk =blk_next_inserted (blk)) !=NULL ) + {BlockStatsList *info =g_malloc0 (sizeof (*info)); -AioContext *ctx =bdrv_get_aio_context (bs); +AioContext *ctx = blk ?blk_get_aio_context (blk) + :bdrv_get_aio_context (bs);aio_context_acquire (ctx); + +if (blk) { + bs =blk_bs (blk); + } + info->value =bdrv_query_stats (bs, !query_nodes);aio_context_release (ctx);
block/snapshot.c +2 -1
@@ -24,6 +24,7 @@#include "block/snapshot.h" #include "block/block_int.h" +#include "sysemu/block-backend.h" QemuOptsList internal_snapshot_opts = { .name ="snapshot" ,
@@ -238,7 +239,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs, }/* drain all pending i/o before deleting snapshot */ -bdrv_drain_all (); +blk_drain_all ();if (drv->bdrv_snapshot_delete) {return drv->bdrv_snapshot_delete (bs, snapshot_id, name, errp);
blockdev.c +8 -6
@@ -1156,7 +1156,7 @@ void do_commit(Monitor *mon, const QDict *qdict)int ret;if (!strcmp (device,"all" )) { - ret =bdrv_commit_all (); + ret =blk_commit_all (); }else { bs =bdrv_find (device);if (!bs) {
@@ -1830,7 +1830,7 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp)QSIMPLEQ_INIT (&snap_bdrv_states);/* drain all i/o before any operations */ -bdrv_drain_all (); +blk_drain_all ();/* We don't do anything in this loop that commits us to the operations */ while (NULL != dev_entry) {
@@ -2337,7 +2337,7 @@ void qmp_block_resize(bool has_device, const char *device, }/* complete all in-flight operations before resizing the device */ -bdrv_drain_all (); +blk_drain_all (); ret =bdrv_truncate (bs, size);switch (ret) {
@@ -2504,7 +2504,7 @@ void qmp_block_commit(const char *device, bs =blk_bs (blk);/* drain all i/o before commits */ -bdrv_drain_all (); +blk_drain_all ();if (bdrv_op_is_blocked (bs,BLOCK_OP_TYPE_COMMIT_SOURCE , errp)) { goto out;
@@ -3238,12 +3238,14 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp) {BlockJobInfoList *head =NULL , **p_next = &head;BlockDriverState *bs; +BlockBackend *blk =NULL ; -for (bs =bdrv_next (NULL ); bs; bs =bdrv_next (bs)) { -AioContext *aio_context =bdrv_get_aio_context (bs); +while ((blk =blk_next_inserted (blk)) !=NULL ) { +AioContext *aio_context =blk_get_aio_context (blk);aio_context_acquire (aio_context); + bs =blk_bs (blk);if (bs->job) {BlockJobInfoList *elem =g_new0 (BlockJobInfoList,1 ); elem->value =block_job_query (bs->job);
cpus.c +4 -3
@@ -28,6 +28,7 @@#include "monitor/monitor.h" #include "qapi/qmp/qerror.h" #include "sysemu/sysemu.h" +#include "sysemu/block-backend.h" #include "exec/gdbstub.h" #include "sysemu/dma.h" #include "sysemu/kvm.h"
@@ -603,8 +604,8 @@ static int do_vm_stop(RunState state)qapi_event_send_stop (&error_abort); } -bdrv_drain_all (); - ret =bdrv_flush_all (); +blk_drain_all (); + ret =blk_flush_all ();return ret; }
@@ -1302,7 +1303,7 @@ int vm_stop_force_state(RunState state)runstate_set (state);/* Make sure to return an error if the flush in a previous vm_stop() * failed. */ -return bdrv_flush_all (); +return blk_flush_all (); } }
migration/block.c +7 -3
@@ -23,6 +23,7 @@#include "migration/block.h" #include "migration/migration.h" #include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include <assert.h> #define BLOCK_SIZE (1 << 20)
@@ -348,6 +349,7 @@ static void unset_dirty_tracking(void)static void init_blk_migration (QEMUFile *f) {BlockDriverState *bs; +BlockBackend *blk =NULL ;BlkMigDevState *bmds;int64_t sectors;
@@ -359,7 +361,9 @@ static void init_blk_migration(QEMUFile *f) block_mig_state.bulk_completed =0 ; block_mig_state.zero_blocks =migrate_zero_blocks (); -for (bs =bdrv_next (NULL ); bs; bs =bdrv_next (bs)) { +while ((blk =blk_next_inserted (blk)) !=NULL ) { + bs =blk_bs (blk); +if (bdrv_is_read_only (bs)) {continue ; }
@@ -456,7 +460,7 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,blk_mig_lock ();if (bmds_aio_inflight (bmds, sector)) {blk_mig_unlock (); -bdrv_drain_all (); +blk_drain_all (); }else {blk_mig_unlock (); }
@@ -596,7 +600,7 @@ static void blk_mig_cleanup(void)BlkMigDevState *bmds;BlkMigBlock *blk; -bdrv_drain_all (); +blk_drain_all ();unset_dirty_tracking ();
migration/migration.c +2 -2
@@ -19,7 +19,7 @@#include "monitor/monitor.h" #include "migration/qemu-file.h" #include "sysemu/sysemu.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "qemu/sockets.h" #include "migration/block.h" #include "qemu/thread.h"
@@ -104,7 +104,7 @@ static void process_incoming_migration_co(void *opaque)qemu_announce_self ();/* Make sure all file formats flush their mutable metadata */ -bdrv_invalidate_cache_all (&local_err); +blk_invalidate_cache_all (&local_err);if (local_err) {qerror_report_err (local_err);error_free (local_err);
monitor.c +8 -5
@@ -40,6 +40,7 @@#include "ui/console.h" #include "ui/input.h" #include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "audio/audio.h" #include "disas/disas.h" #include "sysemu/balloon.h"
@@ -4617,13 +4618,15 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)static void vm_completion (ReadLineState *rs,const char *str) {size_t len; -BlockDriverState *bs =NULL ; +BlockDriverState *bs; +BlockBackend *blk =NULL ; len =strlen (str);readline_set_completion_index (rs, len); -while ((bs =bdrv_next (bs))) { +while ((blk =blk_next_inserted (blk)) !=NULL ) {SnapshotInfoList *snapshots, *snapshot; + bs =blk_bs (blk);if (!bdrv_can_snapshot (bs)) {continue ; }
@@ -4670,7 +4673,7 @@ static void monitor_find_completion_by_table(Monitor *mon,int i;const char *ptype, *str, *name;const mon_cmd_t *cmd; -BlockDriverState *bs; +BlockBackend *blk =NULL ;if (nb_args <=1 ) {/* command completion */
@@ -4723,8 +4726,8 @@ static void monitor_find_completion_by_table(Monitor *mon,case 'B' :/* block device name completion */ readline_set_completion_index (mon->rs,strlen (str)); -for (bs =bdrv_next (NULL ); bs; bs =bdrv_next (bs)) { - name =bdrv_get_device_name (bs); +while ((blk =blk_next (blk)) !=NULL ) { + name =blk_name (blk);if (str[0 ] =='\0' || !strncmp (name, str,strlen (str))) {readline_add_completion (mon->rs, name);
qemu-char.c +2 -1
@@ -24,6 +24,7 @@#include "qemu-common.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h" +#include "sysemu/block-backend.h" #include "qemu/timer.h" #include "sysemu/char.h" #include "hw/usb.h"
@@ -523,7 +524,7 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)break ; }case 's' : -bdrv_commit_all (); +blk_commit_all ();break ;case 'b' :qemu_chr_be_event (chr,CHR_EVENT_BREAK );
qemu-io.c +1 -1
@@ -472,7 +472,7 @@ int main(int argc, char **argv)/* * Make sure all outstanding requests complete before the program exits. */ -bdrv_drain_all (); +blk_drain_all ();blk_unref (qemuio_blk,NULL );g_free (readline_state);
qmp.c +4 -5
@@ -156,8 +156,7 @@ SpiceInfo *qmp_query_spice(Error **errp)void qmp_cont (Error **errp) {Error *local_err =NULL ; -BlockBackend *blk; -BlockDriverState *bs; +BlockBackend *blk =NULL ;if (runstate_needs_reset ()) {error_setg (errp,"Resetting the Virtual Machine is required" );
@@ -166,11 +165,11 @@ void qmp_cont(Error **errp)return ; } -for (blk =blk_next (NULL ); blk; blk =blk_next (blk)) { +while ((blk =blk_next (blk)) !=NULL ) {blk_iostatus_reset (blk); } -for (bs =bdrv_next (NULL ); bs; bs =bdrv_next (bs)) { -bdrv_add_key (bs,NULL , &local_err); +while ((blk =blk_next_inserted (blk)) !=NULL ) { +bdrv_add_key (blk_bs (blk),NULL , &local_err);if (local_err) {error_propagate (errp, local_err);return ;
savevm.c +39 -27
167 lines not on this page · raw message
xen-mapcache.c +2 -1
@@ -14,6 +14,7 @@#include "hw/xen/xen_backend.h" #include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "qemu/bitmap.h" #include <xen/hvm/params.h>
@@ -421,7 +422,7 @@ void xen_invalidate_map_cache(void)MapCacheRev *reventry;/* Flush pending AIO before destroying the mapcache */ -bdrv_drain_all (); +blk_drain_all ();mapcache_lock ();
Signature · 1 line
2.1.0
PATCH v2 13/22 block: Add blk_commit_all() and blk_invalidate_cache_all()
In reply to Max ReitzThese functions will be changed to iterate through the BDS trees as defined by the BlockBackends instead of the list of root BDS, therefore prepare moving their code to the BlockBackend level.
--- block/block-backend.c | 10 ++++++++++ include/sysemu/block-backend.h | 2 ++ 2 files changed, 12 insertions(+)
block/block-backend.c +10 -0
@@ -1261,3 +1261,13 @@ BlockBackendRootState *blk_get_root_state(BlockBackend *blk) {return &blk->root_state; } + +int blk_commit_all (void ) +{ +return bdrv_commit_all (); +} + +void blk_invalidate_cache_all (Error **errp) +{ +bdrv_invalidate_cache_all (errp); +}
include/sysemu/block-backend.h +2 -0
@@ -128,7 +128,9 @@ int blk_co_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors);int blk_co_flush (BlockBackend *blk);int blk_flush (BlockBackend *blk);int blk_flush_all (void ); +int blk_commit_all (void );void blk_drain_all (void ); +void blk_invalidate_cache_all (Error **errp);void blk_set_on_error (BlockBackend *blk,BlockdevOnError on_read_error,BlockdevOnError on_write_error);BlockdevOnError blk_get_on_error (BlockBackend *blk,bool is_read);
Signature · 1 line
2.1.0
PATCH v2 17/22 block: Make bdrv_drain_one() public
In reply to Max ReitzWe will need it in block/block-backend.c.
--- block.c | 2 +- include/block/block_int.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
block.c +1 -1
@@ -1949,7 +1949,7 @@ static bool bdrv_requests_pending(BlockDriverState *bs)return false; } -static bool bdrv_drain_one (BlockDriverState *bs) +bool bdrv_drain_one (BlockDriverState *bs) {bool bs_busy;
include/block/block_int.h +2 -0
@@ -428,6 +428,8 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,void bdrv_set_io_limits (BlockDriverState *bs,ThrottleConfig *cfg); +bool bdrv_drain_one (BlockDriverState *bs); +/** * bdrv_add_before_write_notifier:
Signature · 1 line
2.1.0
PATCH v2 15/22 blockdev: Add list of monitor-owned BlockBackends
In reply to Max ReitzThe monitor does hold references to some BlockBackends so it should have a list of those BBs; blk_backends is a different list, as it contains references to all BBs (after a follow-up patch, that is), and that should not be changed because we do need such a list.
--- block/block-backend.c | 27 ++++++++++++++++++++++++++- blockdev.c | 14 ++++++++++++++ include/sysemu/block-backend.h | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-)
block/block-backend.c +26 -1
@@ -28,6 +28,7 @@ struct BlockBackend {BlockDriverState *bs;DriveInfo *legacy_dinfo;/* null unless created by drive_new() */ QTAILQ_ENTRY (BlockBackend) link;/* for blk_backends */ +QTAILQ_ENTRY (BlockBackend) monitor_link;/* for monitor_block_backends */ void *dev;/* attached device model, if any */ /* TODO change to DeviceState when all users are qdevified */
@@ -69,6 +70,11 @@ static void drive_info_del(DriveInfo *dinfo); static QTAILQ_HEAD(, BlockBackend) blk_backends =QTAILQ_HEAD_INITIALIZER (blk_backends); +/* All BlockBackends referenced by the monitor and which are iterated through by +* blk_next() */ +static QTAILQ_HEAD(, BlockBackend) monitor_block_backends = +QTAILQ_HEAD_INITIALIZER (monitor_block_backends); +/* * Create a new BlockBackend with @name, with a reference count of one. * @name must not be null or empty.
@@ -231,7 +237,8 @@ void blk_unref(BlockBackend *blk, Notifier *close_all_notifier)*/ BlockBackend *blk_next (BlockBackend *blk) { -return blk ?QTAILQ_NEXT (blk, link) :QTAILQ_FIRST (&blk_backends); +return blk ?QTAILQ_NEXT (blk, monitor_link) + :QTAILQ_FIRST (&monitor_block_backends); }/*
@@ -250,6 +257,24 @@ BlockBackend *blk_next_inserted(BlockBackend *blk) }/* +* Add a BlockBackend into the list of backends referenced by the monitor. +* Strictly for use by blockdev.c. +*/ +void monitor_add_blk (BlockBackend *blk) +{ +QTAILQ_INSERT_TAIL (&monitor_block_backends, blk, monitor_link); +} + +/* +* Remove a BlockBackend from the list of backends referenced by the monitor. +* Strictly for use by blockdev.c. +*/ +void monitor_remove_blk (BlockBackend *blk) +{ +QTAILQ_REMOVE (&monitor_block_backends, blk, monitor_link); +} + +/* * Return @blk's name, a non-null string. * Wart: the name is empty iff @blk has been hidden with * blk_hide_on_behalf_of_do_drive_del().
blockdev.c +14 -0
@@ -90,6 +90,8 @@ static int if_max_devs[IF_COUNT] = {static void monitor_blk_unref_with_can (BlockBackend *blk,BlockdevCloseAllNotifier *can) { +BlockBackend *blk1 =NULL ; +if (can) {assert (can->blk == blk); }else {
@@ -101,6 +103,15 @@ static void monitor_blk_unref_with_can(BlockBackend *blk,assert (can); } +/* Thanks to do_drive_del() magic, the BlockBackend is not necessarily +* listed at this point */ +while ((blk1 =blk_next (blk1)) !=NULL ) { +if (blk1 == blk) { +monitor_remove_blk (blk); +break ; + } + } +blk_unref (blk, &can->n);QTAILQ_REMOVE (&close_all_notifiers, can, next);g_free (can);
@@ -634,6 +645,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,blk_set_on_error (blk, on_read_error, on_write_error); +monitor_add_blk (blk); + err_no_bs_opts:qemu_opts_del (opts);return blk;
@@ -2290,6 +2303,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)*/ if (blk_get_attached_dev (blk)) {blk_hide_on_behalf_of_do_drive_del (blk); +monitor_remove_blk (blk);/* Further I/O must not pause the guest */ blk_set_on_error (blk,BLOCKDEV_ON_ERROR_REPORT ,BLOCKDEV_ON_ERROR_REPORT );
include/sysemu/block-backend.h +2 -0
@@ -75,6 +75,8 @@ BlockBackend *blk_by_name(const char *name);bool blk_name_taken (const char *name);BlockBackend *blk_next (BlockBackend *blk);BlockBackend *blk_next_inserted (BlockBackend *blk); +void monitor_add_blk (BlockBackend *blk); +void monitor_remove_blk (BlockBackend *blk);BlockDriverState *blk_bs (BlockBackend *blk);void blk_remove_bs (BlockBackend *blk);
Signature · 1 line
2.1.0
PATCH v2 18/22 block: Move some bdrv_*_all() functions to BB
In reply to Max ReitzMove bdrv_drain_all(), bdrv_commit_all(), bdrv_flush_all() and bdrv_invalidate_cache_all() to BB.
The only operation left is bdrv_close_all(), which cannot be moved to the BB because it should not only close all BBs, but also all monitor-owned BDSs.
--- block.c | 97 -------------------------------------------- block/block-backend.c | 104 ++++++++++++++++++++++++++++++++++++++++++------ include/block/block.h | 4 -- stubs/Makefile.objs | 2 +- stubs/bdrv-commit-all.c | 7 ---- stubs/blk-commit-all.c | 7 ++++ 6 files changed, 100 insertions(+), 121 deletions(-) delete mode 100644 stubs/bdrv-commit-all.c create mode 100644 stubs/blk-commit-all.c
block.c +0 -97
@@ -1977,37 +1977,6 @@ void bdrv_drain(BlockDriverState *bs) } } -/* -* Wait for pending requests to complete across all BlockDriverStates -* -* This function does not flush data to disk, use bdrv_flush_all() for that -* after calling this function. -* -* Note that completion of an asynchronous I/O operation can trigger any -* number of other I/O operations on other devices---for example a coroutine -* can be arbitrarily complex and a constant flow of I/O can come until the -* coroutine is complete. Because of this, it is not possible to have a -* function to drain a single device's I/O queue. -*/ -void bdrv_drain_all (void ) -{ -/* Always run first iteration so any pending completion BHs run */ -bool busy = true; -BlockDriverState *bs; - -while (busy) { - busy = false; - - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { -AioContext *aio_context =bdrv_get_aio_context (bs); - -aio_context_acquire (aio_context); - busy |=bdrv_drain_one (bs); -aio_context_release (aio_context); - } - } -} -/* make a BlockDriverState anonymous by removing from bdrv_state and * graph_bdrv_state list. Also, NULL terminate the device_name to prevent double remove */
@@ -2300,26 +2269,6 @@ ro_cleanup:return ret; } -int bdrv_commit_all (void ) -{ -BlockDriverState *bs; - - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { -AioContext *aio_context =bdrv_get_aio_context (bs); - -aio_context_acquire (aio_context); -if (bs->drv && bs->backing_hd) { -int ret =bdrv_commit (bs); -if (ret <0 ) { -aio_context_release (aio_context); -return ret; - } - } -aio_context_release (aio_context); - } -return 0 ; -} -/** * Remove an active request from the tracked requests list *
@@ -3794,14 +3743,6 @@ BlockDriverState *bdrv_next_node(BlockDriverState *bs)return QTAILQ_NEXT (bs, node_list); } -BlockDriverState *bdrv_next (BlockDriverState *bs) -{ -if (!bs) { -return QTAILQ_FIRST (&bdrv_states); - } -return QTAILQ_NEXT (bs, device_list); -} -const char *bdrv_get_node_name (const BlockDriverState *bs) {return bs->node_name;
@@ -3818,26 +3759,6 @@ int bdrv_get_flags(BlockDriverState *bs)return bs->open_flags; } -int bdrv_flush_all (void ) -{ -BlockDriverState *bs; -int result =0 ; - - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { -AioContext *aio_context =bdrv_get_aio_context (bs); -int ret; - -aio_context_acquire (aio_context); - ret =bdrv_flush (bs); -if (ret <0 && !result) { - result = ret; - } -aio_context_release (aio_context); - } - -return result; -} -int bdrv_has_zero_init_1 (BlockDriverState *bs) {return 1 ;
@@ -4997,24 +4918,6 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) } } -void bdrv_invalidate_cache_all (Error **errp) -{ -BlockDriverState *bs; -Error *local_err =NULL ; - - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { -AioContext *aio_context =bdrv_get_aio_context (bs); - -aio_context_acquire (aio_context); -bdrv_invalidate_cache (bs, &local_err); -aio_context_release (aio_context); -if (local_err) { -error_propagate (errp, local_err); -return ; - } - } -} -int bdrv_flush (BlockDriverState *bs) {Coroutine *co;
block/block-backend.c +92 -12
126 lines not on this page · raw message
include/block/block.h +0 -4
@@ -239,7 +239,6 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);void bdrv_get_geometry (BlockDriverState *bs,uint64_t *nb_sectors_ptr);void bdrv_refresh_limits (BlockDriverState *bs,Error **errp);int bdrv_commit (BlockDriverState *bs); -int bdrv_commit_all (void );int bdrv_change_backing_file (BlockDriverState *bs,const char *backing_file,const char *backing_fmt);void bdrv_register (BlockDriver *bdrv);
@@ -325,15 +324,12 @@ BlockAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,/* Invalidate any cached metadata used by image formats */ void bdrv_invalidate_cache (BlockDriverState *bs,Error **errp); -void bdrv_invalidate_cache_all (Error **errp);/* Ensure contents are flushed to disk. */ int bdrv_flush (BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs); -int bdrv_flush_all (void );void bdrv_close_all (void );void bdrv_drain (BlockDriverState *bs); -void bdrv_drain_all (void );int bdrv_discard (BlockDriverState *bs,int64_t sector_num,int nb_sectors);int bdrv_co_discard (BlockDriverState *bs,int64_t sector_num,int nb_sectors);
stubs/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ stub-obj-y += arch-query-cpu-def.o -stub-obj-y += bdrv-commit-all.o +stub-obj-y += blk-commit-all.o stub-obj-y += chr-baum-init.o stub-obj-y += chr-msmouse.o stub-obj-y += chr-testdev.o
stubs/bdrv-commit-all.c deleted +0 -7
@@ -1,7 +0,0 @@ -#include "qemu-common.h" -#include "block/block.h" - -int bdrv_commit_all (void ) -{ -return 0 ; -}
stubs/blk-commit-all.c new file +7 -0
@@ -0,0 +1,7 @@ +#include "qemu-common.h" +#include "sysemu/block-backend.h" + +int blk_commit_all (void ) +{ +return 0 ; +}
Signature · 1 line
2.1.0
PATCH v2 19/22 block: Remove bdrv_states
In reply to Max ReitzEvery entry in this list should be a root BDS and as such either be anchored to a BlockBackend or be owned by the monitor.
--- block.c | 21 +-------------------- include/block/block.h | 1 - include/block/block_int.h | 2 -- 3 files changed, 1 insertion(+), 23 deletions(-)
block.c +1 -20
@@ -88,9 +88,6 @@ static void coroutine_fn bdrv_co_do_rw(void *opaque); static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,int64_t sector_num,int nb_sectors,BdrvRequestFlags flags); -static QTAILQ_HEAD(, BlockDriverState) bdrv_states = -QTAILQ_HEAD_INITIALIZER (bdrv_states); - static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =QTAILQ_HEAD_INITIALIZER (graph_bdrv_states);
@@ -360,10 +357,7 @@ void bdrv_register(BlockDriver *bdrv)BlockDriverState *bdrv_new_root (void ) { -BlockDriverState *bs =bdrv_new (); - -QTAILQ_INSERT_TAIL (&bdrv_states, bs, device_list); -return bs; +return bdrv_new (); }BlockDriverState *bdrv_new (void )
@@ -1982,17 +1976,6 @@ void bdrv_drain(BlockDriverState *bs)Also, NULL terminate the device_name to prevent double remove */ void bdrv_make_anon (BlockDriverState *bs) { -/* -* Take care to remove bs from bdrv_states only when it's actually -* in it. Note that bs->device_list.tqe_prev is initially null, -* and gets set to non-null by QTAILQ_INSERT_TAIL(). Establish -* the useful invariant "bs in bdrv_states iff bs->tqe_prev" by -* resetting it to null on remove. -*/ -if (bs->device_list.tqe_prev) { -QTAILQ_REMOVE (&bdrv_states, bs, device_list); - bs->device_list.tqe_prev =NULL ; - }if (bs->node_name[0 ] !='\0' ) {QTAILQ_REMOVE (&graph_bdrv_states, bs, node_list); }
@@ -2033,8 +2016,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,/* job */ bs_dest->job = bs_src->job; -/* keep the same entry in bdrv_states */ - bs_dest->device_list = bs_src->device_list; bs_dest->blk = bs_src->blk; memcpy(bs_dest->op_blockers, bs_src->op_blockers,
include/block/block.h +0 -1
@@ -361,7 +361,6 @@ BlockDriverState *bdrv_lookup_bs(const char *device, Error **errp);bool bdrv_chain_contains (BlockDriverState *top,BlockDriverState *base);BlockDriverState *bdrv_next_node (BlockDriverState *bs); -BlockDriverState *bdrv_next (BlockDriverState *bs);int bdrv_is_encrypted (BlockDriverState *bs);int bdrv_key_required (BlockDriverState *bs);int bdrv_set_key (BlockDriverState *bs,const char *key);
include/block/block_int.h +0 -2
@@ -380,8 +380,6 @@ struct BlockDriverState {char node_name[32 ];/* element of the list of named nodes building the graph */ QTAILQ_ENTRY (BlockDriverState) node_list; -/* element of the list of "drives" the guest sees */ -QTAILQ_ENTRY (BlockDriverState) device_list; QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps;int refcnt;
Signature · 1 line
2.1.0
PATCH v2 16/22 blockdev: Remove blk_hide_on_behalf_of_do_drive_del()
In reply to Max ReitzThis function first removed the BlockBackend from the blk_backends list and cleared its name so it would no longer be found by blk_name(); since blk_next() now iterates through monitor_block_backends (which the BB is removed from in do_drive_del()), this is no longer necessary.
Second, bdrv_make_anon() was called on the BDS. This was intended for cases where the BDS was owned by that BB alone; in which case the BDS will no longer exist at this point thanks to the blk_remove_bs() in do_drive_del().
Therefore, this function does nothing useful anymore. Remove it.
--- block/block-backend.c | 25 ++----------------------- blockdev.c | 1 - include/sysemu/block-backend.h | 2 -- 3 files changed, 2 insertions(+), 26 deletions(-)
block/block-backend.c +2 -23
@@ -66,7 +66,7 @@ static const AIOCBInfo block_backend_aiocb_info = {static void drive_info_del (DriveInfo *dinfo); -/* All the BlockBackends (except for hidden ones) */ +/* All the BlockBackends */ static QTAILQ_HEAD(, BlockBackend) blk_backends =QTAILQ_HEAD_INITIALIZER (blk_backends);
@@ -174,10 +174,7 @@ static void blk_delete(BlockBackend *blk)assert (!blk->refcnt);assert (!blk->dev);blk_remove_bs (blk); -/* Avoid double-remove after blk_hide_on_behalf_of_do_drive_del() */ -if (blk->name[0 ]) { -QTAILQ_REMOVE (&blk_backends, blk, link); - } +QTAILQ_REMOVE (&blk_backends, blk, link);g_free (blk->name);drive_info_del (blk->legacy_dinfo);g_free (blk);
@@ -362,24 +359,6 @@ BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo) }/* -* Hide @blk. -* @blk must not have been hidden already. -* Make attached BlockDriverState, if any, anonymous. -* Once hidden, @blk is invisible to all functions that don't receive -* it as argument. For example, blk_by_name() won't return it. -* Strictly for use by do_drive_del(). -* TODO get rid of it! -*/ -void blk_hide_on_behalf_of_do_drive_del (BlockBackend *blk) -{ -QTAILQ_REMOVE (&blk_backends, blk, link); - blk->name[0 ] =0 ; -if (blk->bs) { -bdrv_make_anon (blk->bs); - } -} - -/* * Disassociates the currently associated BlockDriverState from @blk. */ void blk_remove_bs (BlockBackend *blk)
blockdev.c +0 -1
@@ -2302,7 +2302,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)* then we can just get rid of the block driver state right here. */ if (blk_get_attached_dev (blk)) { -blk_hide_on_behalf_of_do_drive_del (blk);monitor_remove_blk (blk);/* Further I/O must not pause the guest */ blk_set_on_error(blk, BLOCKDEV_ON_ERROR_REPORT,
include/sysemu/block-backend.h +0 -2
@@ -82,8 +82,6 @@ BlockDriverState *blk_bs(BlockBackend *blk);void blk_remove_bs (BlockBackend *blk);void blk_insert_bs (BlockBackend *blk,BlockDriverState *bs); -void blk_hide_on_behalf_of_do_drive_del (BlockBackend *blk); -void blk_iostatus_enable (BlockBackend *blk);bool blk_iostatus_is_enabled (const BlockBackend *blk);BlockDeviceIoStatus blk_iostatus (const BlockBackend *blk);
Signature · 1 line
2.1.0
PATCH v2 20/22 blockdev: Keep track of monitor-owned BDS
In reply to Max Reitz...and release the reference on bdrv_close_all().
--- block.c | 2 ++ blockdev.c | 24 ++++++++++++++++++++++++ include/block/block_int.h | 2 ++ 3 files changed, 28 insertions(+)
block.c +2 -0
@@ -2016,6 +2016,8 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,/* job */ bs_dest->job = bs_src->job; +/* keep the same entry in the list of monitor-owned BDS */ + bs_dest->monitor_list = bs_src->monitor_list; bs_dest->blk = bs_src->blk; memcpy(bs_dest->op_blockers, bs_src->op_blockers,
blockdev.c +24 -0
@@ -56,6 +56,11 @@ typedef struct BlockdevCloseAllNotifier { static QTAILQ_HEAD(, BlockdevCloseAllNotifier) close_all_notifiers =QTAILQ_HEAD_INITIALIZER (close_all_notifiers); +static Notifier *close_all_bdrv_states_notifier; + +static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states = +QTAILQ_HEAD_INITIALIZER (monitor_bdrv_states); +static const char *const if_name[IF_COUNT ] = { [IF_NONE ] ="none" , [IF_IDE ] ="ide" ,
@@ -129,6 +134,17 @@ static void blockdev_close_all_notifier(Notifier *n, void *data)monitor_blk_unref_with_can (can->blk, can); } +static void blockdev_close_all_bdrv_states (Notifier *n,void *data) +{ +BlockDriverState *bds, *next_bds; + + QTAILQ_FOREACH_SAFE(bds, &monitor_bdrv_states, monitor_list, next_bds) { +bdrv_unref (bds); + } + +g_free (n); +} +/** * Boards may call this to offer board-by-board overrides * of the default, global values.
@@ -3231,6 +3247,14 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)if (!bs) { goto fail; } + +QTAILQ_INSERT_TAIL (&monitor_bdrv_states, bs, monitor_list); +if (!close_all_bdrv_states_notifier) { + close_all_bdrv_states_notifier =g_new0 (Notifier,1 ); + close_all_bdrv_states_notifier->notify = + blockdev_close_all_bdrv_states; +bdrv_add_close_all_notifier (close_all_bdrv_states_notifier); + } }if (bs &&bdrv_key_required (bs)) {
include/block/block_int.h +2 -0
@@ -380,6 +380,8 @@ struct BlockDriverState {char node_name[32 ];/* element of the list of named nodes building the graph */ QTAILQ_ENTRY (BlockDriverState) node_list; +/* element of the list of monitor-owned BDS */ +QTAILQ_ENTRY (BlockDriverState) monitor_list; QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps;int refcnt;
Signature · 1 line
2.1.0
PATCH v2 21/22 block: Strip down bdrv_close_all()
In reply to Max ReitzReferences to all BlockBackends and BlockDriverStates are now released by their respective holders; force-closing them is no longer necessary.
--- block.c | 11 +---------- block/block-backend.c | 8 ++++++++ include/sysemu/block-backend.h | 1 + 3 files changed, 10 insertions(+), 10 deletions(-)
block.c +1 -10
@@ -1904,17 +1904,8 @@ static void bdrv_close(BlockDriverState *bs)void bdrv_close_all (void ) { -BlockBackend *blk =NULL ; -notifier_list_notify (&close_all_notifiers,NULL ); - -while ((blk =blk_next_inserted (blk)) !=NULL ) { -AioContext *aio_context =blk_get_aio_context (blk); - -aio_context_acquire (aio_context); -bdrv_close (blk_bs (blk)); -aio_context_release (aio_context); - } +blk_close_all_finalize (); }void bdrv_add_close_all_notifier (Notifier *notifier)
block/block-backend.c +8 -0
@@ -223,6 +223,14 @@ void blk_unref(BlockBackend *blk, Notifier *close_all_notifier) }/* +* For use by bdrv_close_all() +*/ +void blk_close_all_finalize (void ) +{ +assert (QTAILQ_EMPTY (&blk_backends)); +} + +/* * Return the BlockBackend after @blk. * If @blk is null, return the first one. * Else, return @blk's next sibling, which may be null.
include/sysemu/block-backend.h +1 -0
@@ -70,6 +70,7 @@ BlockBackend *blk_new_open(const char *name, const char *filename, Notifier *close_all_notifier, Error **errp);void blk_ref (BlockBackend *blk,Notifier *close_all_notifier);void blk_unref (BlockBackend *blk,Notifier *close_all_notifier); +void blk_close_all_finalize (void );const char *blk_name (BlockBackend *blk);BlockBackend *blk_by_name (const char *name);bool blk_name_taken (const char *name);
Signature · 1 line
2.1.0
PATCH v2 22/22 iotests: Add test for multiple BB on BDS tree
In reply to Max ReitzThis adds a test for having multiple BlockBackends in one BDS tree. In this case, there is one BB for the protocol BDS and one BB for the format BDS in a simple two-BDS tree (with the protocol BDS and BB added first).
When bdrv_close_all() is executed, no cached data from any BDS should be lost; the protocol BDS may not be closed until the format BDS is closed. Otherwise, metadata updates may be lost.
--- tests/qemu-iotests/117 | 86 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/117.out | 14 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 101 insertions(+) create mode 100755 tests/qemu-iotests/117 create mode 100644 tests/qemu-iotests/117.out
tests/qemu-iotests/117 new file +86 -0
@@ -0,0 +1,86 @@ +#!/bin/bash +# +# Test case for shared BDS between backend trees +# +# Copyright (C) 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.qemu + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +_make_test_img 64k + +_launch_qemu + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'qmp_capabilities' }" \ + 'return' + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'blockdev-add', + 'arguments': { 'options': { 'id': 'protocol', + 'driver': 'file', + 'filename': '$TEST_IMG' } } }" \ + 'return' + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'blockdev-add', + 'arguments': { 'options': { 'id': 'format', + 'driver': '$IMGFMT', + 'file': 'protocol' } } }" \ + 'return' + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'human-monitor-command', + 'arguments': { 'command-line': 'qemu-io format \"write -P 42 0 64k\"' } }" \ + 'return' + +_send_qemu_cmd $QEMU_HANDLE \ + "{ 'execute': 'quit' }" \ + 'return' + +wait=1 _cleanup_qemu + +_check_test_img + +$QEMU_IO -c 'read -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io + +# success, all done +echo '*** done' +rm -f $seq.full +status=0
tests/qemu-iotests/117.out new file +14 -0
@@ -0,0 +1,14 @@ +QA output created by 117 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536 +{"return": {}} +{"return": {}} +{"return": {}} +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +{"return": ""} +{"return": {}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"} +No errors were found on the image. +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done
tests/qemu-iotests/group +1 -0
@@ -119,4 +119,5 @@ 113 rw auto quick 114 rw auto quick 116 rw auto quick +117 rw auto 118 rw auto
Signature · 1 line
2.1.0
Quoted 8 lines · Max Reitz
Currently,
bdrv_close_all()force-closes all BDSs with a BlockBackend, which can lead to data corruption (see the iotest added in the final patch of this series) and is most certainly very ugly.This series reworks
bdrv_close_all()to notify all owners of a BlockBackend that they should release their reference (and additionally the monitor releases all its references to BB-less BDSs). This way, force-closing becomes unnecessary.
The NBD parts look good.
Paolo
Re: [Qemu-devel] [PATCH v2 07/22] block: Add bdrv_close_all() handlers
In reply to Max ReitzQuoted 26 lines · Max Reitz
Every time a reference to a BlockBackend is taken, a notifier for
bdrv_close_all()has to be deposited so the reference holder can relinquish its reference whenbdrv_close_all()is called. That notifier should be revoked on abdrv_unref()call.Add a Notifier * parameter to all the functions changing the reference count of a BlockBackend:
blk_new(),blk_new_with_bs(),blk_new_open(),blk_ref()andblk_unref().By dropping the manual reference handling in
hw/block/xen_disk.c, theblk_unref()inhw/ide/piix.ccan be dropped as well.Signed-off-by Max Reitz <[email protected]>--- block/block-backend.c | 69 ++++++++++++++++++++++++++++++++++++------ blockdev.c | 62 ++++++++++++++++++++++++++++++++++--- device-hotplug.c | 2 +- hw/block/xen_disk.c | 16 +++++++--- hw/ide/piix.c | 1 - include/sysemu/block-backend.h | 13 +++++--- include/sysemu/blockdev.h | 3 ++ nbd.c | 26 ++++++++++++++-- qemu-img.c | 39 ++++++++++++------------ qemu-io.c | 6 ++-- qemu-nbd.c | 6 ++-- 11 files changed, 189 insertions(+), 54 deletions(-)
[snip]
Quoted 25 lines
qemu-nbd.c +4
-1@@ -694,7 +694,8 @@ int main(int argc, char **argv) } srcpath = argv[optind]; - blk =blk_new_open ("hda" , srcpath,NULL , options, flags, &local_err); +/* the reference will be passed on nbd_export_new() */ + blk =blk_new_open ("hda" , srcpath,NULL , options, flags,NULL , &local_err);if (!blk) {errx (EXIT_FAILURE ,"Failed to blk_new_open '%s': %s" , argv[optind],error_get_pretty (local_err));@@ -728,7 +729,9 @@ int main(int argc, char **argv) } } +/* nbd_export_new() takes the reference to blk */ exp =nbd_export_new (blk, dev_offset, fd_size, nbdflags, nbd_export_closed); +blk_unref (blk,NULL );if (sockpath) { fd =unix_socket_incoming (sockpath);
qemu-nbd.c int main(int argc, char **argv) · line 781
Quoted 7 lines
qemu-nbd.c +0
-1@@ -773,7 +776,6 @@ int main(int argc, char **argv) } }while (state !=TERMINATED ); -blk_unref (blk);if (sockpath) {unlink (sockpath); }
Because qemu-nbd does not install a handler for relinquishing its reference, it has to make sure it drops that reference before a bdrv_close_all() occurs. Therefore, err() and errx() calls after blk_new_open() (except for the if (!blk) path) and before blk_unref(blk, NULL) need to be preceded by a blk_unref(blk, NULL).
I'll fix it in v3.
Max
Re: [Qemu-devel] [PATCH v2 01/22] iotests: Move _filter_nbd into common.filter
In reply to Max ReitzQuoted 7 lines · Max Reitz
_filter_nbdcan be useful for other NBD tests, too, therefore it should reside in common.filter, and it should support URLs of the "nbd://" format and export names.The NBD log lines ("/your/source/dir/nbd.c:function():line: error") should not be converted to empty lines but removed altogether.
Quoted 6 lines
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/083 | 13 +------------ tests/qemu-iotests/083.out | 10 ---------- tests/qemu-iotests/common.filter | 12 ++++++++++++ 3 files changed, 13 insertions(+), 22 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org