block/export: add BlockExportOptions->iothread member
Subsystems (2)
v2 cover block/export: add BlockExportOptions->iothread member
v2:
* Add fixed-iothread option to set AioContext change policy [Kevin]
* Use os-posix.c signal handling utilities in qemu-nbd.c [Paolo]
This series adjusts the build system and then adds a BlockExportOptions->iothread member so that it is possible to set the iothread for an export.
Based-on: [email protected] ("[PATCH v2 00/13] block/export: convert vhost-user-blk-server to block exports API")
Stefan Hajnoczi (4):
util/vhost-user-server: use static library in meson.build
qemu-storage-daemon: avoid compiling blockdev_ss twice
block: move block exports to libblockdev block/export: add iothread and fixed-iothread options
qapi/block-export.json | 11 ++++++++ block/export/export.c | 39 ++++++++++++++++++++++++---- block/export/vhost-user-blk-server.c | 5 +++- nbd/server.c | 2 -- qemu-nbd.c | 21 +++++++-------- stubs/blk-exp-close-all.c | 7 +++++ block/export/meson.build | 4 +-- contrib/libvhost-user/meson.build | 1 + meson.build | 22 ++++++++++++---- nbd/meson.build | 2 ++ storage-daemon/meson.build | 3 +-- stubs/meson.build | 1 + tests/qtest/meson.build | 2 +- util/meson.build | 4 ++- 14 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 stubs/blk-exp-close-all.c
Signature · 1 line
2.26.2
PATCH v2 1/4 util/vhost-user-server: use static library in meson.build
Don't compile contrib/libvhost-user/libvhost-user.c again. Instead build the static library once and then reuse it throughout QEMU.
Also switch from CONFIG_LINUX to CONFIG_VHOST_USER, which is what the vhost-user tools (vhost-user-gpu, etc) do.
--- block/export/export.c | 8 ++++---- block/export/meson.build | 2 +- contrib/libvhost-user/meson.build | 1 + meson.build | 6 +++++- tests/qtest/meson.build | 2 +- util/meson.build | 4 +++- 6 files changed, 15 insertions(+), 8 deletions(-)
block/export/export.c +4 -4
@@ -17,17 +17,17 @@#include "sysemu/block-backend.h" #include "block/export.h" #include "block/nbd.h" -#if CONFIG_LINUX -#include "block/export/vhost-user-blk-server.h" -#endif #include "qapi/error.h" #include "qapi/qapi-commands-block-export.h" #include "qapi/qapi-events-block-export.h" #include "qemu/id.h" +#ifdef CONFIG_VHOST_USER +#include "vhost-user-blk-server.h" +#endif static const BlockExportDriver *blk_exp_drivers[] = { &blk_exp_nbd, -#if CONFIG_LINUX +#ifdef CONFIG_VHOST_USER &blk_exp_vhost_user_blk, #endif };
block/export/meson.build +1 -1
@@ -1,2 +1,2 @@ block_ss.add(files('export.c')) -block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c', '../../contrib/libvhost-user/libvhost-user.c')) +block_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c'))
contrib/libvhost-user/meson.build +1 -0
@@ -1,3 +1,4 @@ libvhost_user = static_library('vhost-user', files('libvhost-user.c', 'libvhost-user-glib.c'), build_by_default: false) +vhost_user = declare_dependency(link_with: libvhost_user)
meson.build +5 -1
@@ -788,6 +788,11 @@ trace_events_subdirs += [ 'util', ] +vhost_user = not_found +if 'CONFIG_VHOST_USER' in config_host + subdir('contrib/libvhost-user') +endif + subdir('qapi') subdir('qobject') subdir('stubs')
@@ -1169,7 +1174,6 @@ if have_tools install: true) if 'CONFIG_VHOST_USER' in config_host - subdir('contrib/libvhost-user') subdir('contrib/vhost-user-blk') subdir('contrib/vhost-user-gpu') subdir('contrib/vhost-user-input')
tests/qtest/meson.build +1 -1
@@ -191,7 +191,7 @@ qos_test_ss.add( ) qos_test_ss.add(when: 'CONFIG_VIRTFS', if_true: files('virtio-9p-test.c')) qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-test.c')) -qos_test_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-test.c')) +qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-test.c')) extra_qtest_deps = { 'bios-tables-test': [io],
util/meson.build +3 -1
@@ -66,7 +66,9 @@ if have_block util_ss.add(files('main-loop.c')) util_ss.add(files('nvdimm-utils.c')) util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) - util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) + util_ss.add(when: 'CONFIG_VHOST_USER', if_true: [ + files('vhost-user-server.c'), vhost_user + ]) util_ss.add(files('block-helpers.c')) util_ss.add(files('qemu-coroutine-sleep.c')) util_ss.add(files('qemu-co-shared-resource.c'))
Signature · 1 line
2.26.2
PATCH v2 2/4 qemu-storage-daemon: avoid compiling blockdev_ss twice
In reply to Stefan HajnocziIntroduce libblkdev.fa to avoid recompiling blockdev_ss twice.
--- meson.build | 12 ++++++++++-- storage-daemon/meson.build | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-)
meson.build +10 -2
@@ -857,7 +857,6 @@ blockdev_ss.add(files( blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c')) softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')]) -softmmu_ss.add_all(blockdev_ss) softmmu_ss.add(files( 'bootdevice.c', 'dma-helpers.c',
@@ -952,6 +951,15 @@ block = declare_dependency(link_whole: [libblock], link_args: '@block.syms', dependencies: [crypto, io]) +blockdev_ss = blockdev_ss.apply(config_host, strict: false) +libblockdev = static_library('blockdev', blockdev_ss.sources() + genh, + dependencies: blockdev_ss.dependencies(), + name_suffix: 'fa', + build_by_default: false) + +blockdev = declare_dependency(link_whole: [libblockdev], + dependencies: [block]) + qmp_ss = qmp_ss.apply(config_host, strict: false) libqmp = static_library('qmp', qmp_ss.sources() + genh, dependencies: qmp_ss.dependencies(),
@@ -968,7 +976,7 @@ foreach m : block_mods + softmmu_mods install_dir: config_host['qemu_moddir']) endforeach -softmmu_ss.add(authz, block, chardev, crypto, io, qmp) +softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp) common_ss.add(qom, qemuutil) common_ss.add_all(when: 'CONFIG_SOFTMMU', if_true: [softmmu_ss])
storage-daemon/meson.build +1 -2
@@ -1,7 +1,6 @@ qsd_ss = ss.source_set() qsd_ss.add(files('qemu-storage-daemon.c')) -qsd_ss.add(block, chardev, qmp, qom, qemuutil) -qsd_ss.add_all(blockdev_ss) +qsd_ss.add(blockdev, chardev, qmp, qom, qemuutil) subdir('qapi')
Signature · 1 line
2.26.2
PATCH v2 3/4 block: move block exports to libblockdev
In reply to Stefan HajnocziBlock exports are used by softmmu, qemu-storage-daemon, and qemu-nbd. They are not used by other programs and are not otherwise needed in libblock.
Undo the recent move of blockdev-nbd.c from blockdev_ss into block_ss. Since bdrv_close_all() (libblock) calls blk_exp_close_all() (libblockdev) a stub function is required..
Make qemu-ndb.c use signal handling utility functions instead of duplicating the code. This helps because os-posix.c is in libblockdev and it depends on a qemu_system_killed() symbol that qemu-nbd.c lacks. Once we use the signal handling utility functions we also end up providing the necessary symbol.
--- qemu-nbd.c | 21 +++++++++------------ stubs/blk-exp-close-all.c | 7 +++++++ block/export/meson.build | 4 ++-- meson.build | 4 ++-- nbd/meson.build | 2 ++ stubs/meson.build | 1 + 6 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 stubs/blk-exp-close-all.c
qemu-nbd.c +9 -12
@@ -25,6 +25,7 @@#include "qapi/error.h" #include "qemu/cutils.h" #include "sysemu/block-backend.h" +#include "sysemu/runstate.h" /* for qemu_system_killed() prototype */ #include "block/block_int.h" #include "block/nbd.h" #include "qemu/main-loop.h"
@@ -155,7 +156,11 @@ QEMU_COPYRIGHT "\n" }#if HAVE_NBD_DEVICE -static void termsig_handler (int signum) +/* +* The client thread uses SIGTERM to interrupt the server. A signal +* handler ensures that "qemu-nbd -v -c" exits with a nice status code. +*/ +void qemu_system_killed (int signum,pid_t pid) {atomic_cmpxchg (&state,RUNNING ,TERMINATE );qemu_notify_event ();
@@ -581,20 +586,12 @@ int main(int argc, char **argv)const char *pid_file_name =NULL ;BlockExportOptions *export_opts; +os_setup_early_signal_handling (); +#if HAVE_NBD_DEVICE -/* The client thread uses SIGTERM to interrupt the server. A signal -* handler ensures that "qemu-nbd -v -c" exits with a nice status code. -*/ -struct sigaction sa_sigterm; -memset (&sa_sigterm,0 ,sizeof (sa_sigterm)); - sa_sigterm.sa_handler = termsig_handler; -sigaction (SIGTERM , &sa_sigterm,NULL ); +os_setup_signal_handling ();#endif /* HAVE_NBD_DEVICE */ -#ifdef CONFIG_POSIX -signal (SIGPIPE ,SIG_IGN ); -#endif -socket_init ();error_init (argv[0 ]);module_call_init (MODULE_INIT_TRACE );
stubs/blk-exp-close-all.c new file +7 -0
@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "block/export.h" + +/* Only used in programs that support block exports (libblockdev.fa) */ +void blk_exp_close_all (void ) +{ +}
block/export/meson.build +2 -2
@@ -1,2 +1,2 @@ -block_ss.add(files('export.c')) -block_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c')) +blockdev_ss.add(files('export.c')) +blockdev_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c'))
meson.build +2 -2
@@ -835,7 +835,6 @@ subdir('dump') block_ss.add(files( 'block.c', - 'blockdev-nbd.c', 'blockjob.c', 'job.c', 'qemu-io-cmds.c',
@@ -848,6 +847,7 @@ subdir('block') blockdev_ss.add(files( 'blockdev.c', + 'blockdev-nbd.c', 'iothread.c', 'job-qmp.c', ))
@@ -1171,7 +1171,7 @@ if have_tools qemu_io = executable('qemu-io', files('qemu-io.c'), dependencies: [block, qemuutil], install: true) qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'), - dependencies: [block, qemuutil], install: true) + dependencies: [blockdev, qemuutil], install: true) subdir('storage-daemon') subdir('contrib/rdmacm-mux')
nbd/meson.build +2 -0
@@ -1,5 +1,7 @@ block_ss.add(files( 'client.c', 'common.c', +)) +blockdev_ss.add(files( 'server.c', ))
stubs/meson.build +1 -0
@@ -1,6 +1,7 @@ stub_ss.add(files('arch_type.c')) stub_ss.add(files('bdrv-next-monitor-owned.c')) stub_ss.add(files('blk-commit-all.c')) +stub_ss.add(files('blk-exp-close-all.c')) stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) stub_ss.add(files('clock-warp.c'))
Signature · 1 line
2.26.2
Re: [PATCH v2 3/4] block: move block exports to libblockdev
Quoted 143 lines · Stefan Hajnoczi
Block exports are used by softmmu, qemu-storage-daemon, and qemu-nbd. They are not used by other programs and are not otherwise needed in libblock.
Undo the recent move of
blockdev-nbd.cfromblockdev_ssintoblock_ss. Sincebdrv_close_all()(libblock) callsblk_exp_close_all()(libblockdev) a stub function is required..Make
qemu-ndb.cuse signal handling utility functions instead of duplicating the code. This helps becauseos-posix.cis in libblockdev and it depends on aqemu_system_killed()symbol thatqemu-nbd.clacks. Once we use the signal handling utility functions we also end up providing the necessary symbol.Signed-off-by Stefan Hajnoczi <[email protected]>--- qemu-nbd.c | 21 +++++++++------------ stubs/blk-exp-close-all.c | 7 +++++++ block/export/meson.build | 4 ++-- meson.build | 4 ++-- nbd/meson.build | 2 ++ stubs/meson.build | 1 + 6 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 stubs/blk-exp-close-all.cqemu-nbd.c +9
-12@@ -25,6 +25,7 @@#include "qapi/error.h" #include "qemu/cutils.h" #include "sysemu/block-backend.h" +#include "sysemu/runstate.h" /* for qemu_system_killed() prototype */ #include "block/block_int.h" #include "block/nbd.h" #include "qemu/main-loop.h" @@ -155,7 +156,11 @@ QEMU_COPYRIGHT "\n" }#if HAVE_NBD_DEVICE -static void termsig_handler (int signum) +/* +* The client thread uses SIGTERM to interrupt the server. A signal +* handler ensures that "qemu-nbd -v -c" exits with a nice status code. +*/ +void qemu_system_killed (int signum,pid_t pid) {atomic_cmpxchg (&state,RUNNING ,TERMINATE );qemu_notify_event ();@@ -581,20 +586,12 @@ int main(int argc, char **argv)const char *pid_file_name =NULL ;BlockExportOptions *export_opts; +os_setup_early_signal_handling (); +#if HAVE_NBD_DEVICE -/* The client thread uses SIGTERM to interrupt the server. A signal -* handler ensures that "qemu-nbd -v -c" exits with a nice status code. -*/ -struct sigaction sa_sigterm; -memset (&sa_sigterm,0 ,sizeof (sa_sigterm)); - sa_sigterm.sa_handler = termsig_handler; -sigaction (SIGTERM , &sa_sigterm,NULL ); +os_setup_signal_handling ();#endif /* HAVE_NBD_DEVICE */ -#ifdef CONFIG_POSIX -signal (SIGPIPE ,SIG_IGN ); -#endif -socket_init ();error_init (argv[0 ]);module_call_init (MODULE_INIT_TRACE );stubs/blk-exp-close-all.c new file +7
-0@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "block/export.h" + +/* Only used in programs that support block exports (libblockdev.fa) */ +void blk_exp_close_all (void ) +{ +}block/export/meson.build +2
-2@@ -1,2 +1,2 @@ -block_ss.add(files('export.c')) -block_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c')) +blockdev_ss.add(files('export.c')) +blockdev_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c'))meson.build +2
-2@@ -835,7 +835,6 @@ subdir('dump') block_ss.add(files( 'block.c', - 'blockdev-nbd.c', 'blockjob.c', 'job.c', 'qemu-io-cmds.c',@@ -848,6 +847,7 @@ subdir('block') blockdev_ss.add(files( 'blockdev.c', + 'blockdev-nbd.c', 'iothread.c', 'job-qmp.c', ))@@ -1171,7 +1171,7 @@ if have_tools qemu_io = executable('qemu-io', files('qemu-io.c'), dependencies: [block, qemuutil], install: true) qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'), - dependencies: [block, qemuutil], install: true) + dependencies: [blockdev, qemuutil], install: true) subdir('storage-daemon') subdir('contrib/rdmacm-mux')nbd/meson.build +2
-0@@ -1,5 +1,7 @@ block_ss.add(files( 'client.c', 'common.c', +)) +blockdev_ss.add(files( 'server.c', ))stubs/meson.build +0
-0
stubs/meson.build line 7
Quoted 7 lines
stubs/meson.build +1
-0@@ -1,6 +1,7 @@ stub_ss.add(files('arch_type.c')) stub_ss.add(files('bdrv-next-monitor-owned.c')) stub_ss.add(files('blk-commit-all.c')) +stub_ss.add(files('blk-exp-close-all.c')) stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) stub_ss.add(files('clock-warp.c'))
Re: [PATCH v2 3/4] block: move block exports to libblockdev
In reply to Stefan HajnocziQuoted 9 lines · Stefan Hajnoczi
Block exports are used by softmmu, qemu-storage-daemon, and qemu-nbd. They are not used by other programs and are not otherwise needed in libblock.
Undo the recent move of
blockdev-nbd.cfromblockdev_ssintoblock_ss. Sincebdrv_close_all()(libblock) callsblk_exp_close_all()(libblockdev) a stub function is required..Make
qemu-ndb.cuse signal handling utility functions instead of
nbd
Quoted 7 lines
duplicating the code. This helps because
os-posix.cis in libblockdev and it depends on aqemu_system_killed()symbol thatqemu-nbd.clacks. Once we use the signal handling utility functions we also end up providing the necessary symbol.Signed-off-by Stefan Hajnoczi <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 3/4] block: move block exports to libblockdev
In reply to Stefan HajnocziQuoted 8 lines · Stefan Hajnoczi
Block exports are used by softmmu, qemu-storage-daemon, and qemu-nbd. They are not used by other programs and are not otherwise needed in libblock.
Undo the recent move of
blockdev-nbd.cfromblockdev_ssintoblock_ss. Sincebdrv_close_all()(libblock) callsblk_exp_close_all()(libblockdev) a stub function is required..
Quoted 5 lines
Make
qemu-ndb.cuse signal handling utility functions instead of duplicating the code. This helps becauseos-posix.cis in libblockdev and it depends on aqemu_system_killed()symbol thatqemu-nbd.clacks. Once we use the signal handling utility functions we also end up providing the necessary symbol.
Hmm. I just stumbled on a long-standing bug in qemu-nbd - it installs a SIGTERM handler, but not a SIGINT or SIGHUP handler. This matters in the following sequence:
qemu-nbd -f qcow2 -B bitmap image # Ctrl-C
qemu-nbd -f qcow2 -B bitmap image
because the first instance dies with SIGINT but there is no handler installed, qemu-nbd does not release the bitmap from being marked in-use, and the second instance then fails with:
qemu-nbd: Bitmap 'b0' is inconsistent and cannot be used
And to my surprise, while I was trying to find the root cause to fixing the bug I just found, I noticed that your patch happens to fix that...
Quoted 7 lines
+++
b/qemu-nbd.cqemu-nbd.c +1
-0@@ -581,20 +586,12 @@ int main(int argc, char **argv)const char *pid_file_name =NULL ;BlockExportOptions *export_opts; +os_setup_early_signal_handling ();
qemu-nbd.c int main(int argc, char **argv) · line 592
Quoted 10 lines
qemu-nbd.c +2
-7+#if HAVE_NBD_DEVICE -/* The client thread uses SIGTERM to interrupt the server. A signal -* handler ensures that "qemu-nbd -v -c" exits with a nice status code. -*/ -struct sigaction sa_sigterm; -memset (&sa_sigterm,0 ,sizeof (sa_sigterm)); - sa_sigterm.sa_handler = termsig_handler; -sigaction (SIGTERM , &sa_sigterm,NULL ); +os_setup_signal_handling ();
...by installing a SIGINT handler.
Is HAVE_NBD_DEVICE really the best gate for this code, or is it really whether we are compiling for mingw? At any rate, you may want to add a link to https://bugzilla.redhat.com/show_bug.cgi?id=1883608 in the commit message, and/or separate the bug fix out into a separate commit.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 3/4] block: move block exports to libblockdev
Quoted 51 lines · Eric Blake
Quoted 8 lines · Stefan Hajnoczi
Block exports are used by softmmu, qemu-storage-daemon, and qemu-nbd. They are not used by other programs and are not otherwise needed in libblock.
Undo the recent move of
blockdev-nbd.cfromblockdev_ssintoblock_ss. Sincebdrv_close_all()(libblock) callsblk_exp_close_all()(libblockdev) a stub function is required..Quoted 5 lines
Make
qemu-ndb.cuse signal handling utility functions instead of duplicating the code. This helps becauseos-posix.cis in libblockdev and it depends on aqemu_system_killed()symbol thatqemu-nbd.clacks. Once we use the signal handling utility functions we also end up providing the necessary symbol.Hmm. I just stumbled on a long-standing bug in qemu-nbd - it installs a SIGTERM handler, but not a SIGINT or SIGHUP handler. This matters in the following sequence:
qemu-nbd -f qcow2 -B bitmap image # Ctrl-C
qemu-nbd -f qcow2 -B bitmap imagebecause the first instance dies with SIGINT but there is no handler installed, qemu-nbd does not release the bitmap from being marked in-use, and the second instance then fails with:
qemu-nbd: Bitmap 'b0' is inconsistent and cannot be used
And to my surprise, while I was trying to find the root cause to fixing the bug I just found, I noticed that your patch happens to fix that...
Quoted 7 lines
+++
b/qemu-nbd.cqemu-nbd.c +1
-0@@ -581,20 +586,12 @@ int main(int argc, char **argv)const char *pid_file_name =NULL ;BlockExportOptions *export_opts; +os_setup_early_signal_handling ();qemu-nbd.c int main(int argc, char **argv) · line 592
Quoted 10 lines
qemu-nbd.c +2
-7+#if HAVE_NBD_DEVICE -/* The client thread uses SIGTERM to interrupt the server. A signal -* handler ensures that "qemu-nbd -v -c" exits with a nice status code. -*/ -struct sigaction sa_sigterm; -memset (&sa_sigterm,0 ,sizeof (sa_sigterm)); - sa_sigterm.sa_handler = termsig_handler; -sigaction (SIGTERM , &sa_sigterm,NULL ); +os_setup_signal_handling ();...by installing a SIGINT handler.
Quoted 4 lines
Is
HAVE_NBD_DEVICEreally the best gate for this code, or is it really whether we are compiling for mingw? At any rate, you may want to add a link to https://bugzilla.redhat.com/show_bug.cgi?id=1883608 in the commit message, and/or separate the bug fix out into a separate commit.
Thanks for letting me know about the bug report. The link can be added to the commit description when merging (or if I resend).
Stefan
PATCH v2 4/4 block/export: add iothread and fixed-iothread options
In reply to Stefan HajnocziMake it possible to specify the iothread where the export will run. By default the block node can be moved to other AioContexts later and the export will follow. The fixed-iothread option forces strict behavior that prevents changing AioContext while the export is active. See the QAPI docs for details.
---
Note the x-blockdev-set-iothread QMP command can be used to do the same, but not from the command-line. And it requires sending an additional command.
In the long run vhost-user-blk will support per-virtqueue iothread mappings. But for now a single iothread makes sense and most other transports will just use one iothread anyway.
--- qapi/block-export.json | 11 ++++++++++ block/export/export.c | 31 +++++++++++++++++++++++++++- block/export/vhost-user-blk-server.c | 5 ++++- nbd/server.c | 2 -- 4 files changed, 45 insertions(+), 4 deletions(-)
qapi/block-export.json +11 -0
@@ -219,11 +219,22 @@ # export before completion is signalled. (since: 5.2; # default: false) # +# @iothread: The name of the iothread object where the export will run. The +# default is to use the thread currently associated with the # +# block node. (since: 5.2) +# +# @fixed-iothread: True prevents the block node from being moved to another +# thread while the export is active. If true and @iothread is +# given, export creation fails if the block node cannot be +# moved to the iothread. The default is false. +# # Since: 4.2 ## { 'union': 'BlockExportOptions', 'base': { 'type': 'BlockExportType', 'id': 'str', + '*fixed-iothread': 'bool', + '*iothread': 'str', 'node-name': 'str', '*writable': 'bool', '*writethrough': 'bool' },
block/export/export.c +30 -1
@@ -15,6 +15,7 @@#include "block/block.h" #include "sysemu/block-backend.h" +#include "sysemu/iothread.h" #include "block/export.h" #include "block/nbd.h" #include "qapi/error.h"
@@ -63,10 +64,11 @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type)BlockExport *blk_exp_add (BlockExportOptions *export,Error **errp) { +bool fixed_iothread = export->has_fixed_iothread && export->fixed_iothread;const BlockExportDriver *drv;BlockExport *exp =NULL ;BlockDriverState *bs; -BlockBackend *blk; +BlockBackend *blk =NULL ;AioContext *ctx;uint64_t perm;int ret;
@@ -102,6 +104,28 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) ctx =bdrv_get_aio_context (bs);aio_context_acquire (ctx); +if (export->has_iothread) { +IOThread *iothread; +AioContext *new_ctx; + + iothread =iothread_by_id (export->iothread); +if (!iothread) { +error_setg (errp,"iothread \"%s\" not found" , export->iothread); + goto fail; + } + + new_ctx =iothread_get_aio_context (iothread); + + ret =bdrv_try_set_aio_context (bs, new_ctx, errp); +if (ret ==0 ) { +aio_context_release (ctx); +aio_context_acquire (new_ctx); + ctx = new_ctx; + }else if (fixed_iothread) { + goto fail; + } + } +/* * Block exports are used for non-shared storage migration. Make sure * that BDRV_O_INACTIVE is cleared and the image is ready for write
@@ -116,6 +140,11 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) } blk =blk_new (ctx, perm,BLK_PERM_ALL ); + +if (!fixed_iothread) { +blk_set_allow_aio_context_change (blk, true); + } + ret =blk_insert_bs (blk, bs, errp);if (ret <0 ) { goto fail;
block/export/vhost-user-blk-server.c +4 -1
@@ -323,13 +323,17 @@ static const VuDevIface vu_blk_iface = {static void blk_aio_attached (AioContext *ctx,void *opaque) {VuBlkExport *vexp = opaque; + + vexp->export.ctx = ctx;vhost_user_server_attach_aio_context (&vexp->vu_server, ctx); }static void blk_aio_detach (void *opaque) {VuBlkExport *vexp = opaque; +vhost_user_server_detach_aio_context (&vexp->vu_server); + vexp->export.ctx =NULL ; } static void
@@ -384,7 +388,6 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,vu_blk_initialize_config (blk_bs (exp->blk), &vexp->blkcfg, logical_block_size); -blk_set_allow_aio_context_change (exp->blk, true);blk_add_aio_context_notifier (exp->blk, blk_aio_attached, blk_aio_detach, vexp);
nbd/server.c +0 -2
@@ -1560,8 +1560,6 @@ static int nbd_export_create(BlockExport *blk_exp, BlockExportOptions *exp_args,return ret; } -blk_set_allow_aio_context_change (blk, true); -QTAILQ_INIT (&exp->clients); exp->name =g_strdup (arg->name); exp->description =g_strdup (arg->description);
Signature · 1 line
2.26.2
Re: [PATCH v2 4/4] block/export: add iothread and fixed-iothread options
Quoted 27 lines · Stefan Hajnoczi
Make it possible to specify the iothread where the export will run. By default the block node can be moved to other AioContexts later and the export will follow. The fixed-iothread option forces strict behavior that prevents changing AioContext while the export is active. See the QAPI docs for details.
Signed-off-by Stefan Hajnoczi <[email protected]>---
Note the x-blockdev-set-iothread QMP command can be used to do the same, but not from the command-line. And it requires sending an additional command.In the long run vhost-user-blk will support per-virtqueue iothread mappings. But for now a single iothread makes sense and most other transports will just use one iothread anyway.
--- qapi/block-export.json | 11 ++++++++++ block/export/export.c | 31 +++++++++++++++++++++++++++- block/export/vhost-user-blk-server.c | 5 ++++- nbd/server.c | 2 -- 4 files changed, 45 insertions(+), 4 deletions(-)qapi/block-export.json +0
-0
qapi/block-export.json line 223
Quoted 5 lines
qapi/block-export.json +2
-0@@ -219,11 +219,22 @@ # export before completion is signalled. (since: 5.2; # default: false) # +# @iothread: The name of the iothread object where the export will run. The +# default is to use the thread currently associated with the #
Stray #
qapi/block-export.json line 230
Quoted 7 lines
qapi/block-export.json +7
-0+# block node. (since: 5.2) +# +# @fixed-iothread: True prevents the block node from being moved to another +# thread while the export is active. If true and @iothread is +# given, export creation fails if the block node cannot be +# moved to the iothread. The default is false. +#
Missing a '(since 5.2)' tag. (Hmm, we're inconsistent on whether it is 'since 5.2' or 'since: 5.2' inside () parentheticals; Markus, is that something we should be cleaning up as part of the conversion to rST?)
qapi/block-export.json static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) · line 67
Quoted 5 lines
qapi/block-export.json +1
-0@@ -63,10 +64,11 @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { + bool fixed_iothread = export->has_fixed_iothread && export->fixed_iothread;
Technically, our QAPI code guarantees that export->fixed_iothread is false if export->has_fixed_iothread is false. And someday I'd love to let QAPI express default values for bools so that we don't need a has_FOO field when a default has been expressed. But neither of those points affect this patch; what you have is correct even if it is verbose.
Otherwise looks reasonable.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 4/4] block/export: add iothread and fixed-iothread options
Quoted 59 lines · Eric Blake
Quoted 27 lines · Stefan Hajnoczi
Make it possible to specify the iothread where the export will run. By default the block node can be moved to other AioContexts later and the export will follow. The fixed-iothread option forces strict behavior that prevents changing AioContext while the export is active. See the QAPI docs for details.
Signed-off-by Stefan Hajnoczi <[email protected]>---
Note the x-blockdev-set-iothread QMP command can be used to do the same, but not from the command-line. And it requires sending an additional command.In the long run vhost-user-blk will support per-virtqueue iothread mappings. But for now a single iothread makes sense and most other transports will just use one iothread anyway.
--- qapi/block-export.json | 11 ++++++++++ block/export/export.c | 31 +++++++++++++++++++++++++++- block/export/vhost-user-blk-server.c | 5 ++++- nbd/server.c | 2 -- 4 files changed, 45 insertions(+), 4 deletions(-)qapi/block-export.json +0
-0qapi/block-export.json line 223
Quoted 5 lines
qapi/block-export.json +2
-0@@ -219,11 +219,22 @@ # export before completion is signalled. (since: 5.2; # default: false) # +# @iothread: The name of the iothread object where the export will run. The +# default is to use the thread currently associated with the #Stray #
qapi/block-export.json line 230
Quoted 7 lines
qapi/block-export.json +7
-0+# block node. (since: 5.2) +# +# @fixed-iothread: True prevents the block node from being moved to another +# thread while the export is active. If true and @iothread is +# given, export creation fails if the block node cannot be +# moved to the iothread. The default is false. +#Missing a '(since 5.2)' tag. (Hmm, we're inconsistent on whether it is 'since 5.2' or 'since: 5.2' inside () parentheticals; Markus, is that something we should be cleaning up as part of the conversion to rST?)
qapi/block-export.json static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) · line 66
Quoted 4 lines
qapi/block-export.json +1
-0@@ -63,10 +64,11 @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { + bool fixed_iothread = export->has_fixed_iothread && export->fixed_iothread;Technically, our QAPI code guarantees that
export->fixed_iothreadis false ifexport->has_fixed_iothreadis false. And someday I'd love to let QAPI express default values for bools so that we don't need ahas_FOOfield when a default has been expressed. But neither of those points affect this patch; what you have is correct even if it is verbose.
Quoted 1 line
Otherwise looks reasonable.
Great, thanks for pointing this out.
I'll wait for comments from Kevin. These things could be fixed when merging.
Stefan
Stefan Hajnoczi
AppliedQuoted 16 lines · Stefan Hajnoczi
v2:
* Add fixed-iothread option to set AioContext change policy [Kevin]
* Useos-posix.csignal handling utilities inqemu-nbd.c[Paolo]This series adjusts the build system and then adds a
BlockExportOptions->iothreadmember so that it is possible to set the iothread for an export.Based-on: [email protected] ("[PATCH v2 00/13] block/export: convert vhost-user-blk-server to block exports API")
Stefan Hajnoczi (4):
util/vhost-user-server: use static library in meson.build
qemu-storage-daemon: avoid compilingblockdev_sstwice
block: move block exports to libblockdev block/export: add iothread and fixed-iothread options
Quoted 20 lines
qapi/block-export.json | 11 ++++++++ block/export/export.c | 39 ++++++++++++++++++++++++---- block/export/vhost-user-blk-server.c | 5 +++- nbd/server.c | 2 -- qemu-nbd.c | 21 +++++++-------- stubs/blk-exp-close-all.c | 7 +++++ block/export/meson.build | 4 +-- contrib/libvhost-user/meson.build | 1 + meson.build | 22 ++++++++++++---- nbd/meson.build | 2 ++ storage-daemon/meson.build | 3 +-- stubs/meson.build | 1 + tests/qtest/meson.build | 2 +- util/meson.build | 4 ++- 14 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 stubs/blk-exp-close-all.cSignature · 1 line
2.26.2
Thanks, applied to my block tree with Eric's suggestions applied:
https://github.com/stefanha/qemu/commits/block
Stefan