|
@@ -253,6 +253,12 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+struct NbdClientOpts {
|
|
|
|
+ char *device;
|
|
|
|
+ bool fork_process;
|
|
|
|
+ bool verbose;
|
|
|
|
+};
|
|
|
|
+
|
|
#if HAVE_NBD_DEVICE
|
|
#if HAVE_NBD_DEVICE
|
|
static void *show_parts(void *arg)
|
|
static void *show_parts(void *arg)
|
|
{
|
|
{
|
|
@@ -271,12 +277,6 @@ static void *show_parts(void *arg)
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
-struct NbdClientOpts {
|
|
|
|
- char *device;
|
|
|
|
- bool fork_process;
|
|
|
|
- bool verbose;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
static void *nbd_client_thread(void *arg)
|
|
static void *nbd_client_thread(void *arg)
|
|
{
|
|
{
|
|
struct NbdClientOpts *opts = arg;
|
|
struct NbdClientOpts *opts = arg;
|
|
@@ -519,7 +519,6 @@ int main(int argc, char **argv)
|
|
const char *bindto = NULL;
|
|
const char *bindto = NULL;
|
|
const char *port = NULL;
|
|
const char *port = NULL;
|
|
char *sockpath = NULL;
|
|
char *sockpath = NULL;
|
|
- char *device = NULL;
|
|
|
|
QemuOpts *sn_opts = NULL;
|
|
QemuOpts *sn_opts = NULL;
|
|
const char *sn_id_or_name = NULL;
|
|
const char *sn_id_or_name = NULL;
|
|
const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L";
|
|
const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L";
|
|
@@ -582,16 +581,16 @@ int main(int argc, char **argv)
|
|
const char *tlshostname = NULL;
|
|
const char *tlshostname = NULL;
|
|
bool imageOpts = false;
|
|
bool imageOpts = false;
|
|
bool writethrough = false; /* Client will flush as needed. */
|
|
bool writethrough = false; /* Client will flush as needed. */
|
|
- bool verbose = false;
|
|
|
|
- bool fork_process = false;
|
|
|
|
bool list = false;
|
|
bool list = false;
|
|
unsigned socket_activation;
|
|
unsigned socket_activation;
|
|
const char *pid_file_name = NULL;
|
|
const char *pid_file_name = NULL;
|
|
const char *selinux_label = NULL;
|
|
const char *selinux_label = NULL;
|
|
BlockExportOptions *export_opts;
|
|
BlockExportOptions *export_opts;
|
|
-#if HAVE_NBD_DEVICE
|
|
|
|
- struct NbdClientOpts opts;
|
|
|
|
-#endif
|
|
|
|
|
|
+ struct NbdClientOpts opts = {
|
|
|
|
+ .fork_process = false,
|
|
|
|
+ .verbose = false,
|
|
|
|
+ .device = NULL,
|
|
|
|
+ };
|
|
|
|
|
|
#ifdef CONFIG_POSIX
|
|
#ifdef CONFIG_POSIX
|
|
os_setup_early_signal_handling();
|
|
os_setup_early_signal_handling();
|
|
@@ -719,7 +718,7 @@ int main(int argc, char **argv)
|
|
disconnect = true;
|
|
disconnect = true;
|
|
break;
|
|
break;
|
|
case 'c':
|
|
case 'c':
|
|
- device = optarg;
|
|
|
|
|
|
+ opts.device = optarg;
|
|
break;
|
|
break;
|
|
case 'e':
|
|
case 'e':
|
|
if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 ||
|
|
if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 ||
|
|
@@ -750,7 +749,7 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case 'v':
|
|
case 'v':
|
|
- verbose = true;
|
|
|
|
|
|
+ opts.verbose = true;
|
|
break;
|
|
break;
|
|
case 'V':
|
|
case 'V':
|
|
version(argv[0]);
|
|
version(argv[0]);
|
|
@@ -782,7 +781,7 @@ int main(int argc, char **argv)
|
|
tlsauthz = optarg;
|
|
tlsauthz = optarg;
|
|
break;
|
|
break;
|
|
case QEMU_NBD_OPT_FORK:
|
|
case QEMU_NBD_OPT_FORK:
|
|
- fork_process = true;
|
|
|
|
|
|
+ opts.fork_process = true;
|
|
break;
|
|
break;
|
|
case 'L':
|
|
case 'L':
|
|
list = true;
|
|
list = true;
|
|
@@ -802,12 +801,12 @@ int main(int argc, char **argv)
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
if (export_name || export_description || dev_offset ||
|
|
if (export_name || export_description || dev_offset ||
|
|
- device || disconnect || fmt || sn_id_or_name || bitmaps ||
|
|
|
|
|
|
+ opts.device || disconnect || fmt || sn_id_or_name || bitmaps ||
|
|
alloc_depth || seen_aio || seen_discard || seen_cache) {
|
|
alloc_depth || seen_aio || seen_discard || seen_cache) {
|
|
error_report("List mode is incompatible with per-device settings");
|
|
error_report("List mode is incompatible with per-device settings");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
- if (fork_process) {
|
|
|
|
|
|
+ if (opts.fork_process) {
|
|
error_report("List mode is incompatible with forking");
|
|
error_report("List mode is incompatible with forking");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
@@ -832,7 +831,8 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
/* Using socket activation - check user didn't use -p etc. */
|
|
/* Using socket activation - check user didn't use -p etc. */
|
|
- const char *err_msg = socket_activation_validate_opts(device, sockpath,
|
|
|
|
|
|
+ const char *err_msg = socket_activation_validate_opts(opts.device,
|
|
|
|
+ sockpath,
|
|
bindto, port,
|
|
bindto, port,
|
|
selinux_label,
|
|
selinux_label,
|
|
list);
|
|
list);
|
|
@@ -850,7 +850,7 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
|
|
|
|
if (tlscredsid) {
|
|
if (tlscredsid) {
|
|
- if (device) {
|
|
|
|
|
|
+ if (opts.device) {
|
|
error_report("TLS is not supported with a host device");
|
|
error_report("TLS is not supported with a host device");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
@@ -880,7 +880,7 @@ int main(int argc, char **argv)
|
|
|
|
|
|
if (selinux_label) {
|
|
if (selinux_label) {
|
|
#ifdef CONFIG_SELINUX
|
|
#ifdef CONFIG_SELINUX
|
|
- if (sockpath == NULL && device == NULL) {
|
|
|
|
|
|
+ if (sockpath == NULL && opts.device == NULL) {
|
|
error_report("--selinux-label is not permitted without --socket");
|
|
error_report("--selinux-label is not permitted without --socket");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
@@ -897,7 +897,7 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
|
|
|
|
#if !HAVE_NBD_DEVICE
|
|
#if !HAVE_NBD_DEVICE
|
|
- if (disconnect || device) {
|
|
|
|
|
|
+ if (disconnect || opts.device) {
|
|
error_report("Kernel /dev/nbdN support not available");
|
|
error_report("Kernel /dev/nbdN support not available");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
@@ -919,7 +919,7 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- if ((device && !verbose) || fork_process) {
|
|
|
|
|
|
+ if ((opts.device && !opts.verbose) || opts.fork_process) {
|
|
#ifndef WIN32
|
|
#ifndef WIN32
|
|
g_autoptr(GError) err = NULL;
|
|
g_autoptr(GError) err = NULL;
|
|
int stderr_fd[2];
|
|
int stderr_fd[2];
|
|
@@ -1002,9 +1002,9 @@ int main(int argc, char **argv)
|
|
#endif /* WIN32 */
|
|
#endif /* WIN32 */
|
|
}
|
|
}
|
|
|
|
|
|
- if (device != NULL && sockpath == NULL) {
|
|
|
|
|
|
+ if (opts.device != NULL && sockpath == NULL) {
|
|
sockpath = g_malloc(128);
|
|
sockpath = g_malloc(128);
|
|
- snprintf(sockpath, 128, SOCKET_PATH, basename(device));
|
|
|
|
|
|
+ snprintf(sockpath, 128, SOCKET_PATH, basename(opts.device));
|
|
}
|
|
}
|
|
|
|
|
|
server = qio_net_listener_new();
|
|
server = qio_net_listener_new();
|
|
@@ -1145,15 +1145,9 @@ int main(int argc, char **argv)
|
|
blk_exp_add(export_opts, &error_fatal);
|
|
blk_exp_add(export_opts, &error_fatal);
|
|
qapi_free_BlockExportOptions(export_opts);
|
|
qapi_free_BlockExportOptions(export_opts);
|
|
|
|
|
|
- if (device) {
|
|
|
|
|
|
+ if (opts.device) {
|
|
#if HAVE_NBD_DEVICE
|
|
#if HAVE_NBD_DEVICE
|
|
int ret;
|
|
int ret;
|
|
- opts = (struct NbdClientOpts) {
|
|
|
|
- .device = device,
|
|
|
|
- .fork_process = fork_process,
|
|
|
|
- .verbose = verbose,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
ret = pthread_create(&client_thread, NULL, nbd_client_thread, &opts);
|
|
ret = pthread_create(&client_thread, NULL, nbd_client_thread, &opts);
|
|
if (ret != 0) {
|
|
if (ret != 0) {
|
|
error_report("Failed to create client thread: %s", strerror(ret));
|
|
error_report("Failed to create client thread: %s", strerror(ret));
|
|
@@ -1179,7 +1173,7 @@ int main(int argc, char **argv)
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
- if (fork_process) {
|
|
|
|
|
|
+ if (opts.fork_process) {
|
|
if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) {
|
|
if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) {
|
|
error_report("Could not release pipe to parent: %s",
|
|
error_report("Could not release pipe to parent: %s",
|
|
strerror(errno));
|
|
strerror(errno));
|
|
@@ -1203,7 +1197,7 @@ int main(int argc, char **argv)
|
|
|
|
|
|
qemu_opts_del(sn_opts);
|
|
qemu_opts_del(sn_opts);
|
|
|
|
|
|
- if (device) {
|
|
|
|
|
|
+ if (opts.device) {
|
|
void *ret;
|
|
void *ret;
|
|
pthread_join(client_thread, &ret);
|
|
pthread_join(client_thread, &ret);
|
|
exit(ret != NULL);
|
|
exit(ret != NULL);
|