block: Move common QMP commands to block-core QAPI module
[qemu/ar7.git] / qemu-storage-daemon.c
blobfc4aef572bde9389d6f5fca448f76c3141ca2886
1 /*
2 * QEMU storage daemon
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 * Copyright (c) 2019 Kevin Wolf <kwolf@redhat.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
26 #include "qemu/osdep.h"
28 #include <getopt.h>
30 #include "block/block.h"
31 #include "crypto/init.h"
33 #include "qapi/error.h"
34 #include "qemu-common.h"
35 #include "qemu-version.h"
36 #include "qemu/config-file.h"
37 #include "qemu/error-report.h"
38 #include "qemu/log.h"
39 #include "qemu/main-loop.h"
40 #include "qemu/module.h"
42 #include "trace/control.h"
44 static void help(void)
46 printf(
47 "Usage: %s [options]\n"
48 "QEMU storage daemon\n"
49 "\n"
50 " -h, --help display this help and exit\n"
51 " -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
52 " specify tracing options\n"
53 " -V, --version output version information and exit\n"
54 "\n"
55 QEMU_HELP_BOTTOM "\n",
56 error_get_progname());
59 static void process_options(int argc, char *argv[])
61 int c;
63 static const struct option long_options[] = {
64 {"help", no_argument, NULL, 'h'},
65 {"trace", required_argument, NULL, 'T'},
66 {"version", no_argument, NULL, 'V'},
67 {0, 0, 0, 0}
71 * In contrast to the system emulator, options are processed in the order
72 * they are given on the command lines. This means that things must be
73 * defined first before they can be referenced in another option.
75 while ((c = getopt_long(argc, argv, "hT:V", long_options, NULL)) != -1) {
76 switch (c) {
77 case '?':
78 exit(EXIT_FAILURE);
79 case 'h':
80 help();
81 exit(EXIT_SUCCESS);
82 case 'T':
84 char *trace_file = trace_opt_parse(optarg);
85 trace_init_file(trace_file);
86 g_free(trace_file);
87 break;
89 case 'V':
90 printf("qemu-storage-daemon version "
91 QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n");
92 exit(EXIT_SUCCESS);
93 default:
94 g_assert_not_reached();
97 if (optind != argc) {
98 error_report("Unexpected argument: %s", argv[optind]);
99 exit(EXIT_FAILURE);
103 int main(int argc, char *argv[])
105 #ifdef CONFIG_POSIX
106 signal(SIGPIPE, SIG_IGN);
107 #endif
109 error_init(argv[0]);
110 qemu_init_exec_dir(argv[0]);
112 module_call_init(MODULE_INIT_QOM);
113 module_call_init(MODULE_INIT_TRACE);
114 qemu_add_opts(&qemu_trace_opts);
115 qcrypto_init(&error_fatal);
116 bdrv_init();
118 if (!trace_init_backends()) {
119 return EXIT_FAILURE;
121 qemu_set_log(LOG_TRACE);
123 qemu_init_main_loop(&error_fatal);
124 process_options(argc, argv);
126 return EXIT_SUCCESS;