]> git.proxmox.com Git - mirror_qemu.git/blame - block/nbd.c
e1000e: Fix ICR "Other" causes clear logic
[mirror_qemu.git] / block / nbd.c
CommitLineData
75818250
TS
1/*
2 * QEMU Block driver for NBD
3 *
4 * Copyright (C) 2008 Bull S.A.S.
bd5921b4 5 * Author: Laurent Vivier <Laurent.Vivier@bull.net>
75818250
TS
6 *
7 * Some parts:
8 * Copyright (C) 2007 Anthony Liguori <anthony@codemonkey.ws>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * THE SOFTWARE.
27 */
28
80c71a24 29#include "qemu/osdep.h"
2302c1ca 30#include "block/nbd-client.h"
da34e65c 31#include "qapi/error.h"
1de7afc9 32#include "qemu/uri.h"
737e150e 33#include "block/block_int.h"
1de7afc9 34#include "qemu/module.h"
491d6c7c
HR
35#include "qapi-visit.h"
36#include "qapi/qobject-input-visitor.h"
37#include "qapi/qobject-output-visitor.h"
2019d68b 38#include "qapi/qmp/qdict.h"
f53a1feb
KW
39#include "qapi/qmp/qjson.h"
40#include "qapi/qmp/qint.h"
2019d68b 41#include "qapi/qmp/qstring.h"
f348b6d1 42#include "qemu/cutils.h"
75818250 43
1d45f8b5
LV
44#define EN_OPTSTR ":exportname="
45
75818250 46typedef struct BDRVNBDState {
10676b81 47 NBDClientSession client;
03504d05
HR
48
49 /* For nbd_refresh_filename() */
9445673e 50 SocketAddressFlat *saddr;
491d6c7c 51 char *export, *tlscredsid;
75818250
TS
52} BDRVNBDState;
53
f53a1feb 54static int nbd_parse_uri(const char *filename, QDict *options)
1d7d2a9d
PB
55{
56 URI *uri;
57 const char *p;
58 QueryParams *qp = NULL;
59 int ret = 0;
f53a1feb 60 bool is_unix;
1d7d2a9d
PB
61
62 uri = uri_parse(filename);
63 if (!uri) {
64 return -EINVAL;
65 }
66
67 /* transport */
68 if (!strcmp(uri->scheme, "nbd")) {
f53a1feb 69 is_unix = false;
1d7d2a9d 70 } else if (!strcmp(uri->scheme, "nbd+tcp")) {
f53a1feb 71 is_unix = false;
1d7d2a9d 72 } else if (!strcmp(uri->scheme, "nbd+unix")) {
f53a1feb 73 is_unix = true;
1d7d2a9d
PB
74 } else {
75 ret = -EINVAL;
76 goto out;
77 }
78
79 p = uri->path ? uri->path : "/";
80 p += strspn(p, "/");
81 if (p[0]) {
e59084b5 82 qdict_put_str(options, "export", p);
1d7d2a9d
PB
83 }
84
85 qp = query_params_parse(uri->query);
f53a1feb 86 if (qp->n > 1 || (is_unix && !qp->n) || (!is_unix && qp->n)) {
1d7d2a9d
PB
87 ret = -EINVAL;
88 goto out;
89 }
90
f53a1feb 91 if (is_unix) {
1d7d2a9d
PB
92 /* nbd+unix:///export?socket=path */
93 if (uri->server || uri->port || strcmp(qp->p[0].name, "socket")) {
94 ret = -EINVAL;
95 goto out;
96 }
e59084b5
EB
97 qdict_put_str(options, "server.type", "unix");
98 qdict_put_str(options, "server.path", qp->p[0].value);
1d7d2a9d 99 } else {
23307908 100 QString *host;
f84d431b
HR
101 char *port_str;
102
bebbf7fa 103 /* nbd[+tcp]://host[:port]/export */
1d7d2a9d
PB
104 if (!uri->server) {
105 ret = -EINVAL;
106 goto out;
107 }
f17c90be 108
23307908
JT
109 /* strip braces from literal IPv6 address */
110 if (uri->server[0] == '[') {
111 host = qstring_from_substr(uri->server, 1,
112 strlen(uri->server) - 2);
113 } else {
114 host = qstring_from_str(uri->server);
115 }
116
e59084b5 117 qdict_put_str(options, "server.type", "inet");
9445673e 118 qdict_put(options, "server.host", host);
f84d431b
HR
119
120 port_str = g_strdup_printf("%d", uri->port ?: NBD_DEFAULT_PORT);
e59084b5 121 qdict_put_str(options, "server.port", port_str);
f84d431b 122 g_free(port_str);
1d7d2a9d
PB
123 }
124
125out:
126 if (qp) {
127 query_params_free(qp);
128 }
129 uri_free(uri);
130 return ret;
131}
132
48c38e0b
HR
133static bool nbd_has_filename_options_conflict(QDict *options, Error **errp)
134{
135 const QDictEntry *e;
136
137 for (e = qdict_first(options); e; e = qdict_next(options, e)) {
138 if (!strcmp(e->key, "host") ||
139 !strcmp(e->key, "port") ||
140 !strcmp(e->key, "path") ||
491d6c7c
HR
141 !strcmp(e->key, "export") ||
142 strstart(e->key, "server.", NULL))
48c38e0b
HR
143 {
144 error_setg(errp, "Option '%s' cannot be used with a file name",
145 e->key);
146 return true;
147 }
148 }
149
150 return false;
151}
152
6963a30d
KW
153static void nbd_parse_filename(const char *filename, QDict *options,
154 Error **errp)
75818250 155{
1d45f8b5 156 char *file;
33897dc7
NT
157 char *export_name;
158 const char *host_spec;
75818250 159 const char *unixpath;
75818250 160
48c38e0b 161 if (nbd_has_filename_options_conflict(options, errp)) {
681e7ad0
KW
162 return;
163 }
164
1d7d2a9d 165 if (strstr(filename, "://")) {
6963a30d
KW
166 int ret = nbd_parse_uri(filename, options);
167 if (ret < 0) {
168 error_setg(errp, "No valid URL specified");
169 }
170 return;
1d7d2a9d
PB
171 }
172
7267c094 173 file = g_strdup(filename);
1d45f8b5 174
33897dc7
NT
175 export_name = strstr(file, EN_OPTSTR);
176 if (export_name) {
177 if (export_name[strlen(EN_OPTSTR)] == 0) {
1d45f8b5
LV
178 goto out;
179 }
33897dc7
NT
180 export_name[0] = 0; /* truncate 'file' */
181 export_name += strlen(EN_OPTSTR);
f53a1feb 182
e59084b5 183 qdict_put_str(options, "export", export_name);
1d45f8b5
LV
184 }
185
33897dc7
NT
186 /* extract the host_spec - fail if it's not nbd:... */
187 if (!strstart(file, "nbd:", &host_spec)) {
6963a30d 188 error_setg(errp, "File name string for NBD must start with 'nbd:'");
1d45f8b5
LV
189 goto out;
190 }
75818250 191
f53a1feb 192 if (!*host_spec) {
f53a1feb
KW
193 goto out;
194 }
195
33897dc7
NT
196 /* are we a UNIX or TCP socket? */
197 if (strstart(host_spec, "unix:", &unixpath)) {
e59084b5
EB
198 qdict_put_str(options, "server.type", "unix");
199 qdict_put_str(options, "server.path", unixpath);
75818250 200 } else {
f53a1feb
KW
201 InetSocketAddress *addr = NULL;
202
6963a30d 203 addr = inet_parse(host_spec, errp);
92de9012 204 if (!addr) {
f17c90be
KW
205 goto out;
206 }
75818250 207
e59084b5
EB
208 qdict_put_str(options, "server.type", "inet");
209 qdict_put_str(options, "server.host", addr->host);
210 qdict_put_str(options, "server.port", addr->port);
f53a1feb
KW
211 qapi_free_InetSocketAddress(addr);
212 }
75818250 213
33897dc7 214out:
7267c094 215 g_free(file);
f53a1feb
KW
216}
217
491d6c7c
HR
218static bool nbd_process_legacy_socket_options(QDict *output_options,
219 QemuOpts *legacy_opts,
220 Error **errp)
f53a1feb 221{
491d6c7c
HR
222 const char *path = qemu_opt_get(legacy_opts, "path");
223 const char *host = qemu_opt_get(legacy_opts, "host");
224 const char *port = qemu_opt_get(legacy_opts, "port");
225 const QDictEntry *e;
f53a1feb 226
491d6c7c
HR
227 if (!path && !host && !port) {
228 return true;
229 }
03504d05 230
491d6c7c
HR
231 for (e = qdict_first(output_options); e; e = qdict_next(output_options, e))
232 {
233 if (strstart(e->key, "server.", NULL)) {
234 error_setg(errp, "Cannot use 'server' and path/host/port at the "
235 "same time");
236 return false;
681e7ad0 237 }
33897dc7 238 }
491d6c7c
HR
239
240 if (path && host) {
241 error_setg(errp, "path and host may not be used at the same time");
242 return false;
243 } else if (path) {
244 if (port) {
245 error_setg(errp, "port may not be used without host");
246 return false;
247 }
248
e59084b5
EB
249 qdict_put_str(output_options, "server.type", "unix");
250 qdict_put_str(output_options, "server.path", path);
491d6c7c 251 } else if (host) {
e59084b5
EB
252 qdict_put_str(output_options, "server.type", "inet");
253 qdict_put_str(output_options, "server.host", host);
254 qdict_put_str(output_options, "server.port",
255 port ?: stringify(NBD_DEFAULT_PORT));
442045cb 256 }
f53a1feb 257
491d6c7c
HR
258 return true;
259}
f53a1feb 260
9445673e
MA
261static SocketAddressFlat *nbd_config(BDRVNBDState *s, QDict *options,
262 Error **errp)
491d6c7c 263{
9445673e 264 SocketAddressFlat *saddr = NULL;
491d6c7c
HR
265 QDict *addr = NULL;
266 QObject *crumpled_addr = NULL;
267 Visitor *iv = NULL;
268 Error *local_err = NULL;
269
270 qdict_extract_subqdict(options, &addr, "server.");
271 if (!qdict_size(addr)) {
272 error_setg(errp, "NBD server address missing");
273 goto done;
f53a1feb
KW
274 }
275
491d6c7c
HR
276 crumpled_addr = qdict_crumple(addr, errp);
277 if (!crumpled_addr) {
278 goto done;
279 }
bebbf7fa 280
129c7d1c
MA
281 /*
282 * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive
283 * server.type=inet. .to doesn't matter, it's ignored anyway.
284 * That's because when @options come from -blockdev or
285 * blockdev_add, members are typed according to the QAPI schema,
286 * but when they come from -drive, they're all QString. The
287 * visitor expects the former.
288 */
048abb7b 289 iv = qobject_input_visitor_new(crumpled_addr);
9445673e 290 visit_type_SocketAddressFlat(iv, NULL, &saddr, &local_err);
491d6c7c
HR
291 if (local_err) {
292 error_propagate(errp, local_err);
293 goto done;
294 }
7a5ed437 295
491d6c7c
HR
296done:
297 QDECREF(addr);
298 qobject_decref(crumpled_addr);
299 visit_free(iv);
7a5ed437 300 return saddr;
33897dc7 301}
1d45f8b5 302
10676b81 303NBDClientSession *nbd_get_client_session(BlockDriverState *bs)
f53a829b
HR
304{
305 BDRVNBDState *s = bs->opaque;
306 return &s->client;
307}
308
9445673e 309static QIOChannelSocket *nbd_establish_connection(SocketAddressFlat *saddr_flat,
064097d9 310 Error **errp)
33897dc7 311{
9445673e 312 SocketAddress *saddr = socket_address_crumple(saddr_flat);
064097d9
DB
313 QIOChannelSocket *sioc;
314 Error *local_err = NULL;
75818250 315
064097d9 316 sioc = qio_channel_socket_new();
0d73f725 317 qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client");
75818250 318
064097d9
DB
319 qio_channel_socket_connect_sync(sioc,
320 saddr,
321 &local_err);
9445673e 322 qapi_free_SocketAddress(saddr);
064097d9 323 if (local_err) {
cc1e1391 324 object_unref(OBJECT(sioc));
064097d9
DB
325 error_propagate(errp, local_err);
326 return NULL;
1d45f8b5 327 }
75818250 328
064097d9 329 qio_channel_set_delay(QIO_CHANNEL(sioc), false);
7a5ed437 330
064097d9 331 return sioc;
33897dc7
NT
332}
333
75822a12
DB
334
335static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
336{
337 Object *obj;
338 QCryptoTLSCreds *creds;
339
340 obj = object_resolve_path_component(
341 object_get_objects_root(), id);
342 if (!obj) {
343 error_setg(errp, "No TLS credentials with id '%s'",
344 id);
345 return NULL;
346 }
347 creds = (QCryptoTLSCreds *)
348 object_dynamic_cast(obj, TYPE_QCRYPTO_TLS_CREDS);
349 if (!creds) {
350 error_setg(errp, "Object with id '%s' is not TLS credentials",
351 id);
352 return NULL;
353 }
354
355 if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) {
356 error_setg(errp,
357 "Expecting TLS credentials with a client endpoint");
358 return NULL;
359 }
360 object_ref(obj);
361 return creds;
362}
363
364
7ccc44fd
HR
365static QemuOptsList nbd_runtime_opts = {
366 .name = "nbd",
367 .head = QTAILQ_HEAD_INITIALIZER(nbd_runtime_opts.head),
368 .desc = {
369 {
370 .name = "host",
371 .type = QEMU_OPT_STRING,
372 .help = "TCP host to connect to",
373 },
374 {
375 .name = "port",
376 .type = QEMU_OPT_STRING,
377 .help = "TCP port to connect to",
378 },
379 {
380 .name = "path",
381 .type = QEMU_OPT_STRING,
382 .help = "Unix socket path to connect to",
383 },
384 {
385 .name = "export",
386 .type = QEMU_OPT_STRING,
387 .help = "Name of the NBD export to open",
388 },
389 {
390 .name = "tls-creds",
391 .type = QEMU_OPT_STRING,
392 .help = "ID of the TLS credentials to use",
393 },
394 },
395};
396
015a1036
HR
397static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
398 Error **errp)
33897dc7
NT
399{
400 BDRVNBDState *s = bs->opaque;
7ccc44fd
HR
401 QemuOpts *opts = NULL;
402 Error *local_err = NULL;
75822a12 403 QIOChannelSocket *sioc = NULL;
75822a12
DB
404 QCryptoTLSCreds *tlscreds = NULL;
405 const char *hostname = NULL;
406 int ret = -EINVAL;
ae255e52 407
7ccc44fd
HR
408 opts = qemu_opts_create(&nbd_runtime_opts, NULL, 0, &error_abort);
409 qemu_opts_absorb_qdict(opts, options, &local_err);
410 if (local_err) {
411 error_propagate(errp, local_err);
412 goto error;
413 }
414
9445673e 415 /* Translate @host, @port, and @path to a SocketAddressFlat */
491d6c7c
HR
416 if (!nbd_process_legacy_socket_options(options, opts, errp)) {
417 goto error;
418 }
419
33897dc7 420 /* Pop the config into our state object. Exit if invalid. */
491d6c7c
HR
421 s->saddr = nbd_config(s, options, errp);
422 if (!s->saddr) {
75822a12
DB
423 goto error;
424 }
425
491d6c7c
HR
426 s->export = g_strdup(qemu_opt_get(opts, "export"));
427
03504d05
HR
428 s->tlscredsid = g_strdup(qemu_opt_get(opts, "tls-creds"));
429 if (s->tlscredsid) {
430 tlscreds = nbd_get_tls_creds(s->tlscredsid, errp);
75822a12
DB
431 if (!tlscreds) {
432 goto error;
433 }
434
ca0b64e5 435 /* TODO SOCKET_ADDRESS_KIND_FD where fd has AF_INET or AF_INET6 */
9445673e 436 if (s->saddr->type != SOCKET_ADDRESS_FLAT_TYPE_INET) {
75822a12
DB
437 error_setg(errp, "TLS only supported over IP sockets");
438 goto error;
439 }
9445673e 440 hostname = s->saddr->u.inet.host;
33897dc7
NT
441 }
442
443 /* establish TCP connection, return error if it fails
444 * TODO: Configurable retry-until-timeout behaviour.
445 */
491d6c7c 446 sioc = nbd_establish_connection(s->saddr, errp);
064097d9 447 if (!sioc) {
75822a12
DB
448 ret = -ECONNREFUSED;
449 goto error;
2c7989a9
PB
450 }
451
2302c1ca 452 /* NBD handshake */
03504d05 453 ret = nbd_client_init(bs, sioc, s->export,
75822a12
DB
454 tlscreds, hostname, errp);
455 error:
456 if (sioc) {
457 object_unref(OBJECT(sioc));
458 }
459 if (tlscreds) {
460 object_unref(OBJECT(tlscreds));
461 }
03504d05 462 if (ret < 0) {
9445673e 463 qapi_free_SocketAddressFlat(s->saddr);
03504d05
HR
464 g_free(s->export);
465 g_free(s->tlscredsid);
466 }
7ccc44fd 467 qemu_opts_del(opts);
75822a12 468 return ret;
e183ef75
PB
469}
470
1486d04a
PB
471static int nbd_co_flush(BlockDriverState *bs)
472{
f53a829b 473 return nbd_client_co_flush(bs);
1486d04a
PB
474}
475
fa21e6fa
DL
476static void nbd_refresh_limits(BlockDriverState *bs, Error **errp)
477{
b9f7855a 478 bs->bl.max_pdiscard = NBD_MAX_BUFFER_SIZE;
fa778fff 479 bs->bl.max_pwrite_zeroes = NBD_MAX_BUFFER_SIZE;
5def6b80 480 bs->bl.max_transfer = NBD_MAX_BUFFER_SIZE;
fa21e6fa
DL
481}
482
75818250
TS
483static void nbd_close(BlockDriverState *bs)
484{
03504d05
HR
485 BDRVNBDState *s = bs->opaque;
486
f53a829b 487 nbd_client_close(bs);
03504d05 488
9445673e 489 qapi_free_SocketAddressFlat(s->saddr);
03504d05
HR
490 g_free(s->export);
491 g_free(s->tlscredsid);
75818250
TS
492}
493
494static int64_t nbd_getlength(BlockDriverState *bs)
495{
496 BDRVNBDState *s = bs->opaque;
497
2302c1ca 498 return s->client.size;
75818250
TS
499}
500
69447cd8
SH
501static void nbd_detach_aio_context(BlockDriverState *bs)
502{
f53a829b 503 nbd_client_detach_aio_context(bs);
69447cd8
SH
504}
505
506static void nbd_attach_aio_context(BlockDriverState *bs,
507 AioContext *new_context)
508{
f53a829b 509 nbd_client_attach_aio_context(bs, new_context);
69447cd8
SH
510}
511
4cdd01d3 512static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
2019d68b 513{
03504d05 514 BDRVNBDState *s = bs->opaque;
2019d68b 515 QDict *opts = qdict_new();
491d6c7c
HR
516 QObject *saddr_qdict;
517 Visitor *ov;
518 const char *host = NULL, *port = NULL, *path = NULL;
519
9445673e
MA
520 if (s->saddr->type == SOCKET_ADDRESS_FLAT_TYPE_INET) {
521 const InetSocketAddress *inet = &s->saddr->u.inet;
491d6c7c
HR
522 if (!inet->has_ipv4 && !inet->has_ipv6 && !inet->has_to) {
523 host = inet->host;
524 port = inet->port;
525 }
9445673e
MA
526 } else if (s->saddr->type == SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
527 path = s->saddr->u.q_unix.path;
528 } /* else can't represent as pseudo-filename */
2019d68b 529
e59084b5 530 qdict_put_str(opts, "driver", "nbd");
2019d68b 531
491d6c7c 532 if (path && s->export) {
2019d68b 533 snprintf(bs->exact_filename, sizeof(bs->exact_filename),
491d6c7c
HR
534 "nbd+unix:///%s?socket=%s", s->export, path);
535 } else if (path && !s->export) {
2019d68b 536 snprintf(bs->exact_filename, sizeof(bs->exact_filename),
491d6c7c
HR
537 "nbd+unix://?socket=%s", path);
538 } else if (host && s->export) {
ec0de768 539 snprintf(bs->exact_filename, sizeof(bs->exact_filename),
491d6c7c
HR
540 "nbd://%s:%s/%s", host, port, s->export);
541 } else if (host && !s->export) {
ec0de768 542 snprintf(bs->exact_filename, sizeof(bs->exact_filename),
491d6c7c 543 "nbd://%s:%s", host, port);
ec0de768
HR
544 }
545
491d6c7c 546 ov = qobject_output_visitor_new(&saddr_qdict);
9445673e 547 visit_type_SocketAddressFlat(ov, NULL, &s->saddr, &error_abort);
491d6c7c 548 visit_complete(ov, &saddr_qdict);
a1d4e38a 549 visit_free(ov);
491d6c7c
HR
550 qdict_put_obj(opts, "server", saddr_qdict);
551
03504d05 552 if (s->export) {
e59084b5 553 qdict_put_str(opts, "export", s->export);
2019d68b 554 }
03504d05 555 if (s->tlscredsid) {
e59084b5 556 qdict_put_str(opts, "tls-creds", s->tlscredsid);
75822a12 557 }
2019d68b 558
491d6c7c 559 qdict_flatten(opts);
2019d68b
HR
560 bs->full_open_options = opts;
561}
562
5efa9d5a 563static BlockDriver bdrv_nbd = {
69447cd8
SH
564 .format_name = "nbd",
565 .protocol_name = "nbd",
566 .instance_size = sizeof(BDRVNBDState),
567 .bdrv_parse_filename = nbd_parse_filename,
568 .bdrv_file_open = nbd_open,
70c4fb26
EB
569 .bdrv_co_preadv = nbd_client_co_preadv,
570 .bdrv_co_pwritev = nbd_client_co_pwritev,
fa778fff 571 .bdrv_co_pwrite_zeroes = nbd_client_co_pwrite_zeroes,
69447cd8
SH
572 .bdrv_close = nbd_close,
573 .bdrv_co_flush_to_os = nbd_co_flush,
447e57c3 574 .bdrv_co_pdiscard = nbd_client_co_pdiscard,
fa21e6fa 575 .bdrv_refresh_limits = nbd_refresh_limits,
69447cd8
SH
576 .bdrv_getlength = nbd_getlength,
577 .bdrv_detach_aio_context = nbd_detach_aio_context,
578 .bdrv_attach_aio_context = nbd_attach_aio_context,
2019d68b 579 .bdrv_refresh_filename = nbd_refresh_filename,
1d7d2a9d
PB
580};
581
582static BlockDriver bdrv_nbd_tcp = {
69447cd8
SH
583 .format_name = "nbd",
584 .protocol_name = "nbd+tcp",
585 .instance_size = sizeof(BDRVNBDState),
586 .bdrv_parse_filename = nbd_parse_filename,
587 .bdrv_file_open = nbd_open,
70c4fb26
EB
588 .bdrv_co_preadv = nbd_client_co_preadv,
589 .bdrv_co_pwritev = nbd_client_co_pwritev,
fa778fff 590 .bdrv_co_pwrite_zeroes = nbd_client_co_pwrite_zeroes,
69447cd8
SH
591 .bdrv_close = nbd_close,
592 .bdrv_co_flush_to_os = nbd_co_flush,
447e57c3 593 .bdrv_co_pdiscard = nbd_client_co_pdiscard,
fa21e6fa 594 .bdrv_refresh_limits = nbd_refresh_limits,
69447cd8
SH
595 .bdrv_getlength = nbd_getlength,
596 .bdrv_detach_aio_context = nbd_detach_aio_context,
597 .bdrv_attach_aio_context = nbd_attach_aio_context,
2019d68b 598 .bdrv_refresh_filename = nbd_refresh_filename,
1d7d2a9d
PB
599};
600
601static BlockDriver bdrv_nbd_unix = {
69447cd8
SH
602 .format_name = "nbd",
603 .protocol_name = "nbd+unix",
604 .instance_size = sizeof(BDRVNBDState),
605 .bdrv_parse_filename = nbd_parse_filename,
606 .bdrv_file_open = nbd_open,
70c4fb26
EB
607 .bdrv_co_preadv = nbd_client_co_preadv,
608 .bdrv_co_pwritev = nbd_client_co_pwritev,
fa778fff 609 .bdrv_co_pwrite_zeroes = nbd_client_co_pwrite_zeroes,
69447cd8
SH
610 .bdrv_close = nbd_close,
611 .bdrv_co_flush_to_os = nbd_co_flush,
447e57c3 612 .bdrv_co_pdiscard = nbd_client_co_pdiscard,
fa21e6fa 613 .bdrv_refresh_limits = nbd_refresh_limits,
69447cd8
SH
614 .bdrv_getlength = nbd_getlength,
615 .bdrv_detach_aio_context = nbd_detach_aio_context,
616 .bdrv_attach_aio_context = nbd_attach_aio_context,
2019d68b 617 .bdrv_refresh_filename = nbd_refresh_filename,
75818250 618};
5efa9d5a
AL
619
620static void bdrv_nbd_init(void)
621{
622 bdrv_register(&bdrv_nbd);
1d7d2a9d
PB
623 bdrv_register(&bdrv_nbd_tcp);
624 bdrv_register(&bdrv_nbd_unix);
5efa9d5a
AL
625}
626
627block_init(bdrv_nbd_init);