[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 08/23] qemu-nbd: Add --fork option
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 08/23] qemu-nbd: Add --fork option |
Date: |
Mon, 24 Oct 2016 19:01:56 +0200 |
From: Max Reitz <address@hidden>
Using the --fork option, one can make qemu-nbd fork the worker process.
The original process will exit on error of the worker or once the worker
enters the main loop.
Suggested-by: Sascha Silbe <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-nbd.c | 17 ++++++++++++++++-
qemu-nbd.texi | 2 ++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index cca4a98..b757dc7 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -48,6 +48,7 @@
#define QEMU_NBD_OPT_OBJECT 260
#define QEMU_NBD_OPT_TLSCREDS 261
#define QEMU_NBD_OPT_IMAGE_OPTS 262
+#define QEMU_NBD_OPT_FORK 263
#define MBR_SIZE 512
@@ -92,6 +93,8 @@ static void usage(const char *name)
" passwords and/or encryption keys\n"
" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
" specify tracing options\n"
+" --fork fork off the server process and exit the parent\n"
+" once the server is running\n"
#ifdef __linux__
"Kernel NBD client support:\n"
" -c, --connect=DEV connect FILE to the local NBD device DEV\n"
@@ -503,6 +506,7 @@ int main(int argc, char **argv)
{ "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS },
{ "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
{ "trace", required_argument, NULL, 'T' },
+ { "fork", no_argument, NULL, QEMU_NBD_OPT_FORK },
{ NULL, 0, NULL, 0 }
};
int ch;
@@ -524,6 +528,8 @@ int main(int argc, char **argv)
bool imageOpts = false;
bool writethrough = true;
char *trace_file = NULL;
+ bool fork_process = false;
+ int old_stderr = -1;
/* The client thread uses SIGTERM to interrupt the server. A signal
* handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -715,6 +721,9 @@ int main(int argc, char **argv)
g_free(trace_file);
trace_file = trace_opt_parse(optarg);
break;
+ case QEMU_NBD_OPT_FORK:
+ fork_process = true;
+ break;
}
}
@@ -774,7 +783,7 @@ int main(int argc, char **argv)
return 0;
}
- if (device && !verbose) {
+ if ((device && !verbose) || fork_process) {
int stderr_fd[2];
pid_t pid;
int ret;
@@ -797,6 +806,7 @@ int main(int argc, char **argv)
ret = qemu_daemon(1, 0);
/* Temporarily redirect stderr to the parent's pipe... */
+ old_stderr = dup(STDERR_FILENO);
dup2(stderr_fd[1], STDERR_FILENO);
if (ret < 0) {
error_report("Failed to daemonize: %s", strerror(errno));
@@ -960,6 +970,11 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ if (fork_process) {
+ dup2(old_stderr, STDERR_FILENO);
+ close(old_stderr);
+ }
+
state = RUNNING;
do {
main_loop_wait(false);
diff --git a/qemu-nbd.texi b/qemu-nbd.texi
index 91ebf04..b7a9c6d 100644
--- a/qemu-nbd.texi
+++ b/qemu-nbd.texi
@@ -86,6 +86,8 @@ the new style NBD protocol negotiation
Enable mandatory TLS encryption for the server by setting the ID
of the TLS credentials object previously created with the --object
option.
address@hidden --fork
+Fork off the server process and exit the parent once the server is running.
@item -v, --verbose
Display extra debugging information
@item -h, --help
--
1.8.3.1
- [Qemu-block] [PULL 00/23] Block layer patches, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 01/23] block: failed qemu-img command should return non-zero exit code, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 04/23] block: improve error handling in raw_open, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 02/23] qcow2: Support BDRV_REQ_MAY_UNMAP, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 03/23] block: Remove "options" indirection from blockdev-add, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 05/23] qapi: fix memory leak in bdrv_image_info_specific_dump, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 08/23] qemu-nbd: Add --fork option,
Kevin Wolf <=
- [Qemu-block] [PULL 09/23] iotests: Remove raciness from 162, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 10/23] iotests: Do not rely on unavailable domains in 162, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 06/23] throttle: Correct access to wrong BlockBackendPublic structures, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 07/23] qemu-iotests: Test I/O in a single drive from a throttling group, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 13/23] block: Hide HBitmap in block dirty bitmap interface, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 11/23] quorum: change child_iter to children_read, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 16/23] block: Support meta dirty bitmap, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 17/23] block: Add two dirty bitmap getters, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 18/23] block: Assert that bdrv_release_dirty_bitmap succeeded, Kevin Wolf, 2016/10/24
- [Qemu-block] [PULL 15/23] tests: Add test code for meta bitmap, Kevin Wolf, 2016/10/24