"\n"
"Exposing part of the image:\n"
" -o, --offset=OFFSET offset into the image\n"
+" -A, --allocation-depth expose the allocation depth\n"
" -B, --bitmap=NAME expose a persistent dirty bitmap\n"
"\n"
"General purpose options:\n"
sioc = qio_channel_socket_new();
if (qio_channel_socket_connect_sync(sioc, saddr, &err) < 0) {
error_report_err(err);
- return EXIT_FAILURE;
+ goto out;
}
rc = nbd_receive_export_list(QIO_CHANNEL(sioc), tls, hostname, &list,
&err);
char *device = arg;
NBDExportInfo info = { .request_sizes = false, .name = g_strdup("") };
QIOChannelSocket *sioc;
- int fd;
- int ret;
+ int fd = -1;
+ int ret = EXIT_FAILURE;
pthread_t show_parts_thread;
Error *local_error = NULL;
goto out;
}
- ret = nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc),
- NULL, NULL, NULL, &info, &local_error);
- if (ret < 0) {
+ if (nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc),
+ NULL, NULL, NULL, &info, &local_error) < 0) {
if (local_error) {
error_report_err(local_error);
}
- goto out_socket;
+ goto out;
}
fd = open(device, O_RDWR);
if (fd < 0) {
/* Linux-only, we can use %m in printf. */
error_report("Failed to open %s: %m", device);
- goto out_socket;
+ goto out;
}
- ret = nbd_init(fd, sioc, &info, &local_error);
- if (ret < 0) {
+ if (nbd_init(fd, sioc, &info, &local_error) < 0) {
error_report_err(local_error);
- goto out_fd;
+ goto out;
}
/* update partition table */
dup2(STDOUT_FILENO, STDERR_FILENO);
}
- ret = nbd_client(fd);
- if (ret) {
- goto out_fd;
+ if (nbd_client(fd) < 0) {
+ goto out;
}
- close(fd);
- object_unref(OBJECT(sioc));
- g_free(info.name);
- kill(getpid(), SIGTERM);
- return (void *) EXIT_SUCCESS;
-out_fd:
- close(fd);
-out_socket:
+ ret = EXIT_SUCCESS;
+
+ out:
+ if (fd >= 0) {
+ close(fd);
+ }
object_unref(OBJECT(sioc));
-out:
g_free(info.name);
kill(getpid(), SIGTERM);
- return (void *) EXIT_FAILURE;
+ return (void *) (intptr_t) ret;
}
#endif /* HAVE_NBD_DEVICE */
static int nbd_can_accept(void)
{
- return state == RUNNING && nb_fds < shared;
+ return state == RUNNING && (shared == 0 || nb_fds < shared);
}
static void nbd_update_server_watch(void);
},
};
-static QemuOptsList qemu_object_opts = {
- .name = "object",
- .implied_opt_name = "qom-type",
- .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
- .desc = {
- { }
- },
-};
-
-static bool qemu_nbd_object_print_help(const char *type, QemuOpts *opts)
-{
- if (user_creatable_print_help(type, opts)) {
- exit(0);
- }
- return true;
-}
-
-
static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, bool list,
Error **errp)
{
static void qemu_nbd_shutdown(void)
{
job_cancel_sync_all();
+ blk_exp_close_all();
bdrv_close_all();
}
char *device = NULL;
QemuOpts *sn_opts = NULL;
const char *sn_id_or_name = NULL;
- const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:B:L";
+ const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L";
struct option lopt[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "socket", required_argument, NULL, 'k' },
{ "offset", required_argument, NULL, 'o' },
{ "read-only", no_argument, NULL, 'r' },
+ { "allocation-depth", no_argument, NULL, 'A' },
{ "bitmap", required_argument, NULL, 'B' },
{ "connect", required_argument, NULL, 'c' },
{ "disconnect", no_argument, NULL, 'd' },
QDict *options = NULL;
const char *export_name = NULL; /* defaults to "" later for server mode */
const char *export_description = NULL;
- const char *bitmap = NULL;
+ strList *bitmaps = NULL;
+ bool alloc_depth = false;
const char *tlscredsid = NULL;
bool imageOpts = false;
bool writethrough = true;
- char *trace_file = NULL;
bool fork_process = false;
bool list = false;
int old_stderr = -1;
qcrypto_init(&error_fatal);
module_call_init(MODULE_INIT_QOM);
- qemu_add_opts(&qemu_object_opts);
qemu_add_opts(&qemu_trace_opts);
qemu_init_exec_dir(argv[0]);
readonly = true;
flags &= ~BDRV_O_RDWR;
break;
+ case 'A':
+ alloc_depth = true;
+ break;
case 'B':
- bitmap = optarg;
+ QAPI_LIST_PREPEND(bitmaps, g_strdup(optarg));
break;
case 'k':
sockpath = optarg;
break;
case 'e':
if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 ||
- shared < 1) {
+ shared < 0) {
error_report("Invalid shared device number '%s'", optarg);
exit(EXIT_FAILURE);
}
case '?':
error_report("Try `%s --help' for more information.", argv[0]);
exit(EXIT_FAILURE);
- case QEMU_NBD_OPT_OBJECT: {
- QemuOpts *opts;
- opts = qemu_opts_parse_noisily(&qemu_object_opts,
- optarg, true);
- if (!opts) {
- exit(EXIT_FAILURE);
- }
- } break;
+ case QEMU_NBD_OPT_OBJECT:
+ user_creatable_process_cmdline(optarg);
+ break;
case QEMU_NBD_OPT_TLSCREDS:
tlscredsid = optarg;
break;
imageOpts = true;
break;
case 'T':
- g_free(trace_file);
- trace_file = trace_opt_parse(optarg);
+ trace_opt_parse(optarg);
break;
case QEMU_NBD_OPT_TLSAUTHZ:
tlsauthz = optarg;
exit(EXIT_FAILURE);
}
if (export_name || export_description || dev_offset ||
- device || disconnect || fmt || sn_id_or_name || bitmap ||
- seen_aio || seen_discard || seen_cache) {
+ device || disconnect || fmt || sn_id_or_name || bitmaps ||
+ alloc_depth || seen_aio || seen_discard || seen_cache) {
error_report("List mode is incompatible with per-device settings");
exit(EXIT_FAILURE);
}
export_name = "";
}
- qemu_opts_foreach(&qemu_object_opts,
- user_creatable_add_opts_foreach,
- qemu_nbd_object_print_help, &error_fatal);
-
if (!trace_init_backends()) {
exit(1);
}
- trace_init_file(trace_file);
+ trace_init_file();
qemu_set_log(LOG_TRACE);
socket_activation = check_socket_activation();
server = qio_net_listener_new();
if (socket_activation == 0) {
+ int backlog;
+
+ if (persistent || shared == 0) {
+ backlog = SOMAXCONN;
+ } else {
+ backlog = MIN(shared, SOMAXCONN);
+ }
saddr = nbd_build_socket_address(sockpath, bindto, port);
- if (qio_net_listener_open_sync(server, saddr, 1, &local_err) < 0) {
+ if (qio_net_listener_open_sync(server, saddr, backlog,
+ &local_err) < 0) {
object_unref(OBJECT(server));
error_report_err(local_err);
exit(EXIT_FAILURE);
.has_writable = true,
.writable = !readonly,
.u.nbd = {
- .has_name = true,
- .name = g_strdup(export_name),
- .has_description = !!export_description,
- .description = g_strdup(export_description),
- .has_bitmap = !!bitmap,
- .bitmap = g_strdup(bitmap),
+ .has_name = true,
+ .name = g_strdup(export_name),
+ .has_description = !!export_description,
+ .description = g_strdup(export_description),
+ .has_bitmaps = !!bitmaps,
+ .bitmaps = bitmaps,
+ .has_allocation_depth = alloc_depth,
+ .allocation_depth = alloc_depth,
},
};
blk_exp_add(export_opts, &error_fatal);