2 * GlusterFS backend for QEMU
4 * Copyright (C) 2012 Bharata B Rao <bharata@linux.vnet.ibm.com>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
12 #include "qemu/units.h"
13 #include <glusterfs/api/glfs.h>
14 #include "block/block_int.h"
15 #include "block/qdict.h"
16 #include "qapi/error.h"
17 #include "qapi/qmp/qdict.h"
18 #include "qapi/qmp/qerror.h"
20 #include "qemu/error-report.h"
21 #include "qemu/module.h"
22 #include "qemu/option.h"
23 #include "qemu/cutils.h"
25 #ifdef CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT
26 # define glfs_ftruncate(fd, offset) glfs_ftruncate(fd, offset, NULL, NULL)
29 #define GLUSTER_OPT_FILENAME "filename"
30 #define GLUSTER_OPT_VOLUME "volume"
31 #define GLUSTER_OPT_PATH "path"
32 #define GLUSTER_OPT_TYPE "type"
33 #define GLUSTER_OPT_SERVER_PATTERN "server."
34 #define GLUSTER_OPT_HOST "host"
35 #define GLUSTER_OPT_PORT "port"
36 #define GLUSTER_OPT_TO "to"
37 #define GLUSTER_OPT_IPV4 "ipv4"
38 #define GLUSTER_OPT_IPV6 "ipv6"
39 #define GLUSTER_OPT_SOCKET "socket"
40 #define GLUSTER_OPT_DEBUG "debug"
41 #define GLUSTER_DEFAULT_PORT 24007
42 #define GLUSTER_DEBUG_DEFAULT 4
43 #define GLUSTER_DEBUG_MAX 9
44 #define GLUSTER_OPT_LOGFILE "logfile"
45 #define GLUSTER_LOGFILE_DEFAULT "-" /* handled in libgfapi as /dev/stderr */
47 * Several versions of GlusterFS (3.12? -> 6.0.1) fail when the transfer size
48 * is greater or equal to 1024 MiB, so we are limiting the transfer size to 512
49 * MiB to avoid this rare issue.
51 #define GLUSTER_MAX_TRANSFER (512 * MiB)
53 #define GERR_INDEX_HINT "hint: check in 'server' array index '%d'\n"
55 typedef struct GlusterAIOCB
{
59 AioContext
*aio_context
;
62 typedef struct BDRVGlusterState
{
66 bool supports_seek_data
;
70 typedef struct BDRVGlusterReopenState
{
73 } BDRVGlusterReopenState
;
76 typedef struct GlfsPreopened
{
82 typedef struct ListElement
{
83 QLIST_ENTRY(ListElement
) list
;
87 static QLIST_HEAD(, ListElement
) glfs_list
;
89 static QemuOptsList qemu_gluster_create_opts
= {
90 .name
= "qemu-gluster-create-opts",
91 .head
= QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts
.head
),
94 .name
= BLOCK_OPT_SIZE
,
95 .type
= QEMU_OPT_SIZE
,
96 .help
= "Virtual disk size"
99 .name
= BLOCK_OPT_PREALLOC
,
100 .type
= QEMU_OPT_STRING
,
101 .help
= "Preallocation mode (allowed values: off"
102 #ifdef CONFIG_GLUSTERFS_FALLOCATE
105 #ifdef CONFIG_GLUSTERFS_ZEROFILL
111 .name
= GLUSTER_OPT_DEBUG
,
112 .type
= QEMU_OPT_NUMBER
,
113 .help
= "Gluster log level, valid range is 0-9",
116 .name
= GLUSTER_OPT_LOGFILE
,
117 .type
= QEMU_OPT_STRING
,
118 .help
= "Logfile path of libgfapi",
120 { /* end of list */ }
124 static QemuOptsList runtime_opts
= {
126 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
129 .name
= GLUSTER_OPT_FILENAME
,
130 .type
= QEMU_OPT_STRING
,
131 .help
= "URL to the gluster image",
134 .name
= GLUSTER_OPT_DEBUG
,
135 .type
= QEMU_OPT_NUMBER
,
136 .help
= "Gluster log level, valid range is 0-9",
139 .name
= GLUSTER_OPT_LOGFILE
,
140 .type
= QEMU_OPT_STRING
,
141 .help
= "Logfile path of libgfapi",
143 { /* end of list */ }
147 static QemuOptsList runtime_json_opts
= {
148 .name
= "gluster_json",
149 .head
= QTAILQ_HEAD_INITIALIZER(runtime_json_opts
.head
),
152 .name
= GLUSTER_OPT_VOLUME
,
153 .type
= QEMU_OPT_STRING
,
154 .help
= "name of gluster volume where VM image resides",
157 .name
= GLUSTER_OPT_PATH
,
158 .type
= QEMU_OPT_STRING
,
159 .help
= "absolute path to image file in gluster volume",
162 .name
= GLUSTER_OPT_DEBUG
,
163 .type
= QEMU_OPT_NUMBER
,
164 .help
= "Gluster log level, valid range is 0-9",
166 { /* end of list */ }
170 static QemuOptsList runtime_type_opts
= {
171 .name
= "gluster_type",
172 .head
= QTAILQ_HEAD_INITIALIZER(runtime_type_opts
.head
),
175 .name
= GLUSTER_OPT_TYPE
,
176 .type
= QEMU_OPT_STRING
,
179 { /* end of list */ }
183 static QemuOptsList runtime_unix_opts
= {
184 .name
= "gluster_unix",
185 .head
= QTAILQ_HEAD_INITIALIZER(runtime_unix_opts
.head
),
188 .name
= GLUSTER_OPT_SOCKET
,
189 .type
= QEMU_OPT_STRING
,
190 .help
= "socket file path (legacy)",
193 .name
= GLUSTER_OPT_PATH
,
194 .type
= QEMU_OPT_STRING
,
195 .help
= "socket file path (QAPI)",
197 { /* end of list */ }
201 static QemuOptsList runtime_inet_opts
= {
202 .name
= "gluster_inet",
203 .head
= QTAILQ_HEAD_INITIALIZER(runtime_inet_opts
.head
),
206 .name
= GLUSTER_OPT_TYPE
,
207 .type
= QEMU_OPT_STRING
,
211 .name
= GLUSTER_OPT_HOST
,
212 .type
= QEMU_OPT_STRING
,
213 .help
= "host address (hostname/ipv4/ipv6 addresses)",
216 .name
= GLUSTER_OPT_PORT
,
217 .type
= QEMU_OPT_STRING
,
218 .help
= "port number on which glusterd is listening (default 24007)",
222 .type
= QEMU_OPT_NUMBER
,
223 .help
= "max port number, not supported by gluster",
227 .type
= QEMU_OPT_BOOL
,
228 .help
= "ipv4 bool value, not supported by gluster",
232 .type
= QEMU_OPT_BOOL
,
233 .help
= "ipv6 bool value, not supported by gluster",
235 { /* end of list */ }
239 static void glfs_set_preopened(const char *volume
, glfs_t
*fs
)
241 ListElement
*entry
= NULL
;
243 entry
= g_new(ListElement
, 1);
245 entry
->saved
.volume
= g_strdup(volume
);
247 entry
->saved
.fs
= fs
;
248 entry
->saved
.ref
= 1;
250 QLIST_INSERT_HEAD(&glfs_list
, entry
, list
);
253 static glfs_t
*glfs_find_preopened(const char *volume
)
255 ListElement
*entry
= NULL
;
257 QLIST_FOREACH(entry
, &glfs_list
, list
) {
258 if (strcmp(entry
->saved
.volume
, volume
) == 0) {
260 return entry
->saved
.fs
;
267 static void glfs_clear_preopened(glfs_t
*fs
)
269 ListElement
*entry
= NULL
;
276 QLIST_FOREACH_SAFE(entry
, &glfs_list
, list
, next
) {
277 if (entry
->saved
.fs
== fs
) {
278 if (--entry
->saved
.ref
) {
282 QLIST_REMOVE(entry
, list
);
284 glfs_fini(entry
->saved
.fs
);
285 g_free(entry
->saved
.volume
);
291 static int parse_volume_options(BlockdevOptionsGluster
*gconf
, char *path
)
300 p
= q
= path
+ strspn(path
, "/");
301 p
+= strcspn(p
, "/");
305 gconf
->volume
= g_strndup(q
, p
- q
);
312 gconf
->path
= g_strdup(p
);
317 * file=gluster[+transport]://[host[:port]]/volume/path[?socket=...]
319 * 'gluster' is the protocol.
321 * 'transport' specifies the transport type used to connect to gluster
322 * management daemon (glusterd). Valid transport types are
323 * tcp or unix. If a transport type isn't specified, then tcp type is assumed.
325 * 'host' specifies the host where the volume file specification for
326 * the given volume resides. This can be either hostname or ipv4 address.
327 * If transport type is 'unix', then 'host' field should not be specified.
328 * The 'socket' field needs to be populated with the path to unix domain
331 * 'port' is the port number on which glusterd is listening. This is optional
332 * and if not specified, QEMU will send 0 which will make gluster to use the
333 * default port. If the transport type is unix, then 'port' should not be
336 * 'volume' is the name of the gluster volume which contains the VM image.
338 * 'path' is the path to the actual VM image that resides on gluster volume.
342 * file=gluster://1.2.3.4/testvol/a.img
343 * file=gluster+tcp://1.2.3.4/testvol/a.img
344 * file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
345 * file=gluster+tcp://host.domain.com:24007/testvol/dir/a.img
346 * file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
348 static int qemu_gluster_parse_uri(BlockdevOptionsGluster
*gconf
,
349 const char *filename
)
351 SocketAddress
*gsconf
;
353 QueryParams
*qp
= NULL
;
354 bool is_unix
= false;
357 uri
= uri_parse(filename
);
362 gsconf
= g_new0(SocketAddress
, 1);
363 QAPI_LIST_PREPEND(gconf
->server
, gsconf
);
366 if (!uri
->scheme
|| !strcmp(uri
->scheme
, "gluster")) {
367 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
368 } else if (!strcmp(uri
->scheme
, "gluster+tcp")) {
369 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
370 } else if (!strcmp(uri
->scheme
, "gluster+unix")) {
371 gsconf
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
373 } else if (!strcmp(uri
->scheme
, "gluster+rdma")) {
374 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
375 warn_report("rdma feature is not supported, falling back to tcp");
381 ret
= parse_volume_options(gconf
, uri
->path
);
386 qp
= query_params_parse(uri
->query
);
387 if (qp
->n
> 1 || (is_unix
&& !qp
->n
) || (!is_unix
&& qp
->n
)) {
393 if (uri
->server
|| uri
->port
) {
397 if (strcmp(qp
->p
[0].name
, "socket")) {
401 gsconf
->u
.q_unix
.path
= g_strdup(qp
->p
[0].value
);
403 gsconf
->u
.inet
.host
= g_strdup(uri
->server
? uri
->server
: "localhost");
405 gsconf
->u
.inet
.port
= g_strdup_printf("%d", uri
->port
);
407 gsconf
->u
.inet
.port
= g_strdup_printf("%d", GLUSTER_DEFAULT_PORT
);
413 query_params_free(qp
);
419 static struct glfs
*qemu_gluster_glfs_init(BlockdevOptionsGluster
*gconf
,
425 SocketAddressList
*server
;
426 unsigned long long port
;
428 glfs
= glfs_find_preopened(gconf
->volume
);
433 glfs
= glfs_new(gconf
->volume
);
438 glfs_set_preopened(gconf
->volume
, glfs
);
440 for (server
= gconf
->server
; server
; server
= server
->next
) {
441 switch (server
->value
->type
) {
442 case SOCKET_ADDRESS_TYPE_UNIX
:
443 ret
= glfs_set_volfile_server(glfs
, "unix",
444 server
->value
->u
.q_unix
.path
, 0);
446 case SOCKET_ADDRESS_TYPE_INET
:
447 if (parse_uint_full(server
->value
->u
.inet
.port
, &port
, 10) < 0 ||
449 error_setg(errp
, "'%s' is not a valid port number",
450 server
->value
->u
.inet
.port
);
454 ret
= glfs_set_volfile_server(glfs
, "tcp",
455 server
->value
->u
.inet
.host
,
458 case SOCKET_ADDRESS_TYPE_VSOCK
:
459 case SOCKET_ADDRESS_TYPE_FD
:
469 ret
= glfs_set_logging(glfs
, gconf
->logfile
, gconf
->debug
);
474 ret
= glfs_init(glfs
);
476 error_setg(errp
, "Gluster connection for volume %s, path %s failed"
477 " to connect", gconf
->volume
, gconf
->path
);
478 for (server
= gconf
->server
; server
; server
= server
->next
) {
479 if (server
->value
->type
== SOCKET_ADDRESS_TYPE_UNIX
) {
480 error_append_hint(errp
, "hint: failed on socket %s ",
481 server
->value
->u
.q_unix
.path
);
483 error_append_hint(errp
, "hint: failed on host %s and port %s ",
484 server
->value
->u
.inet
.host
,
485 server
->value
->u
.inet
.port
);
489 error_append_hint(errp
, "Please refer to gluster logs for more info\n");
491 /* glfs_init sometimes doesn't set errno although docs suggest that */
503 glfs_clear_preopened(glfs
);
510 * Convert the json formatted command line into qapi.
512 static int qemu_gluster_parse_json(BlockdevOptionsGluster
*gconf
,
513 QDict
*options
, Error
**errp
)
516 SocketAddress
*gsconf
= NULL
;
517 SocketAddressList
*curr
= NULL
;
518 QDict
*backing_options
= NULL
;
519 Error
*local_err
= NULL
;
522 int i
, type
, num_servers
;
524 /* create opts info from runtime_json_opts list */
525 opts
= qemu_opts_create(&runtime_json_opts
, NULL
, 0, &error_abort
);
526 if (!qemu_opts_absorb_qdict(opts
, options
, errp
)) {
530 num_servers
= qdict_array_entries(options
, GLUSTER_OPT_SERVER_PATTERN
);
531 if (num_servers
< 1) {
532 error_setg(&local_err
, QERR_MISSING_PARAMETER
, "server");
536 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_VOLUME
);
538 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_VOLUME
);
541 gconf
->volume
= g_strdup(ptr
);
543 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
545 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_PATH
);
548 gconf
->path
= g_strdup(ptr
);
551 for (i
= 0; i
< num_servers
; i
++) {
552 str
= g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN
"%d.", i
);
553 qdict_extract_subqdict(options
, &backing_options
, str
);
555 /* create opts info from runtime_type_opts list */
556 opts
= qemu_opts_create(&runtime_type_opts
, NULL
, 0, &error_abort
);
557 if (!qemu_opts_absorb_qdict(opts
, backing_options
, errp
)) {
561 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TYPE
);
563 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_TYPE
);
564 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
568 gsconf
= g_new0(SocketAddress
, 1);
569 if (!strcmp(ptr
, "tcp")) {
570 ptr
= "inet"; /* accept legacy "tcp" */
572 type
= qapi_enum_parse(&SocketAddressType_lookup
, ptr
, -1, NULL
);
573 if (type
!= SOCKET_ADDRESS_TYPE_INET
574 && type
!= SOCKET_ADDRESS_TYPE_UNIX
) {
575 error_setg(&local_err
,
576 "Parameter '%s' may be 'inet' or 'unix'",
578 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
584 if (gsconf
->type
== SOCKET_ADDRESS_TYPE_INET
) {
585 /* create opts info from runtime_inet_opts list */
586 opts
= qemu_opts_create(&runtime_inet_opts
, NULL
, 0, &error_abort
);
587 if (!qemu_opts_absorb_qdict(opts
, backing_options
, errp
)) {
591 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_HOST
);
593 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
595 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
598 gsconf
->u
.inet
.host
= g_strdup(ptr
);
599 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PORT
);
601 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
603 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
606 gsconf
->u
.inet
.port
= g_strdup(ptr
);
608 /* defend for unsupported fields in InetSocketAddress,
609 * i.e. @ipv4, @ipv6 and @to
611 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TO
);
613 gsconf
->u
.inet
.has_to
= true;
615 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV4
);
617 gsconf
->u
.inet
.has_ipv4
= true;
619 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV6
);
621 gsconf
->u
.inet
.has_ipv6
= true;
623 if (gsconf
->u
.inet
.has_to
) {
624 error_setg(&local_err
, "Parameter 'to' not supported");
627 if (gsconf
->u
.inet
.has_ipv4
|| gsconf
->u
.inet
.has_ipv6
) {
628 error_setg(&local_err
, "Parameters 'ipv4/ipv6' not supported");
633 /* create opts info from runtime_unix_opts list */
634 opts
= qemu_opts_create(&runtime_unix_opts
, NULL
, 0, &error_abort
);
635 if (!qemu_opts_absorb_qdict(opts
, backing_options
, errp
)) {
639 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
641 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
);
642 } else if (qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
)) {
643 error_setg(&local_err
,
644 "Conflicting parameters 'path' and 'socket'");
645 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
649 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
651 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
654 gsconf
->u
.q_unix
.path
= g_strdup(ptr
);
658 if (gconf
->server
== NULL
) {
659 gconf
->server
= g_new0(SocketAddressList
, 1);
660 gconf
->server
->value
= gsconf
;
661 curr
= gconf
->server
;
663 curr
->next
= g_new0(SocketAddressList
, 1);
664 curr
->next
->value
= gsconf
;
669 qobject_unref(backing_options
);
670 backing_options
= NULL
;
678 error_propagate(errp
, local_err
);
679 qapi_free_SocketAddress(gsconf
);
682 qobject_unref(backing_options
);
687 /* Converts options given in @filename and the @options QDict into the QAPI
689 static int qemu_gluster_parse(BlockdevOptionsGluster
*gconf
,
690 const char *filename
,
691 QDict
*options
, Error
**errp
)
695 ret
= qemu_gluster_parse_uri(gconf
, filename
);
697 error_setg(errp
, "invalid URI %s", filename
);
698 error_append_hint(errp
, "Usage: file=gluster[+transport]://"
699 "[host[:port]]volume/path[?socket=...]"
701 "[,file.logfile=/path/filename.log]\n");
705 ret
= qemu_gluster_parse_json(gconf
, options
, errp
);
707 error_append_hint(errp
, "Usage: "
708 "-drive driver=qcow2,file.driver=gluster,"
709 "file.volume=testvol,file.path=/path/a.qcow2"
711 "[,file.logfile=/path/filename.log],"
712 "file.server.0.type=inet,"
713 "file.server.0.host=1.2.3.4,"
714 "file.server.0.port=24007,"
715 "file.server.1.transport=unix,"
716 "file.server.1.path=/var/run/glusterd.socket ..."
725 static struct glfs
*qemu_gluster_init(BlockdevOptionsGluster
*gconf
,
726 const char *filename
,
727 QDict
*options
, Error
**errp
)
731 ret
= qemu_gluster_parse(gconf
, filename
, options
, errp
);
737 return qemu_gluster_glfs_init(gconf
, errp
);
741 * AIO callback routine called from GlusterFS thread.
743 static void gluster_finish_aiocb(struct glfs_fd
*fd
, ssize_t ret
,
744 #ifdef CONFIG_GLUSTERFS_IOCB_HAS_STAT
745 struct glfs_stat
*pre
, struct glfs_stat
*post
,
749 GlusterAIOCB
*acb
= (GlusterAIOCB
*)arg
;
751 if (!ret
|| ret
== acb
->size
) {
752 acb
->ret
= 0; /* Success */
753 } else if (ret
< 0) {
754 acb
->ret
= -errno
; /* Read/Write failed */
756 acb
->ret
= -EIO
; /* Partial read/write - fail it */
759 aio_co_schedule(acb
->aio_context
, acb
->coroutine
);
762 static void qemu_gluster_parse_flags(int bdrv_flags
, int *open_flags
)
764 assert(open_flags
!= NULL
);
766 *open_flags
|= O_BINARY
;
768 if (bdrv_flags
& BDRV_O_RDWR
) {
769 *open_flags
|= O_RDWR
;
771 *open_flags
|= O_RDONLY
;
774 if ((bdrv_flags
& BDRV_O_NOCACHE
)) {
775 *open_flags
|= O_DIRECT
;
780 * Do SEEK_DATA/HOLE to detect if it is functional. Older broken versions of
781 * gfapi incorrectly return the current offset when SEEK_DATA/HOLE is used.
782 * - Corrected versions return -1 and set errno to EINVAL.
783 * - Versions that support SEEK_DATA/HOLE correctly, will return -1 and set
784 * errno to ENXIO when SEEK_DATA is called with a position of EOF.
786 static bool qemu_gluster_test_seek(struct glfs_fd
*fd
)
790 #if defined SEEK_HOLE && defined SEEK_DATA
793 eof
= glfs_lseek(fd
, 0, SEEK_END
);
795 /* this should never occur */
799 /* this should always fail with ENXIO if SEEK_DATA is supported */
800 ret
= glfs_lseek(fd
, eof
, SEEK_DATA
);
803 return (ret
< 0) && (errno
== ENXIO
);
806 static int qemu_gluster_open(BlockDriverState
*bs
, QDict
*options
,
807 int bdrv_flags
, Error
**errp
)
809 BDRVGlusterState
*s
= bs
->opaque
;
812 BlockdevOptionsGluster
*gconf
= NULL
;
814 const char *filename
, *logfile
;
816 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
817 if (!qemu_opts_absorb_qdict(opts
, options
, errp
)) {
822 filename
= qemu_opt_get(opts
, GLUSTER_OPT_FILENAME
);
824 s
->debug
= qemu_opt_get_number(opts
, GLUSTER_OPT_DEBUG
,
825 GLUSTER_DEBUG_DEFAULT
);
828 } else if (s
->debug
> GLUSTER_DEBUG_MAX
) {
829 s
->debug
= GLUSTER_DEBUG_MAX
;
832 gconf
= g_new0(BlockdevOptionsGluster
, 1);
833 gconf
->debug
= s
->debug
;
834 gconf
->has_debug
= true;
836 logfile
= qemu_opt_get(opts
, GLUSTER_OPT_LOGFILE
);
837 s
->logfile
= g_strdup(logfile
? logfile
: GLUSTER_LOGFILE_DEFAULT
);
839 gconf
->logfile
= g_strdup(s
->logfile
);
840 gconf
->has_logfile
= true;
842 s
->glfs
= qemu_gluster_init(gconf
, filename
, options
, errp
);
848 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
849 /* Without this, if fsync fails for a recoverable reason (for instance,
850 * ENOSPC), gluster will dump its cache, preventing retries. This means
851 * almost certain data loss. Not all gluster versions support the
852 * 'resync-failed-syncs-after-fsync' key value, but there is no way to
853 * discover during runtime if it is supported (this api returns success for
854 * unknown key/value pairs) */
855 ret
= glfs_set_xlator_option(s
->glfs
, "*-write-behind",
856 "resync-failed-syncs-after-fsync",
859 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
865 qemu_gluster_parse_flags(bdrv_flags
, &open_flags
);
867 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
868 ret
= s
->fd
? 0 : -errno
;
870 if (ret
== -EACCES
|| ret
== -EROFS
) {
871 /* Try to degrade to read-only, but if it doesn't work, still use the
872 * normal error message. */
873 if (bdrv_apply_auto_read_only(bs
, NULL
, NULL
) == 0) {
874 open_flags
= (open_flags
& ~O_RDWR
) | O_RDONLY
;
875 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
876 ret
= s
->fd
? 0 : -errno
;
880 s
->supports_seek_data
= qemu_gluster_test_seek(s
->fd
);
884 qapi_free_BlockdevOptionsGluster(gconf
);
893 glfs_clear_preopened(s
->glfs
);
898 static void qemu_gluster_refresh_limits(BlockDriverState
*bs
, Error
**errp
)
900 bs
->bl
.max_transfer
= GLUSTER_MAX_TRANSFER
;
903 static int qemu_gluster_reopen_prepare(BDRVReopenState
*state
,
904 BlockReopenQueue
*queue
, Error
**errp
)
908 BDRVGlusterReopenState
*reop_s
;
909 BlockdevOptionsGluster
*gconf
;
912 assert(state
!= NULL
);
913 assert(state
->bs
!= NULL
);
915 s
= state
->bs
->opaque
;
917 state
->opaque
= g_new0(BDRVGlusterReopenState
, 1);
918 reop_s
= state
->opaque
;
920 qemu_gluster_parse_flags(state
->flags
, &open_flags
);
922 gconf
= g_new0(BlockdevOptionsGluster
, 1);
923 gconf
->debug
= s
->debug
;
924 gconf
->has_debug
= true;
925 gconf
->logfile
= g_strdup(s
->logfile
);
926 gconf
->has_logfile
= true;
929 * If 'state->bs->exact_filename' is empty, 'state->options' should contain
930 * the JSON parameters already parsed.
932 if (state
->bs
->exact_filename
[0] != '\0') {
933 reop_s
->glfs
= qemu_gluster_init(gconf
, state
->bs
->exact_filename
, NULL
,
936 reop_s
->glfs
= qemu_gluster_init(gconf
, NULL
, state
->options
, errp
);
938 if (reop_s
->glfs
== NULL
) {
943 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
944 ret
= glfs_set_xlator_option(reop_s
->glfs
, "*-write-behind",
945 "resync-failed-syncs-after-fsync", "on");
947 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
953 reop_s
->fd
= glfs_open(reop_s
->glfs
, gconf
->path
, open_flags
);
954 if (reop_s
->fd
== NULL
) {
955 /* reops->glfs will be cleaned up in _abort */
961 /* state->opaque will be freed in either the _abort or _commit */
962 qapi_free_BlockdevOptionsGluster(gconf
);
966 static void qemu_gluster_reopen_commit(BDRVReopenState
*state
)
968 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
969 BDRVGlusterState
*s
= state
->bs
->opaque
;
977 glfs_clear_preopened(s
->glfs
);
979 /* use the newly opened image / connection */
981 s
->glfs
= reop_s
->glfs
;
983 g_free(state
->opaque
);
984 state
->opaque
= NULL
;
990 static void qemu_gluster_reopen_abort(BDRVReopenState
*state
)
992 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
994 if (reop_s
== NULL
) {
999 glfs_close(reop_s
->fd
);
1002 glfs_clear_preopened(reop_s
->glfs
);
1004 g_free(state
->opaque
);
1005 state
->opaque
= NULL
;
1010 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1011 static coroutine_fn
int qemu_gluster_co_pwrite_zeroes(BlockDriverState
*bs
,
1014 BdrvRequestFlags flags
)
1018 BDRVGlusterState
*s
= bs
->opaque
;
1022 acb
.coroutine
= qemu_coroutine_self();
1023 acb
.aio_context
= bdrv_get_aio_context(bs
);
1025 ret
= glfs_zerofill_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1030 qemu_coroutine_yield();
1035 static int qemu_gluster_do_truncate(struct glfs_fd
*fd
, int64_t offset
,
1036 PreallocMode prealloc
, Error
**errp
)
1038 int64_t current_length
;
1040 current_length
= glfs_lseek(fd
, 0, SEEK_END
);
1041 if (current_length
< 0) {
1042 error_setg_errno(errp
, errno
, "Failed to determine current size");
1046 if (current_length
> offset
&& prealloc
!= PREALLOC_MODE_OFF
) {
1047 error_setg(errp
, "Cannot use preallocation for shrinking files");
1051 if (current_length
== offset
) {
1056 #ifdef CONFIG_GLUSTERFS_FALLOCATE
1057 case PREALLOC_MODE_FALLOC
:
1058 if (glfs_fallocate(fd
, 0, current_length
, offset
- current_length
)) {
1059 error_setg_errno(errp
, errno
, "Could not preallocate data");
1063 #endif /* CONFIG_GLUSTERFS_FALLOCATE */
1064 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1065 case PREALLOC_MODE_FULL
:
1066 if (glfs_ftruncate(fd
, offset
)) {
1067 error_setg_errno(errp
, errno
, "Could not resize file");
1070 if (glfs_zerofill(fd
, current_length
, offset
- current_length
)) {
1071 error_setg_errno(errp
, errno
, "Could not zerofill the new area");
1075 #endif /* CONFIG_GLUSTERFS_ZEROFILL */
1076 case PREALLOC_MODE_OFF
:
1077 if (glfs_ftruncate(fd
, offset
)) {
1078 error_setg_errno(errp
, errno
, "Could not resize file");
1083 error_setg(errp
, "Unsupported preallocation mode: %s",
1084 PreallocMode_str(prealloc
));
1091 static int qemu_gluster_co_create(BlockdevCreateOptions
*options
,
1094 BlockdevCreateOptionsGluster
*opts
= &options
->u
.gluster
;
1096 struct glfs_fd
*fd
= NULL
;
1099 assert(options
->driver
== BLOCKDEV_DRIVER_GLUSTER
);
1101 glfs
= qemu_gluster_glfs_init(opts
->location
, errp
);
1107 fd
= glfs_creat(glfs
, opts
->location
->path
,
1108 O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, S_IRUSR
| S_IWUSR
);
1114 ret
= qemu_gluster_do_truncate(fd
, opts
->size
, opts
->preallocation
, errp
);
1118 if (glfs_close(fd
) != 0 && ret
== 0) {
1122 glfs_clear_preopened(glfs
);
1126 static int coroutine_fn
qemu_gluster_co_create_opts(BlockDriver
*drv
,
1127 const char *filename
,
1131 BlockdevCreateOptions
*options
;
1132 BlockdevCreateOptionsGluster
*gopts
;
1133 BlockdevOptionsGluster
*gconf
;
1135 Error
*local_err
= NULL
;
1138 options
= g_new0(BlockdevCreateOptions
, 1);
1139 options
->driver
= BLOCKDEV_DRIVER_GLUSTER
;
1140 gopts
= &options
->u
.gluster
;
1142 gconf
= g_new0(BlockdevOptionsGluster
, 1);
1143 gopts
->location
= gconf
;
1145 gopts
->size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
1148 tmp
= qemu_opt_get_del(opts
, BLOCK_OPT_PREALLOC
);
1149 gopts
->preallocation
= qapi_enum_parse(&PreallocMode_lookup
, tmp
,
1150 PREALLOC_MODE_OFF
, &local_err
);
1153 error_propagate(errp
, local_err
);
1158 gconf
->debug
= qemu_opt_get_number_del(opts
, GLUSTER_OPT_DEBUG
,
1159 GLUSTER_DEBUG_DEFAULT
);
1160 if (gconf
->debug
< 0) {
1162 } else if (gconf
->debug
> GLUSTER_DEBUG_MAX
) {
1163 gconf
->debug
= GLUSTER_DEBUG_MAX
;
1165 gconf
->has_debug
= true;
1167 gconf
->logfile
= qemu_opt_get_del(opts
, GLUSTER_OPT_LOGFILE
);
1168 if (!gconf
->logfile
) {
1169 gconf
->logfile
= g_strdup(GLUSTER_LOGFILE_DEFAULT
);
1171 gconf
->has_logfile
= true;
1173 ret
= qemu_gluster_parse(gconf
, filename
, NULL
, errp
);
1178 ret
= qemu_gluster_co_create(options
, errp
);
1185 qapi_free_BlockdevCreateOptions(options
);
1189 static coroutine_fn
int qemu_gluster_co_rw(BlockDriverState
*bs
,
1190 int64_t sector_num
, int nb_sectors
,
1191 QEMUIOVector
*qiov
, int write
)
1195 BDRVGlusterState
*s
= bs
->opaque
;
1196 size_t size
= nb_sectors
* BDRV_SECTOR_SIZE
;
1197 off_t offset
= sector_num
* BDRV_SECTOR_SIZE
;
1201 acb
.coroutine
= qemu_coroutine_self();
1202 acb
.aio_context
= bdrv_get_aio_context(bs
);
1205 ret
= glfs_pwritev_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1206 gluster_finish_aiocb
, &acb
);
1208 ret
= glfs_preadv_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1209 gluster_finish_aiocb
, &acb
);
1216 qemu_coroutine_yield();
1220 static coroutine_fn
int qemu_gluster_co_truncate(BlockDriverState
*bs
,
1223 PreallocMode prealloc
,
1224 BdrvRequestFlags flags
,
1227 BDRVGlusterState
*s
= bs
->opaque
;
1228 return qemu_gluster_do_truncate(s
->fd
, offset
, prealloc
, errp
);
1231 static coroutine_fn
int qemu_gluster_co_readv(BlockDriverState
*bs
,
1236 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 0);
1239 static coroutine_fn
int qemu_gluster_co_writev(BlockDriverState
*bs
,
1246 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 1);
1249 static void qemu_gluster_close(BlockDriverState
*bs
)
1251 BDRVGlusterState
*s
= bs
->opaque
;
1258 glfs_clear_preopened(s
->glfs
);
1261 static coroutine_fn
int qemu_gluster_co_flush_to_disk(BlockDriverState
*bs
)
1265 BDRVGlusterState
*s
= bs
->opaque
;
1269 acb
.coroutine
= qemu_coroutine_self();
1270 acb
.aio_context
= bdrv_get_aio_context(bs
);
1272 ret
= glfs_fsync_async(s
->fd
, gluster_finish_aiocb
, &acb
);
1278 qemu_coroutine_yield();
1287 /* Some versions of Gluster (3.5.6 -> 3.5.8?) will not retain its cache
1288 * after a fsync failure, so we have no way of allowing the guest to safely
1289 * continue. Gluster versions prior to 3.5.6 don't retain the cache
1290 * either, but will invalidate the fd on error, so this is again our only
1293 * The 'resync-failed-syncs-after-fsync' xlator option for the
1294 * write-behind cache will cause later gluster versions to retain its
1295 * cache after error, so long as the fd remains open. However, we
1296 * currently have no way of knowing if this option is supported.
1298 * TODO: Once gluster provides a way for us to determine if the option
1299 * is supported, bypass the closure and setting drv to NULL. */
1300 qemu_gluster_close(bs
);
1305 #ifdef CONFIG_GLUSTERFS_DISCARD
1306 static coroutine_fn
int qemu_gluster_co_pdiscard(BlockDriverState
*bs
,
1307 int64_t offset
, int size
)
1311 BDRVGlusterState
*s
= bs
->opaque
;
1315 acb
.coroutine
= qemu_coroutine_self();
1316 acb
.aio_context
= bdrv_get_aio_context(bs
);
1318 ret
= glfs_discard_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1323 qemu_coroutine_yield();
1328 static int64_t qemu_gluster_getlength(BlockDriverState
*bs
)
1330 BDRVGlusterState
*s
= bs
->opaque
;
1333 ret
= glfs_lseek(s
->fd
, 0, SEEK_END
);
1341 static int64_t qemu_gluster_allocated_file_size(BlockDriverState
*bs
)
1343 BDRVGlusterState
*s
= bs
->opaque
;
1347 ret
= glfs_fstat(s
->fd
, &st
);
1351 return st
.st_blocks
* 512;
1356 * Find allocation range in @bs around offset @start.
1357 * May change underlying file descriptor's file offset.
1358 * If @start is not in a hole, store @start in @data, and the
1359 * beginning of the next hole in @hole, and return 0.
1360 * If @start is in a non-trailing hole, store @start in @hole and the
1361 * beginning of the next non-hole in @data, and return 0.
1362 * If @start is in a trailing hole or beyond EOF, return -ENXIO.
1363 * If we can't find out, return a negative errno other than -ENXIO.
1365 * (Shamefully copied from file-posix.c, only minuscule adaptions.)
1367 static int find_allocation(BlockDriverState
*bs
, off_t start
,
1368 off_t
*data
, off_t
*hole
)
1370 BDRVGlusterState
*s
= bs
->opaque
;
1372 if (!s
->supports_seek_data
) {
1376 #if defined SEEK_HOLE && defined SEEK_DATA
1381 * D1. offs == start: start is in data
1382 * D2. offs > start: start is in a hole, next data at offs
1383 * D3. offs < 0, errno = ENXIO: either start is in a trailing hole
1384 * or start is beyond EOF
1385 * If the latter happens, the file has been truncated behind
1386 * our back since we opened it. All bets are off then.
1387 * Treating like a trailing hole is simplest.
1388 * D4. offs < 0, errno != ENXIO: we learned nothing
1390 offs
= glfs_lseek(s
->fd
, start
, SEEK_DATA
);
1392 return -errno
; /* D3 or D4 */
1396 /* This is not a valid return by lseek(). We are safe to just return
1397 * -EIO in this case, and we'll treat it like D4. Unfortunately some
1398 * versions of gluster server will return offs < start, so an assert
1399 * here will unnecessarily abort QEMU. */
1404 /* D2: in hole, next data at offs */
1410 /* D1: in data, end not yet known */
1414 * H1. offs == start: start is in a hole
1415 * If this happens here, a hole has been dug behind our back
1416 * since the previous lseek().
1417 * H2. offs > start: either start is in data, next hole at offs,
1418 * or start is in trailing hole, EOF at offs
1419 * Linux treats trailing holes like any other hole: offs ==
1420 * start. Solaris seeks to EOF instead: offs > start (blech).
1421 * If that happens here, a hole has been dug behind our back
1422 * since the previous lseek().
1423 * H3. offs < 0, errno = ENXIO: start is beyond EOF
1424 * If this happens, the file has been truncated behind our
1425 * back since we opened it. Treat it like a trailing hole.
1426 * H4. offs < 0, errno != ENXIO: we learned nothing
1427 * Pretend we know nothing at all, i.e. "forget" about D1.
1429 offs
= glfs_lseek(s
->fd
, start
, SEEK_HOLE
);
1431 return -errno
; /* D1 and (H3 or H4) */
1435 /* This is not a valid return by lseek(). We are safe to just return
1436 * -EIO in this case, and we'll treat it like H4. Unfortunately some
1437 * versions of gluster server will return offs < start, so an assert
1438 * here will unnecessarily abort QEMU. */
1444 * D1 and H2: either in data, next hole at offs, or it was in
1445 * data but is now in a trailing hole. In the latter case,
1446 * all bets are off. Treating it as if it there was data all
1447 * the way to EOF is safe, so simply do that.
1463 * Returns the allocation status of the specified offset.
1465 * The block layer guarantees 'offset' and 'bytes' are within bounds.
1467 * 'pnum' is set to the number of bytes (including and immediately following
1468 * the specified offset) that are known to be in the same
1469 * allocated/unallocated state.
1471 * 'bytes' is the max value 'pnum' should be set to.
1473 * (Based on raw_co_block_status() from file-posix.c.)
1475 static int coroutine_fn
qemu_gluster_co_block_status(BlockDriverState
*bs
,
1481 BlockDriverState
**file
)
1483 BDRVGlusterState
*s
= bs
->opaque
;
1484 off_t data
= 0, hole
= 0;
1495 return BDRV_BLOCK_DATA
| BDRV_BLOCK_OFFSET_VALID
;
1498 ret
= find_allocation(bs
, offset
, &data
, &hole
);
1499 if (ret
== -ENXIO
) {
1502 ret
= BDRV_BLOCK_ZERO
;
1503 } else if (ret
< 0) {
1504 /* No info available, so pretend there are no holes */
1506 ret
= BDRV_BLOCK_DATA
;
1507 } else if (data
== offset
) {
1508 /* On a data extent, compute bytes to the end of the extent,
1509 * possibly including a partial sector at EOF. */
1510 *pnum
= MIN(bytes
, hole
- offset
);
1511 ret
= BDRV_BLOCK_DATA
;
1513 /* On a hole, compute bytes to the beginning of the next extent. */
1514 assert(hole
== offset
);
1515 *pnum
= MIN(bytes
, data
- offset
);
1516 ret
= BDRV_BLOCK_ZERO
;
1522 return ret
| BDRV_BLOCK_OFFSET_VALID
;
1526 static const char *const gluster_strong_open_opts
[] = {
1530 GLUSTER_OPT_SERVER_PATTERN
,
1541 static BlockDriver bdrv_gluster
= {
1542 .format_name
= "gluster",
1543 .protocol_name
= "gluster",
1544 .instance_size
= sizeof(BDRVGlusterState
),
1545 .bdrv_needs_filename
= false,
1546 .bdrv_file_open
= qemu_gluster_open
,
1547 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1548 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1549 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1550 .bdrv_close
= qemu_gluster_close
,
1551 .bdrv_co_create
= qemu_gluster_co_create
,
1552 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1553 .bdrv_getlength
= qemu_gluster_getlength
,
1554 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1555 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1556 .bdrv_co_readv
= qemu_gluster_co_readv
,
1557 .bdrv_co_writev
= qemu_gluster_co_writev
,
1558 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1559 #ifdef CONFIG_GLUSTERFS_DISCARD
1560 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1562 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1563 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1565 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1566 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1567 .create_opts
= &qemu_gluster_create_opts
,
1568 .strong_runtime_opts
= gluster_strong_open_opts
,
1571 static BlockDriver bdrv_gluster_tcp
= {
1572 .format_name
= "gluster",
1573 .protocol_name
= "gluster+tcp",
1574 .instance_size
= sizeof(BDRVGlusterState
),
1575 .bdrv_needs_filename
= false,
1576 .bdrv_file_open
= qemu_gluster_open
,
1577 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1578 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1579 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1580 .bdrv_close
= qemu_gluster_close
,
1581 .bdrv_co_create
= qemu_gluster_co_create
,
1582 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1583 .bdrv_getlength
= qemu_gluster_getlength
,
1584 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1585 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1586 .bdrv_co_readv
= qemu_gluster_co_readv
,
1587 .bdrv_co_writev
= qemu_gluster_co_writev
,
1588 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1589 #ifdef CONFIG_GLUSTERFS_DISCARD
1590 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1592 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1593 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1595 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1596 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1597 .create_opts
= &qemu_gluster_create_opts
,
1598 .strong_runtime_opts
= gluster_strong_open_opts
,
1601 static BlockDriver bdrv_gluster_unix
= {
1602 .format_name
= "gluster",
1603 .protocol_name
= "gluster+unix",
1604 .instance_size
= sizeof(BDRVGlusterState
),
1605 .bdrv_needs_filename
= true,
1606 .bdrv_file_open
= qemu_gluster_open
,
1607 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1608 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1609 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1610 .bdrv_close
= qemu_gluster_close
,
1611 .bdrv_co_create
= qemu_gluster_co_create
,
1612 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1613 .bdrv_getlength
= qemu_gluster_getlength
,
1614 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1615 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1616 .bdrv_co_readv
= qemu_gluster_co_readv
,
1617 .bdrv_co_writev
= qemu_gluster_co_writev
,
1618 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1619 #ifdef CONFIG_GLUSTERFS_DISCARD
1620 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1622 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1623 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1625 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1626 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1627 .create_opts
= &qemu_gluster_create_opts
,
1628 .strong_runtime_opts
= gluster_strong_open_opts
,
1631 /* rdma is deprecated (actually never supported for volfile fetch).
1632 * Let's maintain it for the protocol compatibility, to make sure things
1633 * won't break immediately. For now, gluster+rdma will fall back to gluster+tcp
1634 * protocol with a warning.
1635 * TODO: remove gluster+rdma interface support
1637 static BlockDriver bdrv_gluster_rdma
= {
1638 .format_name
= "gluster",
1639 .protocol_name
= "gluster+rdma",
1640 .instance_size
= sizeof(BDRVGlusterState
),
1641 .bdrv_needs_filename
= true,
1642 .bdrv_file_open
= qemu_gluster_open
,
1643 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1644 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1645 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1646 .bdrv_close
= qemu_gluster_close
,
1647 .bdrv_co_create
= qemu_gluster_co_create
,
1648 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1649 .bdrv_getlength
= qemu_gluster_getlength
,
1650 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1651 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1652 .bdrv_co_readv
= qemu_gluster_co_readv
,
1653 .bdrv_co_writev
= qemu_gluster_co_writev
,
1654 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1655 #ifdef CONFIG_GLUSTERFS_DISCARD
1656 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1658 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1659 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1661 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1662 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1663 .create_opts
= &qemu_gluster_create_opts
,
1664 .strong_runtime_opts
= gluster_strong_open_opts
,
1667 static void bdrv_gluster_init(void)
1669 bdrv_register(&bdrv_gluster_rdma
);
1670 bdrv_register(&bdrv_gluster_unix
);
1671 bdrv_register(&bdrv_gluster_tcp
);
1672 bdrv_register(&bdrv_gluster
);
1675 block_init(bdrv_gluster_init
);