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 <glusterfs/api/glfs.h>
13 #include "block/block_int.h"
14 #include "block/qdict.h"
15 #include "qapi/error.h"
16 #include "qapi/qmp/qdict.h"
17 #include "qapi/qmp/qerror.h"
19 #include "qemu/error-report.h"
20 #include "qemu/option.h"
21 #include "qemu/cutils.h"
23 #ifdef CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT
24 # define glfs_ftruncate(fd, offset) glfs_ftruncate(fd, offset, NULL, NULL)
27 #define GLUSTER_OPT_FILENAME "filename"
28 #define GLUSTER_OPT_VOLUME "volume"
29 #define GLUSTER_OPT_PATH "path"
30 #define GLUSTER_OPT_TYPE "type"
31 #define GLUSTER_OPT_SERVER_PATTERN "server."
32 #define GLUSTER_OPT_HOST "host"
33 #define GLUSTER_OPT_PORT "port"
34 #define GLUSTER_OPT_TO "to"
35 #define GLUSTER_OPT_IPV4 "ipv4"
36 #define GLUSTER_OPT_IPV6 "ipv6"
37 #define GLUSTER_OPT_SOCKET "socket"
38 #define GLUSTER_OPT_DEBUG "debug"
39 #define GLUSTER_DEFAULT_PORT 24007
40 #define GLUSTER_DEBUG_DEFAULT 4
41 #define GLUSTER_DEBUG_MAX 9
42 #define GLUSTER_OPT_LOGFILE "logfile"
43 #define GLUSTER_LOGFILE_DEFAULT "-" /* handled in libgfapi as /dev/stderr */
45 #define GERR_INDEX_HINT "hint: check in 'server' array index '%d'\n"
47 typedef struct GlusterAIOCB
{
51 AioContext
*aio_context
;
54 typedef struct BDRVGlusterState
{
58 bool supports_seek_data
;
62 typedef struct BDRVGlusterReopenState
{
65 } BDRVGlusterReopenState
;
68 typedef struct GlfsPreopened
{
74 typedef struct ListElement
{
75 QLIST_ENTRY(ListElement
) list
;
79 static QLIST_HEAD(, ListElement
) glfs_list
;
81 static QemuOptsList qemu_gluster_create_opts
= {
82 .name
= "qemu-gluster-create-opts",
83 .head
= QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts
.head
),
86 .name
= BLOCK_OPT_SIZE
,
87 .type
= QEMU_OPT_SIZE
,
88 .help
= "Virtual disk size"
91 .name
= BLOCK_OPT_PREALLOC
,
92 .type
= QEMU_OPT_STRING
,
93 .help
= "Preallocation mode (allowed values: off, full)"
96 .name
= GLUSTER_OPT_DEBUG
,
97 .type
= QEMU_OPT_NUMBER
,
98 .help
= "Gluster log level, valid range is 0-9",
101 .name
= GLUSTER_OPT_LOGFILE
,
102 .type
= QEMU_OPT_STRING
,
103 .help
= "Logfile path of libgfapi",
105 { /* end of list */ }
109 static QemuOptsList runtime_opts
= {
111 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
114 .name
= GLUSTER_OPT_FILENAME
,
115 .type
= QEMU_OPT_STRING
,
116 .help
= "URL to the gluster image",
119 .name
= GLUSTER_OPT_DEBUG
,
120 .type
= QEMU_OPT_NUMBER
,
121 .help
= "Gluster log level, valid range is 0-9",
124 .name
= GLUSTER_OPT_LOGFILE
,
125 .type
= QEMU_OPT_STRING
,
126 .help
= "Logfile path of libgfapi",
128 { /* end of list */ }
132 static QemuOptsList runtime_json_opts
= {
133 .name
= "gluster_json",
134 .head
= QTAILQ_HEAD_INITIALIZER(runtime_json_opts
.head
),
137 .name
= GLUSTER_OPT_VOLUME
,
138 .type
= QEMU_OPT_STRING
,
139 .help
= "name of gluster volume where VM image resides",
142 .name
= GLUSTER_OPT_PATH
,
143 .type
= QEMU_OPT_STRING
,
144 .help
= "absolute path to image file in gluster volume",
147 .name
= GLUSTER_OPT_DEBUG
,
148 .type
= QEMU_OPT_NUMBER
,
149 .help
= "Gluster log level, valid range is 0-9",
151 { /* end of list */ }
155 static QemuOptsList runtime_type_opts
= {
156 .name
= "gluster_type",
157 .head
= QTAILQ_HEAD_INITIALIZER(runtime_type_opts
.head
),
160 .name
= GLUSTER_OPT_TYPE
,
161 .type
= QEMU_OPT_STRING
,
164 { /* end of list */ }
168 static QemuOptsList runtime_unix_opts
= {
169 .name
= "gluster_unix",
170 .head
= QTAILQ_HEAD_INITIALIZER(runtime_unix_opts
.head
),
173 .name
= GLUSTER_OPT_SOCKET
,
174 .type
= QEMU_OPT_STRING
,
175 .help
= "socket file path (legacy)",
178 .name
= GLUSTER_OPT_PATH
,
179 .type
= QEMU_OPT_STRING
,
180 .help
= "socket file path (QAPI)",
182 { /* end of list */ }
186 static QemuOptsList runtime_inet_opts
= {
187 .name
= "gluster_inet",
188 .head
= QTAILQ_HEAD_INITIALIZER(runtime_inet_opts
.head
),
191 .name
= GLUSTER_OPT_TYPE
,
192 .type
= QEMU_OPT_STRING
,
196 .name
= GLUSTER_OPT_HOST
,
197 .type
= QEMU_OPT_STRING
,
198 .help
= "host address (hostname/ipv4/ipv6 addresses)",
201 .name
= GLUSTER_OPT_PORT
,
202 .type
= QEMU_OPT_STRING
,
203 .help
= "port number on which glusterd is listening (default 24007)",
207 .type
= QEMU_OPT_NUMBER
,
208 .help
= "max port number, not supported by gluster",
212 .type
= QEMU_OPT_BOOL
,
213 .help
= "ipv4 bool value, not supported by gluster",
217 .type
= QEMU_OPT_BOOL
,
218 .help
= "ipv6 bool value, not supported by gluster",
220 { /* end of list */ }
224 static void glfs_set_preopened(const char *volume
, glfs_t
*fs
)
226 ListElement
*entry
= NULL
;
228 entry
= g_new(ListElement
, 1);
230 entry
->saved
.volume
= g_strdup(volume
);
232 entry
->saved
.fs
= fs
;
233 entry
->saved
.ref
= 1;
235 QLIST_INSERT_HEAD(&glfs_list
, entry
, list
);
238 static glfs_t
*glfs_find_preopened(const char *volume
)
240 ListElement
*entry
= NULL
;
242 QLIST_FOREACH(entry
, &glfs_list
, list
) {
243 if (strcmp(entry
->saved
.volume
, volume
) == 0) {
245 return entry
->saved
.fs
;
252 static void glfs_clear_preopened(glfs_t
*fs
)
254 ListElement
*entry
= NULL
;
261 QLIST_FOREACH_SAFE(entry
, &glfs_list
, list
, next
) {
262 if (entry
->saved
.fs
== fs
) {
263 if (--entry
->saved
.ref
) {
267 QLIST_REMOVE(entry
, list
);
269 glfs_fini(entry
->saved
.fs
);
270 g_free(entry
->saved
.volume
);
276 static int parse_volume_options(BlockdevOptionsGluster
*gconf
, char *path
)
285 p
= q
= path
+ strspn(path
, "/");
286 p
+= strcspn(p
, "/");
290 gconf
->volume
= g_strndup(q
, p
- q
);
297 gconf
->path
= g_strdup(p
);
302 * file=gluster[+transport]://[host[:port]]/volume/path[?socket=...]
304 * 'gluster' is the protocol.
306 * 'transport' specifies the transport type used to connect to gluster
307 * management daemon (glusterd). Valid transport types are
308 * tcp or unix. If a transport type isn't specified, then tcp type is assumed.
310 * 'host' specifies the host where the volume file specification for
311 * the given volume resides. This can be either hostname or ipv4 address.
312 * If transport type is 'unix', then 'host' field should not be specified.
313 * The 'socket' field needs to be populated with the path to unix domain
316 * 'port' is the port number on which glusterd is listening. This is optional
317 * and if not specified, QEMU will send 0 which will make gluster to use the
318 * default port. If the transport type is unix, then 'port' should not be
321 * 'volume' is the name of the gluster volume which contains the VM image.
323 * 'path' is the path to the actual VM image that resides on gluster volume.
327 * file=gluster://1.2.3.4/testvol/a.img
328 * file=gluster+tcp://1.2.3.4/testvol/a.img
329 * file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
330 * file=gluster+tcp://host.domain.com:24007/testvol/dir/a.img
331 * file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
333 static int qemu_gluster_parse_uri(BlockdevOptionsGluster
*gconf
,
334 const char *filename
)
336 SocketAddress
*gsconf
;
338 QueryParams
*qp
= NULL
;
339 bool is_unix
= false;
342 uri
= uri_parse(filename
);
347 gconf
->server
= g_new0(SocketAddressList
, 1);
348 gconf
->server
->value
= gsconf
= g_new0(SocketAddress
, 1);
351 if (!uri
->scheme
|| !strcmp(uri
->scheme
, "gluster")) {
352 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
353 } else if (!strcmp(uri
->scheme
, "gluster+tcp")) {
354 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
355 } else if (!strcmp(uri
->scheme
, "gluster+unix")) {
356 gsconf
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
358 } else if (!strcmp(uri
->scheme
, "gluster+rdma")) {
359 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
360 warn_report("rdma feature is not supported, falling back to tcp");
366 ret
= parse_volume_options(gconf
, uri
->path
);
371 qp
= query_params_parse(uri
->query
);
372 if (qp
->n
> 1 || (is_unix
&& !qp
->n
) || (!is_unix
&& qp
->n
)) {
378 if (uri
->server
|| uri
->port
) {
382 if (strcmp(qp
->p
[0].name
, "socket")) {
386 gsconf
->u
.q_unix
.path
= g_strdup(qp
->p
[0].value
);
388 gsconf
->u
.inet
.host
= g_strdup(uri
->server
? uri
->server
: "localhost");
390 gsconf
->u
.inet
.port
= g_strdup_printf("%d", uri
->port
);
392 gsconf
->u
.inet
.port
= g_strdup_printf("%d", GLUSTER_DEFAULT_PORT
);
398 query_params_free(qp
);
404 static struct glfs
*qemu_gluster_glfs_init(BlockdevOptionsGluster
*gconf
,
410 SocketAddressList
*server
;
411 unsigned long long port
;
413 glfs
= glfs_find_preopened(gconf
->volume
);
418 glfs
= glfs_new(gconf
->volume
);
423 glfs_set_preopened(gconf
->volume
, glfs
);
425 for (server
= gconf
->server
; server
; server
= server
->next
) {
426 switch (server
->value
->type
) {
427 case SOCKET_ADDRESS_TYPE_UNIX
:
428 ret
= glfs_set_volfile_server(glfs
, "unix",
429 server
->value
->u
.q_unix
.path
, 0);
431 case SOCKET_ADDRESS_TYPE_INET
:
432 if (parse_uint_full(server
->value
->u
.inet
.port
, &port
, 10) < 0 ||
434 error_setg(errp
, "'%s' is not a valid port number",
435 server
->value
->u
.inet
.port
);
439 ret
= glfs_set_volfile_server(glfs
, "tcp",
440 server
->value
->u
.inet
.host
,
443 case SOCKET_ADDRESS_TYPE_VSOCK
:
444 case SOCKET_ADDRESS_TYPE_FD
:
454 ret
= glfs_set_logging(glfs
, gconf
->logfile
, gconf
->debug
);
459 ret
= glfs_init(glfs
);
461 error_setg(errp
, "Gluster connection for volume %s, path %s failed"
462 " to connect", gconf
->volume
, gconf
->path
);
463 for (server
= gconf
->server
; server
; server
= server
->next
) {
464 if (server
->value
->type
== SOCKET_ADDRESS_TYPE_UNIX
) {
465 error_append_hint(errp
, "hint: failed on socket %s ",
466 server
->value
->u
.q_unix
.path
);
468 error_append_hint(errp
, "hint: failed on host %s and port %s ",
469 server
->value
->u
.inet
.host
,
470 server
->value
->u
.inet
.port
);
474 error_append_hint(errp
, "Please refer to gluster logs for more info\n");
476 /* glfs_init sometimes doesn't set errno although docs suggest that */
488 glfs_clear_preopened(glfs
);
495 * Convert the json formatted command line into qapi.
497 static int qemu_gluster_parse_json(BlockdevOptionsGluster
*gconf
,
498 QDict
*options
, Error
**errp
)
501 SocketAddress
*gsconf
= NULL
;
502 SocketAddressList
*curr
= NULL
;
503 QDict
*backing_options
= NULL
;
504 Error
*local_err
= NULL
;
507 int i
, type
, num_servers
;
509 /* create opts info from runtime_json_opts list */
510 opts
= qemu_opts_create(&runtime_json_opts
, NULL
, 0, &error_abort
);
511 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
516 num_servers
= qdict_array_entries(options
, GLUSTER_OPT_SERVER_PATTERN
);
517 if (num_servers
< 1) {
518 error_setg(&local_err
, QERR_MISSING_PARAMETER
, "server");
522 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_VOLUME
);
524 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_VOLUME
);
527 gconf
->volume
= g_strdup(ptr
);
529 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
531 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_PATH
);
534 gconf
->path
= g_strdup(ptr
);
537 for (i
= 0; i
< num_servers
; i
++) {
538 str
= g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN
"%d.", i
);
539 qdict_extract_subqdict(options
, &backing_options
, str
);
541 /* create opts info from runtime_type_opts list */
542 opts
= qemu_opts_create(&runtime_type_opts
, NULL
, 0, &error_abort
);
543 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
548 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TYPE
);
550 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_TYPE
);
551 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
555 gsconf
= g_new0(SocketAddress
, 1);
556 if (!strcmp(ptr
, "tcp")) {
557 ptr
= "inet"; /* accept legacy "tcp" */
559 type
= qapi_enum_parse(&SocketAddressType_lookup
, ptr
, -1, NULL
);
560 if (type
!= SOCKET_ADDRESS_TYPE_INET
561 && type
!= SOCKET_ADDRESS_TYPE_UNIX
) {
562 error_setg(&local_err
,
563 "Parameter '%s' may be 'inet' or 'unix'",
565 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
571 if (gsconf
->type
== SOCKET_ADDRESS_TYPE_INET
) {
572 /* create opts info from runtime_inet_opts list */
573 opts
= qemu_opts_create(&runtime_inet_opts
, NULL
, 0, &error_abort
);
574 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
579 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_HOST
);
581 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
583 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
586 gsconf
->u
.inet
.host
= g_strdup(ptr
);
587 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PORT
);
589 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
591 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
594 gsconf
->u
.inet
.port
= g_strdup(ptr
);
596 /* defend for unsupported fields in InetSocketAddress,
597 * i.e. @ipv4, @ipv6 and @to
599 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TO
);
601 gsconf
->u
.inet
.has_to
= true;
603 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV4
);
605 gsconf
->u
.inet
.has_ipv4
= true;
607 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV6
);
609 gsconf
->u
.inet
.has_ipv6
= true;
611 if (gsconf
->u
.inet
.has_to
) {
612 error_setg(&local_err
, "Parameter 'to' not supported");
615 if (gsconf
->u
.inet
.has_ipv4
|| gsconf
->u
.inet
.has_ipv6
) {
616 error_setg(&local_err
, "Parameters 'ipv4/ipv6' not supported");
621 /* create opts info from runtime_unix_opts list */
622 opts
= qemu_opts_create(&runtime_unix_opts
, NULL
, 0, &error_abort
);
623 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
628 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
630 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
);
631 } else if (qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
)) {
632 error_setg(&local_err
,
633 "Conflicting parameters 'path' and 'socket'");
634 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
638 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
640 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
643 gsconf
->u
.q_unix
.path
= g_strdup(ptr
);
647 if (gconf
->server
== NULL
) {
648 gconf
->server
= g_new0(SocketAddressList
, 1);
649 gconf
->server
->value
= gsconf
;
650 curr
= gconf
->server
;
652 curr
->next
= g_new0(SocketAddressList
, 1);
653 curr
->next
->value
= gsconf
;
658 qobject_unref(backing_options
);
659 backing_options
= NULL
;
667 error_propagate(errp
, local_err
);
668 qapi_free_SocketAddress(gsconf
);
671 qobject_unref(backing_options
);
676 /* Converts options given in @filename and the @options QDict into the QAPI
678 static int qemu_gluster_parse(BlockdevOptionsGluster
*gconf
,
679 const char *filename
,
680 QDict
*options
, Error
**errp
)
684 ret
= qemu_gluster_parse_uri(gconf
, filename
);
686 error_setg(errp
, "invalid URI %s", filename
);
687 error_append_hint(errp
, "Usage: file=gluster[+transport]://"
688 "[host[:port]]volume/path[?socket=...]"
690 "[,file.logfile=/path/filename.log]\n");
694 ret
= qemu_gluster_parse_json(gconf
, options
, errp
);
696 error_append_hint(errp
, "Usage: "
697 "-drive driver=qcow2,file.driver=gluster,"
698 "file.volume=testvol,file.path=/path/a.qcow2"
700 "[,file.logfile=/path/filename.log],"
701 "file.server.0.type=inet,"
702 "file.server.0.host=1.2.3.4,"
703 "file.server.0.port=24007,"
704 "file.server.1.transport=unix,"
705 "file.server.1.path=/var/run/glusterd.socket ..."
714 static struct glfs
*qemu_gluster_init(BlockdevOptionsGluster
*gconf
,
715 const char *filename
,
716 QDict
*options
, Error
**errp
)
720 ret
= qemu_gluster_parse(gconf
, filename
, options
, errp
);
726 return qemu_gluster_glfs_init(gconf
, errp
);
730 * AIO callback routine called from GlusterFS thread.
732 static void gluster_finish_aiocb(struct glfs_fd
*fd
, ssize_t ret
, void *arg
)
734 GlusterAIOCB
*acb
= (GlusterAIOCB
*)arg
;
736 if (!ret
|| ret
== acb
->size
) {
737 acb
->ret
= 0; /* Success */
738 } else if (ret
< 0) {
739 acb
->ret
= -errno
; /* Read/Write failed */
741 acb
->ret
= -EIO
; /* Partial read/write - fail it */
744 aio_co_schedule(acb
->aio_context
, acb
->coroutine
);
747 static void qemu_gluster_parse_flags(int bdrv_flags
, int *open_flags
)
749 assert(open_flags
!= NULL
);
751 *open_flags
|= O_BINARY
;
753 if (bdrv_flags
& BDRV_O_RDWR
) {
754 *open_flags
|= O_RDWR
;
756 *open_flags
|= O_RDONLY
;
759 if ((bdrv_flags
& BDRV_O_NOCACHE
)) {
760 *open_flags
|= O_DIRECT
;
765 * Do SEEK_DATA/HOLE to detect if it is functional. Older broken versions of
766 * gfapi incorrectly return the current offset when SEEK_DATA/HOLE is used.
767 * - Corrected versions return -1 and set errno to EINVAL.
768 * - Versions that support SEEK_DATA/HOLE correctly, will return -1 and set
769 * errno to ENXIO when SEEK_DATA is called with a position of EOF.
771 static bool qemu_gluster_test_seek(struct glfs_fd
*fd
)
775 #if defined SEEK_HOLE && defined SEEK_DATA
778 eof
= glfs_lseek(fd
, 0, SEEK_END
);
780 /* this should never occur */
784 /* this should always fail with ENXIO if SEEK_DATA is supported */
785 ret
= glfs_lseek(fd
, eof
, SEEK_DATA
);
788 return (ret
< 0) && (errno
== ENXIO
);
791 static int qemu_gluster_open(BlockDriverState
*bs
, QDict
*options
,
792 int bdrv_flags
, Error
**errp
)
794 BDRVGlusterState
*s
= bs
->opaque
;
797 BlockdevOptionsGluster
*gconf
= NULL
;
799 Error
*local_err
= NULL
;
800 const char *filename
, *logfile
;
802 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
803 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
805 error_propagate(errp
, local_err
);
810 filename
= qemu_opt_get(opts
, GLUSTER_OPT_FILENAME
);
812 s
->debug
= qemu_opt_get_number(opts
, GLUSTER_OPT_DEBUG
,
813 GLUSTER_DEBUG_DEFAULT
);
816 } else if (s
->debug
> GLUSTER_DEBUG_MAX
) {
817 s
->debug
= GLUSTER_DEBUG_MAX
;
820 gconf
= g_new0(BlockdevOptionsGluster
, 1);
821 gconf
->debug
= s
->debug
;
822 gconf
->has_debug
= true;
824 logfile
= qemu_opt_get(opts
, GLUSTER_OPT_LOGFILE
);
825 s
->logfile
= g_strdup(logfile
? logfile
: GLUSTER_LOGFILE_DEFAULT
);
827 gconf
->logfile
= g_strdup(s
->logfile
);
828 gconf
->has_logfile
= true;
830 s
->glfs
= qemu_gluster_init(gconf
, filename
, options
, errp
);
836 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
837 /* Without this, if fsync fails for a recoverable reason (for instance,
838 * ENOSPC), gluster will dump its cache, preventing retries. This means
839 * almost certain data loss. Not all gluster versions support the
840 * 'resync-failed-syncs-after-fsync' key value, but there is no way to
841 * discover during runtime if it is supported (this api returns success for
842 * unknown key/value pairs) */
843 ret
= glfs_set_xlator_option(s
->glfs
, "*-write-behind",
844 "resync-failed-syncs-after-fsync",
847 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
853 qemu_gluster_parse_flags(bdrv_flags
, &open_flags
);
855 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
856 ret
= s
->fd
? 0 : -errno
;
858 if (ret
== -EACCES
|| ret
== -EROFS
) {
859 /* Try to degrade to read-only, but if it doesn't work, still use the
860 * normal error message. */
861 if (bdrv_apply_auto_read_only(bs
, NULL
, NULL
) == 0) {
862 open_flags
= (open_flags
& ~O_RDWR
) | O_RDONLY
;
863 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
864 ret
= s
->fd
? 0 : -errno
;
868 s
->supports_seek_data
= qemu_gluster_test_seek(s
->fd
);
872 qapi_free_BlockdevOptionsGluster(gconf
);
881 glfs_clear_preopened(s
->glfs
);
886 static int qemu_gluster_reopen_prepare(BDRVReopenState
*state
,
887 BlockReopenQueue
*queue
, Error
**errp
)
891 BDRVGlusterReopenState
*reop_s
;
892 BlockdevOptionsGluster
*gconf
;
895 assert(state
!= NULL
);
896 assert(state
->bs
!= NULL
);
898 s
= state
->bs
->opaque
;
900 state
->opaque
= g_new0(BDRVGlusterReopenState
, 1);
901 reop_s
= state
->opaque
;
903 qemu_gluster_parse_flags(state
->flags
, &open_flags
);
905 gconf
= g_new0(BlockdevOptionsGluster
, 1);
906 gconf
->debug
= s
->debug
;
907 gconf
->has_debug
= true;
908 gconf
->logfile
= g_strdup(s
->logfile
);
909 gconf
->has_logfile
= true;
910 reop_s
->glfs
= qemu_gluster_init(gconf
, state
->bs
->filename
, NULL
, errp
);
911 if (reop_s
->glfs
== NULL
) {
916 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
917 ret
= glfs_set_xlator_option(reop_s
->glfs
, "*-write-behind",
918 "resync-failed-syncs-after-fsync", "on");
920 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
926 reop_s
->fd
= glfs_open(reop_s
->glfs
, gconf
->path
, open_flags
);
927 if (reop_s
->fd
== NULL
) {
928 /* reops->glfs will be cleaned up in _abort */
934 /* state->opaque will be freed in either the _abort or _commit */
935 qapi_free_BlockdevOptionsGluster(gconf
);
939 static void qemu_gluster_reopen_commit(BDRVReopenState
*state
)
941 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
942 BDRVGlusterState
*s
= state
->bs
->opaque
;
950 glfs_clear_preopened(s
->glfs
);
952 /* use the newly opened image / connection */
954 s
->glfs
= reop_s
->glfs
;
956 g_free(state
->opaque
);
957 state
->opaque
= NULL
;
963 static void qemu_gluster_reopen_abort(BDRVReopenState
*state
)
965 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
967 if (reop_s
== NULL
) {
972 glfs_close(reop_s
->fd
);
975 glfs_clear_preopened(reop_s
->glfs
);
977 g_free(state
->opaque
);
978 state
->opaque
= NULL
;
983 #ifdef CONFIG_GLUSTERFS_ZEROFILL
984 static coroutine_fn
int qemu_gluster_co_pwrite_zeroes(BlockDriverState
*bs
,
987 BdrvRequestFlags flags
)
991 BDRVGlusterState
*s
= bs
->opaque
;
995 acb
.coroutine
= qemu_coroutine_self();
996 acb
.aio_context
= bdrv_get_aio_context(bs
);
998 ret
= glfs_zerofill_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1003 qemu_coroutine_yield();
1008 static int qemu_gluster_do_truncate(struct glfs_fd
*fd
, int64_t offset
,
1009 PreallocMode prealloc
, Error
**errp
)
1011 int64_t current_length
;
1013 current_length
= glfs_lseek(fd
, 0, SEEK_END
);
1014 if (current_length
< 0) {
1015 error_setg_errno(errp
, errno
, "Failed to determine current size");
1019 if (current_length
> offset
&& prealloc
!= PREALLOC_MODE_OFF
) {
1020 error_setg(errp
, "Cannot use preallocation for shrinking files");
1024 if (current_length
== offset
) {
1029 #ifdef CONFIG_GLUSTERFS_FALLOCATE
1030 case PREALLOC_MODE_FALLOC
:
1031 if (glfs_fallocate(fd
, 0, current_length
, offset
- current_length
)) {
1032 error_setg_errno(errp
, errno
, "Could not preallocate data");
1036 #endif /* CONFIG_GLUSTERFS_FALLOCATE */
1037 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1038 case PREALLOC_MODE_FULL
:
1039 if (glfs_ftruncate(fd
, offset
)) {
1040 error_setg_errno(errp
, errno
, "Could not resize file");
1043 if (glfs_zerofill(fd
, current_length
, offset
- current_length
)) {
1044 error_setg_errno(errp
, errno
, "Could not zerofill the new area");
1048 #endif /* CONFIG_GLUSTERFS_ZEROFILL */
1049 case PREALLOC_MODE_OFF
:
1050 if (glfs_ftruncate(fd
, offset
)) {
1051 error_setg_errno(errp
, errno
, "Could not resize file");
1056 error_setg(errp
, "Unsupported preallocation mode: %s",
1057 PreallocMode_str(prealloc
));
1064 static int qemu_gluster_co_create(BlockdevCreateOptions
*options
,
1067 BlockdevCreateOptionsGluster
*opts
= &options
->u
.gluster
;
1069 struct glfs_fd
*fd
= NULL
;
1072 assert(options
->driver
== BLOCKDEV_DRIVER_GLUSTER
);
1074 glfs
= qemu_gluster_glfs_init(opts
->location
, errp
);
1080 fd
= glfs_creat(glfs
, opts
->location
->path
,
1081 O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, S_IRUSR
| S_IWUSR
);
1087 ret
= qemu_gluster_do_truncate(fd
, opts
->size
, opts
->preallocation
, errp
);
1091 if (glfs_close(fd
) != 0 && ret
== 0) {
1095 glfs_clear_preopened(glfs
);
1099 static int coroutine_fn
qemu_gluster_co_create_opts(const char *filename
,
1103 BlockdevCreateOptions
*options
;
1104 BlockdevCreateOptionsGluster
*gopts
;
1105 BlockdevOptionsGluster
*gconf
;
1107 Error
*local_err
= NULL
;
1110 options
= g_new0(BlockdevCreateOptions
, 1);
1111 options
->driver
= BLOCKDEV_DRIVER_GLUSTER
;
1112 gopts
= &options
->u
.gluster
;
1114 gconf
= g_new0(BlockdevOptionsGluster
, 1);
1115 gopts
->location
= gconf
;
1117 gopts
->size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
1120 tmp
= qemu_opt_get_del(opts
, BLOCK_OPT_PREALLOC
);
1121 gopts
->preallocation
= qapi_enum_parse(&PreallocMode_lookup
, tmp
,
1122 PREALLOC_MODE_OFF
, &local_err
);
1125 error_propagate(errp
, local_err
);
1130 gconf
->debug
= qemu_opt_get_number_del(opts
, GLUSTER_OPT_DEBUG
,
1131 GLUSTER_DEBUG_DEFAULT
);
1132 if (gconf
->debug
< 0) {
1134 } else if (gconf
->debug
> GLUSTER_DEBUG_MAX
) {
1135 gconf
->debug
= GLUSTER_DEBUG_MAX
;
1137 gconf
->has_debug
= true;
1139 gconf
->logfile
= qemu_opt_get_del(opts
, GLUSTER_OPT_LOGFILE
);
1140 if (!gconf
->logfile
) {
1141 gconf
->logfile
= g_strdup(GLUSTER_LOGFILE_DEFAULT
);
1143 gconf
->has_logfile
= true;
1145 ret
= qemu_gluster_parse(gconf
, filename
, NULL
, errp
);
1150 ret
= qemu_gluster_co_create(options
, errp
);
1157 qapi_free_BlockdevCreateOptions(options
);
1161 static coroutine_fn
int qemu_gluster_co_rw(BlockDriverState
*bs
,
1162 int64_t sector_num
, int nb_sectors
,
1163 QEMUIOVector
*qiov
, int write
)
1167 BDRVGlusterState
*s
= bs
->opaque
;
1168 size_t size
= nb_sectors
* BDRV_SECTOR_SIZE
;
1169 off_t offset
= sector_num
* BDRV_SECTOR_SIZE
;
1173 acb
.coroutine
= qemu_coroutine_self();
1174 acb
.aio_context
= bdrv_get_aio_context(bs
);
1177 ret
= glfs_pwritev_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1178 gluster_finish_aiocb
, &acb
);
1180 ret
= glfs_preadv_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1181 gluster_finish_aiocb
, &acb
);
1188 qemu_coroutine_yield();
1192 static coroutine_fn
int qemu_gluster_co_truncate(BlockDriverState
*bs
,
1194 PreallocMode prealloc
,
1197 BDRVGlusterState
*s
= bs
->opaque
;
1198 return qemu_gluster_do_truncate(s
->fd
, offset
, prealloc
, errp
);
1201 static coroutine_fn
int qemu_gluster_co_readv(BlockDriverState
*bs
,
1206 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 0);
1209 static coroutine_fn
int qemu_gluster_co_writev(BlockDriverState
*bs
,
1216 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 1);
1219 static void qemu_gluster_close(BlockDriverState
*bs
)
1221 BDRVGlusterState
*s
= bs
->opaque
;
1228 glfs_clear_preopened(s
->glfs
);
1231 static coroutine_fn
int qemu_gluster_co_flush_to_disk(BlockDriverState
*bs
)
1235 BDRVGlusterState
*s
= bs
->opaque
;
1239 acb
.coroutine
= qemu_coroutine_self();
1240 acb
.aio_context
= bdrv_get_aio_context(bs
);
1242 ret
= glfs_fsync_async(s
->fd
, gluster_finish_aiocb
, &acb
);
1248 qemu_coroutine_yield();
1257 /* Some versions of Gluster (3.5.6 -> 3.5.8?) will not retain its cache
1258 * after a fsync failure, so we have no way of allowing the guest to safely
1259 * continue. Gluster versions prior to 3.5.6 don't retain the cache
1260 * either, but will invalidate the fd on error, so this is again our only
1263 * The 'resync-failed-syncs-after-fsync' xlator option for the
1264 * write-behind cache will cause later gluster versions to retain its
1265 * cache after error, so long as the fd remains open. However, we
1266 * currently have no way of knowing if this option is supported.
1268 * TODO: Once gluster provides a way for us to determine if the option
1269 * is supported, bypass the closure and setting drv to NULL. */
1270 qemu_gluster_close(bs
);
1275 #ifdef CONFIG_GLUSTERFS_DISCARD
1276 static coroutine_fn
int qemu_gluster_co_pdiscard(BlockDriverState
*bs
,
1277 int64_t offset
, int size
)
1281 BDRVGlusterState
*s
= bs
->opaque
;
1285 acb
.coroutine
= qemu_coroutine_self();
1286 acb
.aio_context
= bdrv_get_aio_context(bs
);
1288 ret
= glfs_discard_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1293 qemu_coroutine_yield();
1298 static int64_t qemu_gluster_getlength(BlockDriverState
*bs
)
1300 BDRVGlusterState
*s
= bs
->opaque
;
1303 ret
= glfs_lseek(s
->fd
, 0, SEEK_END
);
1311 static int64_t qemu_gluster_allocated_file_size(BlockDriverState
*bs
)
1313 BDRVGlusterState
*s
= bs
->opaque
;
1317 ret
= glfs_fstat(s
->fd
, &st
);
1321 return st
.st_blocks
* 512;
1325 static int qemu_gluster_has_zero_init(BlockDriverState
*bs
)
1327 /* GlusterFS volume could be backed by a block device */
1332 * Find allocation range in @bs around offset @start.
1333 * May change underlying file descriptor's file offset.
1334 * If @start is not in a hole, store @start in @data, and the
1335 * beginning of the next hole in @hole, and return 0.
1336 * If @start is in a non-trailing hole, store @start in @hole and the
1337 * beginning of the next non-hole in @data, and return 0.
1338 * If @start is in a trailing hole or beyond EOF, return -ENXIO.
1339 * If we can't find out, return a negative errno other than -ENXIO.
1341 * (Shamefully copied from file-posix.c, only minuscule adaptions.)
1343 static int find_allocation(BlockDriverState
*bs
, off_t start
,
1344 off_t
*data
, off_t
*hole
)
1346 BDRVGlusterState
*s
= bs
->opaque
;
1348 if (!s
->supports_seek_data
) {
1352 #if defined SEEK_HOLE && defined SEEK_DATA
1357 * D1. offs == start: start is in data
1358 * D2. offs > start: start is in a hole, next data at offs
1359 * D3. offs < 0, errno = ENXIO: either start is in a trailing hole
1360 * or start is beyond EOF
1361 * If the latter happens, the file has been truncated behind
1362 * our back since we opened it. All bets are off then.
1363 * Treating like a trailing hole is simplest.
1364 * D4. offs < 0, errno != ENXIO: we learned nothing
1366 offs
= glfs_lseek(s
->fd
, start
, SEEK_DATA
);
1368 return -errno
; /* D3 or D4 */
1372 /* This is not a valid return by lseek(). We are safe to just return
1373 * -EIO in this case, and we'll treat it like D4. Unfortunately some
1374 * versions of gluster server will return offs < start, so an assert
1375 * here will unnecessarily abort QEMU. */
1380 /* D2: in hole, next data at offs */
1386 /* D1: in data, end not yet known */
1390 * H1. offs == start: start is in a hole
1391 * If this happens here, a hole has been dug behind our back
1392 * since the previous lseek().
1393 * H2. offs > start: either start is in data, next hole at offs,
1394 * or start is in trailing hole, EOF at offs
1395 * Linux treats trailing holes like any other hole: offs ==
1396 * start. Solaris seeks to EOF instead: offs > start (blech).
1397 * If that happens here, a hole has been dug behind our back
1398 * since the previous lseek().
1399 * H3. offs < 0, errno = ENXIO: start is beyond EOF
1400 * If this happens, the file has been truncated behind our
1401 * back since we opened it. Treat it like a trailing hole.
1402 * H4. offs < 0, errno != ENXIO: we learned nothing
1403 * Pretend we know nothing at all, i.e. "forget" about D1.
1405 offs
= glfs_lseek(s
->fd
, start
, SEEK_HOLE
);
1407 return -errno
; /* D1 and (H3 or H4) */
1411 /* This is not a valid return by lseek(). We are safe to just return
1412 * -EIO in this case, and we'll treat it like H4. Unfortunately some
1413 * versions of gluster server will return offs < start, so an assert
1414 * here will unnecessarily abort QEMU. */
1420 * D1 and H2: either in data, next hole at offs, or it was in
1421 * data but is now in a trailing hole. In the latter case,
1422 * all bets are off. Treating it as if it there was data all
1423 * the way to EOF is safe, so simply do that.
1439 * Returns the allocation status of the specified offset.
1441 * The block layer guarantees 'offset' and 'bytes' are within bounds.
1443 * 'pnum' is set to the number of bytes (including and immediately following
1444 * the specified offset) that are known to be in the same
1445 * allocated/unallocated state.
1447 * 'bytes' is the max value 'pnum' should be set to.
1449 * (Based on raw_co_block_status() from file-posix.c.)
1451 static int coroutine_fn
qemu_gluster_co_block_status(BlockDriverState
*bs
,
1457 BlockDriverState
**file
)
1459 BDRVGlusterState
*s
= bs
->opaque
;
1460 off_t data
= 0, hole
= 0;
1471 return BDRV_BLOCK_DATA
| BDRV_BLOCK_OFFSET_VALID
;
1474 ret
= find_allocation(bs
, offset
, &data
, &hole
);
1475 if (ret
== -ENXIO
) {
1478 ret
= BDRV_BLOCK_ZERO
;
1479 } else if (ret
< 0) {
1480 /* No info available, so pretend there are no holes */
1482 ret
= BDRV_BLOCK_DATA
;
1483 } else if (data
== offset
) {
1484 /* On a data extent, compute bytes to the end of the extent,
1485 * possibly including a partial sector at EOF. */
1486 *pnum
= MIN(bytes
, hole
- offset
);
1487 ret
= BDRV_BLOCK_DATA
;
1489 /* On a hole, compute bytes to the beginning of the next extent. */
1490 assert(hole
== offset
);
1491 *pnum
= MIN(bytes
, data
- offset
);
1492 ret
= BDRV_BLOCK_ZERO
;
1498 return ret
| BDRV_BLOCK_OFFSET_VALID
;
1502 static const char *const gluster_strong_open_opts
[] = {
1506 GLUSTER_OPT_SERVER_PATTERN
,
1517 static BlockDriver bdrv_gluster
= {
1518 .format_name
= "gluster",
1519 .protocol_name
= "gluster",
1520 .instance_size
= sizeof(BDRVGlusterState
),
1521 .bdrv_needs_filename
= false,
1522 .bdrv_file_open
= qemu_gluster_open
,
1523 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1524 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1525 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1526 .bdrv_close
= qemu_gluster_close
,
1527 .bdrv_co_create
= qemu_gluster_co_create
,
1528 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1529 .bdrv_getlength
= qemu_gluster_getlength
,
1530 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1531 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1532 .bdrv_co_readv
= qemu_gluster_co_readv
,
1533 .bdrv_co_writev
= qemu_gluster_co_writev
,
1534 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1535 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1536 #ifdef CONFIG_GLUSTERFS_DISCARD
1537 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1539 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1540 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1542 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1543 .create_opts
= &qemu_gluster_create_opts
,
1544 .strong_runtime_opts
= gluster_strong_open_opts
,
1547 static BlockDriver bdrv_gluster_tcp
= {
1548 .format_name
= "gluster",
1549 .protocol_name
= "gluster+tcp",
1550 .instance_size
= sizeof(BDRVGlusterState
),
1551 .bdrv_needs_filename
= false,
1552 .bdrv_file_open
= qemu_gluster_open
,
1553 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1554 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1555 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1556 .bdrv_close
= qemu_gluster_close
,
1557 .bdrv_co_create
= qemu_gluster_co_create
,
1558 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1559 .bdrv_getlength
= qemu_gluster_getlength
,
1560 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1561 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1562 .bdrv_co_readv
= qemu_gluster_co_readv
,
1563 .bdrv_co_writev
= qemu_gluster_co_writev
,
1564 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1565 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1566 #ifdef CONFIG_GLUSTERFS_DISCARD
1567 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1569 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1570 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1572 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1573 .create_opts
= &qemu_gluster_create_opts
,
1574 .strong_runtime_opts
= gluster_strong_open_opts
,
1577 static BlockDriver bdrv_gluster_unix
= {
1578 .format_name
= "gluster",
1579 .protocol_name
= "gluster+unix",
1580 .instance_size
= sizeof(BDRVGlusterState
),
1581 .bdrv_needs_filename
= true,
1582 .bdrv_file_open
= qemu_gluster_open
,
1583 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1584 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1585 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1586 .bdrv_close
= qemu_gluster_close
,
1587 .bdrv_co_create
= qemu_gluster_co_create
,
1588 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1589 .bdrv_getlength
= qemu_gluster_getlength
,
1590 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1591 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1592 .bdrv_co_readv
= qemu_gluster_co_readv
,
1593 .bdrv_co_writev
= qemu_gluster_co_writev
,
1594 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1595 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1596 #ifdef CONFIG_GLUSTERFS_DISCARD
1597 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1599 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1600 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1602 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1603 .create_opts
= &qemu_gluster_create_opts
,
1604 .strong_runtime_opts
= gluster_strong_open_opts
,
1607 /* rdma is deprecated (actually never supported for volfile fetch).
1608 * Let's maintain it for the protocol compatibility, to make sure things
1609 * won't break immediately. For now, gluster+rdma will fall back to gluster+tcp
1610 * protocol with a warning.
1611 * TODO: remove gluster+rdma interface support
1613 static BlockDriver bdrv_gluster_rdma
= {
1614 .format_name
= "gluster",
1615 .protocol_name
= "gluster+rdma",
1616 .instance_size
= sizeof(BDRVGlusterState
),
1617 .bdrv_needs_filename
= true,
1618 .bdrv_file_open
= qemu_gluster_open
,
1619 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1620 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1621 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1622 .bdrv_close
= qemu_gluster_close
,
1623 .bdrv_co_create
= qemu_gluster_co_create
,
1624 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1625 .bdrv_getlength
= qemu_gluster_getlength
,
1626 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1627 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1628 .bdrv_co_readv
= qemu_gluster_co_readv
,
1629 .bdrv_co_writev
= qemu_gluster_co_writev
,
1630 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1631 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1632 #ifdef CONFIG_GLUSTERFS_DISCARD
1633 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1635 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1636 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1638 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1639 .create_opts
= &qemu_gluster_create_opts
,
1640 .strong_runtime_opts
= gluster_strong_open_opts
,
1643 static void bdrv_gluster_init(void)
1645 bdrv_register(&bdrv_gluster_rdma
);
1646 bdrv_register(&bdrv_gluster_unix
);
1647 bdrv_register(&bdrv_gluster_tcp
);
1648 bdrv_register(&bdrv_gluster
);
1651 block_init(bdrv_gluster_init
);