From: Stefan Hajnoczi <stefanha@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-block@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
"Coiby Xu" <Coiby.Xu@gmail.com>, "Max Reitz" <mreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Fam Zheng" <fam@euphon.net>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: [PULL v2 22/30] block: move block exports to libblockdev
Date: Mon, 12 Oct 2020 19:27:52 +0100 [thread overview]
Message-ID: <20201012182800.157697-23-stefanha@redhat.com> (raw)
In-Reply-To: <20201012182800.157697-1-stefanha@redhat.com>
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.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-nbd.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.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20200929125516.186715-4-stefanha@redhat.com
[Fixed s/ndb/nbd/ typo in commit description as suggested by Eric Blake
--Stefan]
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
qemu-nbd.c | 25 +++++++++----------------
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(+), 20 deletions(-)
create mode 100644 stubs/blk-exp-close-all.c
diff --git a/qemu-nbd.c b/qemu-nbd.c
index bc644a0670..369b00e3b9 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -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"
@@ -154,8 +155,12 @@ QEMU_COPYRIGHT "\n"
, name);
}
-#ifdef CONFIG_POSIX
-static void termsig_handler(int signum)
+#if CONFIG_POSIX
+/*
+ * 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)
{
qatomic_cmpxchg(&state, RUNNING, TERMINATE);
qemu_notify_event();
@@ -581,20 +586,8 @@ int main(int argc, char **argv)
const char *pid_file_name = NULL;
BlockExportOptions *export_opts;
-#ifdef CONFIG_POSIX
- /*
- * Exit gracefully on various signals, which includes SIGTERM used
- * by 'qemu-nbd -v -c'.
- */
- struct sigaction sa_sigterm;
- memset(&sa_sigterm, 0, sizeof(sa_sigterm));
- sa_sigterm.sa_handler = termsig_handler;
- sigaction(SIGTERM, &sa_sigterm, NULL);
- sigaction(SIGINT, &sa_sigterm, NULL);
- sigaction(SIGHUP, &sa_sigterm, NULL);
-
- signal(SIGPIPE, SIG_IGN);
-#endif
+ os_setup_early_signal_handling();
+ os_setup_signal_handling();
socket_init();
error_init(argv[0]);
diff --git a/stubs/blk-exp-close-all.c b/stubs/blk-exp-close-all.c
new file mode 100644
index 0000000000..1c71316763
--- /dev/null
+++ b/stubs/blk-exp-close-all.c
@@ -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)
+{
+}
diff --git a/block/export/meson.build b/block/export/meson.build
index 469a7aa0f5..a2772a0dce 100644
--- a/block/export/meson.build
+++ b/block/export/meson.build
@@ -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'))
diff --git a/meson.build b/meson.build
index 2fb0bb7cb4..9964ed43a1 100644
--- a/meson.build
+++ b/meson.build
@@ -1344,7 +1344,6 @@ subdir('dump')
block_ss.add(files(
'block.c',
- 'blockdev-nbd.c',
'blockjob.c',
'job.c',
'qemu-io-cmds.c',
@@ -1357,6 +1356,7 @@ subdir('block')
blockdev_ss.add(files(
'blockdev.c',
+ 'blockdev-nbd.c',
'iothread.c',
'job-qmp.c',
))
@@ -1682,7 +1682,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')
diff --git a/nbd/meson.build b/nbd/meson.build
index 0c00a776d3..2baaa36948 100644
--- a/nbd/meson.build
+++ b/nbd/meson.build
@@ -1,5 +1,7 @@
block_ss.add(files(
'client.c',
'common.c',
+))
+blockdev_ss.add(files(
'server.c',
))
diff --git a/stubs/meson.build b/stubs/meson.build
index 67f2a8c069..7b733fadb7 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -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('cmos.c'))
--
2.26.2
next prev parent reply other threads:[~2020-10-12 18:43 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-12 18:27 [PULL v2 00/30] Block patches Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 01/30] block/nvme: Add driver statistics for access alignment and hw errors Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 02/30] libvhost-user: Allow vu_message_read to be replaced Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 03/30] libvhost-user: remove watch for kick_fd when de-initialize vu-dev Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 04/30] util/vhost-user-server: generic vhost user server Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 05/30] block: move logical block size check function to a common utility function Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 06/30] block/export: vhost-user block device backend server Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 07/30] test: new qTest case to test the vhost-user-blk-server Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 08/30] MAINTAINERS: Add vhost-user block device backend server maintainer Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 09/30] util/vhost-user-server: s/fileds/fields/ typo fix Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 10/30] util/vhost-user-server: drop unnecessary QOM cast Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 11/30] util/vhost-user-server: drop unnecessary watch deletion Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 12/30] block/export: consolidate request structs into VuBlockReq Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 13/30] util/vhost-user-server: drop unused DevicePanicNotifier Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 14/30] util/vhost-user-server: fix memory leak in vu_message_read() Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 15/30] util/vhost-user-server: check EOF when reading payload Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 16/30] util/vhost-user-server: rework vu_client_trip() coroutine lifecycle Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 17/30] block/export: report flush errors Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 18/30] block/export: convert vhost-user-blk server to block export API Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 19/30] util/vhost-user-server: move header to include/ Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 20/30] util/vhost-user-server: use static library in meson.build Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 21/30] qemu-storage-daemon: avoid compiling blockdev_ss twice Stefan Hajnoczi
2020-10-12 18:27 ` Stefan Hajnoczi [this message]
2020-10-12 18:27 ` [PULL v2 23/30] block/export: add iothread and fixed-iothread options Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 24/30] block/export: add vhost-user-blk multi-queue support Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 25/30] tests/qtest: add multi-queue test case to vhost-user-blk-test Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 26/30] block/io: fix bdrv_co_block_status_above Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 27/30] block/io: bdrv_common_block_status_above: support include_base Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 28/30] block/io: bdrv_common_block_status_above: support bs == base Stefan Hajnoczi
2020-10-12 18:27 ` [PULL v2 29/30] block/io: fix bdrv_is_allocated_above Stefan Hajnoczi
2020-10-12 18:28 ` [PULL v2 30/30] iotests: add commit top->base cases to 274 Stefan Hajnoczi
2020-10-12 19:00 ` [PULL v2 00/30] Block patches no-reply
2020-10-12 21:48 ` Peter Maydell
2020-10-13 0:05 ` Eric Blake
2020-10-20 15:19 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201012182800.157697-23-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=Coiby.Xu@gmail.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=crosa@redhat.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=lvivier@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).