qemu-nbd.c (1c3d45df5e94042d5fb2bb31416072563ab30e49) qemu-nbd.c (b25e12daff2c3e5ba933f85e8ba278f5bcba8f4d)
1/*
2 * Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
3 *
4 * Network Block Device
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.

--- 44 unchanged lines hidden (view full) ---

53#define QEMU_NBD_OPT_CACHE 256
54#define QEMU_NBD_OPT_AIO 257
55#define QEMU_NBD_OPT_DISCARD 258
56#define QEMU_NBD_OPT_DETECT_ZEROES 259
57#define QEMU_NBD_OPT_OBJECT 260
58#define QEMU_NBD_OPT_TLSCREDS 261
59#define QEMU_NBD_OPT_IMAGE_OPTS 262
60#define QEMU_NBD_OPT_FORK 263
1/*
2 * Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
3 *
4 * Network Block Device
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.

--- 44 unchanged lines hidden (view full) ---

53#define QEMU_NBD_OPT_CACHE 256
54#define QEMU_NBD_OPT_AIO 257
55#define QEMU_NBD_OPT_DISCARD 258
56#define QEMU_NBD_OPT_DETECT_ZEROES 259
57#define QEMU_NBD_OPT_OBJECT 260
58#define QEMU_NBD_OPT_TLSCREDS 261
59#define QEMU_NBD_OPT_IMAGE_OPTS 262
60#define QEMU_NBD_OPT_FORK 263
61#define QEMU_NBD_OPT_TLSAUTHZ 264
61
62#define MBR_SIZE 512
63
64static NBDExport *export;
65static int verbose;
66static char *srcpath;
67static SocketAddress *saddr;
68static int persistent = 0;
69static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state;
70static int shared = 1;
71static int nb_fds;
72static QIONetListener *server;
73static QCryptoTLSCreds *tlscreds;
62
63#define MBR_SIZE 512
64
65static NBDExport *export;
66static int verbose;
67static char *srcpath;
68static SocketAddress *saddr;
69static int persistent = 0;
70static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state;
71static int shared = 1;
72static int nb_fds;
73static QIONetListener *server;
74static QCryptoTLSCreds *tlscreds;
75static const char *tlsauthz;
74
75static void usage(const char *name)
76{
77 (printf) (
78"Usage: %s [OPTIONS] FILE\n"
79" or: %s -L [OPTIONS]\n"
80"QEMU Disk Network Block Device Utility\n"
81"\n"

--- 16 unchanged lines hidden (view full) ---

98" -P, --partition=NUM only expose partition NUM\n"
99" -B, --bitmap=NAME expose a persistent dirty bitmap\n"
100"\n"
101"General purpose options:\n"
102" -L, --list list exports available from another NBD server\n"
103" --object type,id=ID,... define an object such as 'secret' for providing\n"
104" passwords and/or encryption keys\n"
105" --tls-creds=ID use id of an earlier --object to provide TLS\n"
76
77static void usage(const char *name)
78{
79 (printf) (
80"Usage: %s [OPTIONS] FILE\n"
81" or: %s -L [OPTIONS]\n"
82"QEMU Disk Network Block Device Utility\n"
83"\n"

--- 16 unchanged lines hidden (view full) ---

100" -P, --partition=NUM only expose partition NUM\n"
101" -B, --bitmap=NAME expose a persistent dirty bitmap\n"
102"\n"
103"General purpose options:\n"
104" -L, --list list exports available from another NBD server\n"
105" --object type,id=ID,... define an object such as 'secret' for providing\n"
106" passwords and/or encryption keys\n"
107" --tls-creds=ID use id of an earlier --object to provide TLS\n"
108" --tls-authz=ID use id of an earlier --object to provide\n"
109" authorization\n"
106" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
107" specify tracing options\n"
108" --fork fork off the server process and exit the parent\n"
109" once the server is running\n"
110#if HAVE_NBD_DEVICE
111"\n"
112"Kernel NBD client support:\n"
113" -c, --connect=DEV connect FILE to the local NBD device DEV\n"

--- 333 unchanged lines hidden (view full) ---

447 gpointer opaque)
448{
449 if (state >= TERMINATE) {
450 return;
451 }
452
453 nb_fds++;
454 nbd_update_server_watch();
110" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
111" specify tracing options\n"
112" --fork fork off the server process and exit the parent\n"
113" once the server is running\n"
114#if HAVE_NBD_DEVICE
115"\n"
116"Kernel NBD client support:\n"
117" -c, --connect=DEV connect FILE to the local NBD device DEV\n"

--- 333 unchanged lines hidden (view full) ---

451 gpointer opaque)
452{
453 if (state >= TERMINATE) {
454 return;
455 }
456
457 nb_fds++;
458 nbd_update_server_watch();
455 nbd_client_new(cioc, tlscreds, NULL, nbd_client_closed);
459 nbd_client_new(cioc, tlscreds, tlsauthz, nbd_client_closed);
456}
457
458static void nbd_update_server_watch(void)
459{
460 if (nbd_can_accept()) {
461 qio_net_listener_set_client_func(server, nbd_accept, NULL, NULL);
462 } else {
463 qio_net_listener_set_client_func(server, NULL, NULL, NULL);

--- 174 unchanged lines hidden (view full) ---

638 { "shared", required_argument, NULL, 'e' },
639 { "format", required_argument, NULL, 'f' },
640 { "persistent", no_argument, NULL, 't' },
641 { "verbose", no_argument, NULL, 'v' },
642 { "object", required_argument, NULL, QEMU_NBD_OPT_OBJECT },
643 { "export-name", required_argument, NULL, 'x' },
644 { "description", required_argument, NULL, 'D' },
645 { "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS },
460}
461
462static void nbd_update_server_watch(void)
463{
464 if (nbd_can_accept()) {
465 qio_net_listener_set_client_func(server, nbd_accept, NULL, NULL);
466 } else {
467 qio_net_listener_set_client_func(server, NULL, NULL, NULL);

--- 174 unchanged lines hidden (view full) ---

642 { "shared", required_argument, NULL, 'e' },
643 { "format", required_argument, NULL, 'f' },
644 { "persistent", no_argument, NULL, 't' },
645 { "verbose", no_argument, NULL, 'v' },
646 { "object", required_argument, NULL, QEMU_NBD_OPT_OBJECT },
647 { "export-name", required_argument, NULL, 'x' },
648 { "description", required_argument, NULL, 'D' },
649 { "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS },
650 { "tls-authz", required_argument, NULL, QEMU_NBD_OPT_TLSAUTHZ },
646 { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
647 { "trace", required_argument, NULL, 'T' },
648 { "fork", no_argument, NULL, QEMU_NBD_OPT_FORK },
649 { NULL, 0, NULL, 0 }
650 };
651 int ch;
652 int opt_ind = 0;
653 int flags = BDRV_O_RDWR;

--- 203 unchanged lines hidden (view full) ---

857 break;
858 case QEMU_NBD_OPT_IMAGE_OPTS:
859 imageOpts = true;
860 break;
861 case 'T':
862 g_free(trace_file);
863 trace_file = trace_opt_parse(optarg);
864 break;
651 { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
652 { "trace", required_argument, NULL, 'T' },
653 { "fork", no_argument, NULL, QEMU_NBD_OPT_FORK },
654 { NULL, 0, NULL, 0 }
655 };
656 int ch;
657 int opt_ind = 0;
658 int flags = BDRV_O_RDWR;

--- 203 unchanged lines hidden (view full) ---

862 break;
863 case QEMU_NBD_OPT_IMAGE_OPTS:
864 imageOpts = true;
865 break;
866 case 'T':
867 g_free(trace_file);
868 trace_file = trace_opt_parse(optarg);
869 break;
870 case QEMU_NBD_OPT_TLSAUTHZ:
871 tlsauthz = optarg;
872 break;
865 case QEMU_NBD_OPT_FORK:
866 fork_process = true;
867 break;
868 case 'L':
869 list = true;
870 break;
871 }
872 }

--- 56 unchanged lines hidden (view full) ---

929 if (sockpath) {
930 error_report("TLS is only supported with IPv4/IPv6");
931 exit(EXIT_FAILURE);
932 }
933 if (device) {
934 error_report("TLS is not supported with a host device");
935 exit(EXIT_FAILURE);
936 }
873 case QEMU_NBD_OPT_FORK:
874 fork_process = true;
875 break;
876 case 'L':
877 list = true;
878 break;
879 }
880 }

--- 56 unchanged lines hidden (view full) ---

937 if (sockpath) {
938 error_report("TLS is only supported with IPv4/IPv6");
939 exit(EXIT_FAILURE);
940 }
941 if (device) {
942 error_report("TLS is not supported with a host device");
943 exit(EXIT_FAILURE);
944 }
945 if (tlsauthz && list) {
946 error_report("TLS authorization is incompatible with export list");
947 exit(EXIT_FAILURE);
948 }
937 tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
938 if (local_err) {
939 error_report("Failed to get TLS creds %s",
940 error_get_pretty(local_err));
941 exit(EXIT_FAILURE);
942 }
949 tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
950 if (local_err) {
951 error_report("Failed to get TLS creds %s",
952 error_get_pretty(local_err));
953 exit(EXIT_FAILURE);
954 }
955 } else {
956 if (tlsauthz) {
957 error_report("--tls-authz is not permitted without --tls-creds");
958 exit(EXIT_FAILURE);
959 }
943 }
944
945 if (list) {
946 saddr = nbd_build_socket_address(sockpath, bindto, port);
947 return qemu_nbd_client_list(saddr, tlscreds, bindto);
948 }
949
950#if !HAVE_NBD_DEVICE

--- 270 unchanged lines hidden ---
960 }
961
962 if (list) {
963 saddr = nbd_build_socket_address(sockpath, bindto, port);
964 return qemu_nbd_client_list(saddr, tlscreds, bindto);
965 }
966
967#if !HAVE_NBD_DEVICE

--- 270 unchanged lines hidden ---