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
,
733 #ifdef CONFIG_GLUSTERFS_IOCB_HAS_STAT
734 struct glfs_stat
*pre
, struct glfs_stat
*post
,
738 GlusterAIOCB
*acb
= (GlusterAIOCB
*)arg
;
740 if (!ret
|| ret
== acb
->size
) {
741 acb
->ret
= 0; /* Success */
742 } else if (ret
< 0) {
743 acb
->ret
= -errno
; /* Read/Write failed */
745 acb
->ret
= -EIO
; /* Partial read/write - fail it */
748 aio_co_schedule(acb
->aio_context
, acb
->coroutine
);
751 static void qemu_gluster_parse_flags(int bdrv_flags
, int *open_flags
)
753 assert(open_flags
!= NULL
);
755 *open_flags
|= O_BINARY
;
757 if (bdrv_flags
& BDRV_O_RDWR
) {
758 *open_flags
|= O_RDWR
;
760 *open_flags
|= O_RDONLY
;
763 if ((bdrv_flags
& BDRV_O_NOCACHE
)) {
764 *open_flags
|= O_DIRECT
;
769 * Do SEEK_DATA/HOLE to detect if it is functional. Older broken versions of
770 * gfapi incorrectly return the current offset when SEEK_DATA/HOLE is used.
771 * - Corrected versions return -1 and set errno to EINVAL.
772 * - Versions that support SEEK_DATA/HOLE correctly, will return -1 and set
773 * errno to ENXIO when SEEK_DATA is called with a position of EOF.
775 static bool qemu_gluster_test_seek(struct glfs_fd
*fd
)
779 #if defined SEEK_HOLE && defined SEEK_DATA
782 eof
= glfs_lseek(fd
, 0, SEEK_END
);
784 /* this should never occur */
788 /* this should always fail with ENXIO if SEEK_DATA is supported */
789 ret
= glfs_lseek(fd
, eof
, SEEK_DATA
);
792 return (ret
< 0) && (errno
== ENXIO
);
795 static int qemu_gluster_open(BlockDriverState
*bs
, QDict
*options
,
796 int bdrv_flags
, Error
**errp
)
798 BDRVGlusterState
*s
= bs
->opaque
;
801 BlockdevOptionsGluster
*gconf
= NULL
;
803 Error
*local_err
= NULL
;
804 const char *filename
, *logfile
;
806 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
807 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
809 error_propagate(errp
, local_err
);
814 filename
= qemu_opt_get(opts
, GLUSTER_OPT_FILENAME
);
816 s
->debug
= qemu_opt_get_number(opts
, GLUSTER_OPT_DEBUG
,
817 GLUSTER_DEBUG_DEFAULT
);
820 } else if (s
->debug
> GLUSTER_DEBUG_MAX
) {
821 s
->debug
= GLUSTER_DEBUG_MAX
;
824 gconf
= g_new0(BlockdevOptionsGluster
, 1);
825 gconf
->debug
= s
->debug
;
826 gconf
->has_debug
= true;
828 logfile
= qemu_opt_get(opts
, GLUSTER_OPT_LOGFILE
);
829 s
->logfile
= g_strdup(logfile
? logfile
: GLUSTER_LOGFILE_DEFAULT
);
831 gconf
->logfile
= g_strdup(s
->logfile
);
832 gconf
->has_logfile
= true;
834 s
->glfs
= qemu_gluster_init(gconf
, filename
, options
, errp
);
840 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
841 /* Without this, if fsync fails for a recoverable reason (for instance,
842 * ENOSPC), gluster will dump its cache, preventing retries. This means
843 * almost certain data loss. Not all gluster versions support the
844 * 'resync-failed-syncs-after-fsync' key value, but there is no way to
845 * discover during runtime if it is supported (this api returns success for
846 * unknown key/value pairs) */
847 ret
= glfs_set_xlator_option(s
->glfs
, "*-write-behind",
848 "resync-failed-syncs-after-fsync",
851 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
857 qemu_gluster_parse_flags(bdrv_flags
, &open_flags
);
859 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
860 ret
= s
->fd
? 0 : -errno
;
862 if (ret
== -EACCES
|| ret
== -EROFS
) {
863 /* Try to degrade to read-only, but if it doesn't work, still use the
864 * normal error message. */
865 if (bdrv_apply_auto_read_only(bs
, NULL
, NULL
) == 0) {
866 open_flags
= (open_flags
& ~O_RDWR
) | O_RDONLY
;
867 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
868 ret
= s
->fd
? 0 : -errno
;
872 s
->supports_seek_data
= qemu_gluster_test_seek(s
->fd
);
876 qapi_free_BlockdevOptionsGluster(gconf
);
885 glfs_clear_preopened(s
->glfs
);
890 static int qemu_gluster_reopen_prepare(BDRVReopenState
*state
,
891 BlockReopenQueue
*queue
, Error
**errp
)
895 BDRVGlusterReopenState
*reop_s
;
896 BlockdevOptionsGluster
*gconf
;
899 assert(state
!= NULL
);
900 assert(state
->bs
!= NULL
);
902 s
= state
->bs
->opaque
;
904 state
->opaque
= g_new0(BDRVGlusterReopenState
, 1);
905 reop_s
= state
->opaque
;
907 qemu_gluster_parse_flags(state
->flags
, &open_flags
);
909 gconf
= g_new0(BlockdevOptionsGluster
, 1);
910 gconf
->debug
= s
->debug
;
911 gconf
->has_debug
= true;
912 gconf
->logfile
= g_strdup(s
->logfile
);
913 gconf
->has_logfile
= true;
914 reop_s
->glfs
= qemu_gluster_init(gconf
, state
->bs
->filename
, NULL
, errp
);
915 if (reop_s
->glfs
== NULL
) {
920 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
921 ret
= glfs_set_xlator_option(reop_s
->glfs
, "*-write-behind",
922 "resync-failed-syncs-after-fsync", "on");
924 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
930 reop_s
->fd
= glfs_open(reop_s
->glfs
, gconf
->path
, open_flags
);
931 if (reop_s
->fd
== NULL
) {
932 /* reops->glfs will be cleaned up in _abort */
938 /* state->opaque will be freed in either the _abort or _commit */
939 qapi_free_BlockdevOptionsGluster(gconf
);
943 static void qemu_gluster_reopen_commit(BDRVReopenState
*state
)
945 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
946 BDRVGlusterState
*s
= state
->bs
->opaque
;
954 glfs_clear_preopened(s
->glfs
);
956 /* use the newly opened image / connection */
958 s
->glfs
= reop_s
->glfs
;
960 g_free(state
->opaque
);
961 state
->opaque
= NULL
;
967 static void qemu_gluster_reopen_abort(BDRVReopenState
*state
)
969 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
971 if (reop_s
== NULL
) {
976 glfs_close(reop_s
->fd
);
979 glfs_clear_preopened(reop_s
->glfs
);
981 g_free(state
->opaque
);
982 state
->opaque
= NULL
;
987 #ifdef CONFIG_GLUSTERFS_ZEROFILL
988 static coroutine_fn
int qemu_gluster_co_pwrite_zeroes(BlockDriverState
*bs
,
991 BdrvRequestFlags flags
)
995 BDRVGlusterState
*s
= bs
->opaque
;
999 acb
.coroutine
= qemu_coroutine_self();
1000 acb
.aio_context
= bdrv_get_aio_context(bs
);
1002 ret
= glfs_zerofill_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1007 qemu_coroutine_yield();
1012 static int qemu_gluster_do_truncate(struct glfs_fd
*fd
, int64_t offset
,
1013 PreallocMode prealloc
, Error
**errp
)
1015 int64_t current_length
;
1017 current_length
= glfs_lseek(fd
, 0, SEEK_END
);
1018 if (current_length
< 0) {
1019 error_setg_errno(errp
, errno
, "Failed to determine current size");
1023 if (current_length
> offset
&& prealloc
!= PREALLOC_MODE_OFF
) {
1024 error_setg(errp
, "Cannot use preallocation for shrinking files");
1028 if (current_length
== offset
) {
1033 #ifdef CONFIG_GLUSTERFS_FALLOCATE
1034 case PREALLOC_MODE_FALLOC
:
1035 if (glfs_fallocate(fd
, 0, current_length
, offset
- current_length
)) {
1036 error_setg_errno(errp
, errno
, "Could not preallocate data");
1040 #endif /* CONFIG_GLUSTERFS_FALLOCATE */
1041 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1042 case PREALLOC_MODE_FULL
:
1043 if (glfs_ftruncate(fd
, offset
)) {
1044 error_setg_errno(errp
, errno
, "Could not resize file");
1047 if (glfs_zerofill(fd
, current_length
, offset
- current_length
)) {
1048 error_setg_errno(errp
, errno
, "Could not zerofill the new area");
1052 #endif /* CONFIG_GLUSTERFS_ZEROFILL */
1053 case PREALLOC_MODE_OFF
:
1054 if (glfs_ftruncate(fd
, offset
)) {
1055 error_setg_errno(errp
, errno
, "Could not resize file");
1060 error_setg(errp
, "Unsupported preallocation mode: %s",
1061 PreallocMode_str(prealloc
));
1068 static int qemu_gluster_co_create(BlockdevCreateOptions
*options
,
1071 BlockdevCreateOptionsGluster
*opts
= &options
->u
.gluster
;
1073 struct glfs_fd
*fd
= NULL
;
1076 assert(options
->driver
== BLOCKDEV_DRIVER_GLUSTER
);
1078 glfs
= qemu_gluster_glfs_init(opts
->location
, errp
);
1084 fd
= glfs_creat(glfs
, opts
->location
->path
,
1085 O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, S_IRUSR
| S_IWUSR
);
1091 ret
= qemu_gluster_do_truncate(fd
, opts
->size
, opts
->preallocation
, errp
);
1095 if (glfs_close(fd
) != 0 && ret
== 0) {
1099 glfs_clear_preopened(glfs
);
1103 static int coroutine_fn
qemu_gluster_co_create_opts(const char *filename
,
1107 BlockdevCreateOptions
*options
;
1108 BlockdevCreateOptionsGluster
*gopts
;
1109 BlockdevOptionsGluster
*gconf
;
1111 Error
*local_err
= NULL
;
1114 options
= g_new0(BlockdevCreateOptions
, 1);
1115 options
->driver
= BLOCKDEV_DRIVER_GLUSTER
;
1116 gopts
= &options
->u
.gluster
;
1118 gconf
= g_new0(BlockdevOptionsGluster
, 1);
1119 gopts
->location
= gconf
;
1121 gopts
->size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
1124 tmp
= qemu_opt_get_del(opts
, BLOCK_OPT_PREALLOC
);
1125 gopts
->preallocation
= qapi_enum_parse(&PreallocMode_lookup
, tmp
,
1126 PREALLOC_MODE_OFF
, &local_err
);
1129 error_propagate(errp
, local_err
);
1134 gconf
->debug
= qemu_opt_get_number_del(opts
, GLUSTER_OPT_DEBUG
,
1135 GLUSTER_DEBUG_DEFAULT
);
1136 if (gconf
->debug
< 0) {
1138 } else if (gconf
->debug
> GLUSTER_DEBUG_MAX
) {
1139 gconf
->debug
= GLUSTER_DEBUG_MAX
;
1141 gconf
->has_debug
= true;
1143 gconf
->logfile
= qemu_opt_get_del(opts
, GLUSTER_OPT_LOGFILE
);
1144 if (!gconf
->logfile
) {
1145 gconf
->logfile
= g_strdup(GLUSTER_LOGFILE_DEFAULT
);
1147 gconf
->has_logfile
= true;
1149 ret
= qemu_gluster_parse(gconf
, filename
, NULL
, errp
);
1154 ret
= qemu_gluster_co_create(options
, errp
);
1161 qapi_free_BlockdevCreateOptions(options
);
1165 static coroutine_fn
int qemu_gluster_co_rw(BlockDriverState
*bs
,
1166 int64_t sector_num
, int nb_sectors
,
1167 QEMUIOVector
*qiov
, int write
)
1171 BDRVGlusterState
*s
= bs
->opaque
;
1172 size_t size
= nb_sectors
* BDRV_SECTOR_SIZE
;
1173 off_t offset
= sector_num
* BDRV_SECTOR_SIZE
;
1177 acb
.coroutine
= qemu_coroutine_self();
1178 acb
.aio_context
= bdrv_get_aio_context(bs
);
1181 ret
= glfs_pwritev_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1182 gluster_finish_aiocb
, &acb
);
1184 ret
= glfs_preadv_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1185 gluster_finish_aiocb
, &acb
);
1192 qemu_coroutine_yield();
1196 static coroutine_fn
int qemu_gluster_co_truncate(BlockDriverState
*bs
,
1198 PreallocMode prealloc
,
1201 BDRVGlusterState
*s
= bs
->opaque
;
1202 return qemu_gluster_do_truncate(s
->fd
, offset
, prealloc
, errp
);
1205 static coroutine_fn
int qemu_gluster_co_readv(BlockDriverState
*bs
,
1210 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 0);
1213 static coroutine_fn
int qemu_gluster_co_writev(BlockDriverState
*bs
,
1220 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 1);
1223 static void qemu_gluster_close(BlockDriverState
*bs
)
1225 BDRVGlusterState
*s
= bs
->opaque
;
1232 glfs_clear_preopened(s
->glfs
);
1235 static coroutine_fn
int qemu_gluster_co_flush_to_disk(BlockDriverState
*bs
)
1239 BDRVGlusterState
*s
= bs
->opaque
;
1243 acb
.coroutine
= qemu_coroutine_self();
1244 acb
.aio_context
= bdrv_get_aio_context(bs
);
1246 ret
= glfs_fsync_async(s
->fd
, gluster_finish_aiocb
, &acb
);
1252 qemu_coroutine_yield();
1261 /* Some versions of Gluster (3.5.6 -> 3.5.8?) will not retain its cache
1262 * after a fsync failure, so we have no way of allowing the guest to safely
1263 * continue. Gluster versions prior to 3.5.6 don't retain the cache
1264 * either, but will invalidate the fd on error, so this is again our only
1267 * The 'resync-failed-syncs-after-fsync' xlator option for the
1268 * write-behind cache will cause later gluster versions to retain its
1269 * cache after error, so long as the fd remains open. However, we
1270 * currently have no way of knowing if this option is supported.
1272 * TODO: Once gluster provides a way for us to determine if the option
1273 * is supported, bypass the closure and setting drv to NULL. */
1274 qemu_gluster_close(bs
);
1279 #ifdef CONFIG_GLUSTERFS_DISCARD
1280 static coroutine_fn
int qemu_gluster_co_pdiscard(BlockDriverState
*bs
,
1281 int64_t offset
, int size
)
1285 BDRVGlusterState
*s
= bs
->opaque
;
1289 acb
.coroutine
= qemu_coroutine_self();
1290 acb
.aio_context
= bdrv_get_aio_context(bs
);
1292 ret
= glfs_discard_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1297 qemu_coroutine_yield();
1302 static int64_t qemu_gluster_getlength(BlockDriverState
*bs
)
1304 BDRVGlusterState
*s
= bs
->opaque
;
1307 ret
= glfs_lseek(s
->fd
, 0, SEEK_END
);
1315 static int64_t qemu_gluster_allocated_file_size(BlockDriverState
*bs
)
1317 BDRVGlusterState
*s
= bs
->opaque
;
1321 ret
= glfs_fstat(s
->fd
, &st
);
1325 return st
.st_blocks
* 512;
1329 static int qemu_gluster_has_zero_init(BlockDriverState
*bs
)
1331 /* GlusterFS volume could be backed by a block device */
1336 * Find allocation range in @bs around offset @start.
1337 * May change underlying file descriptor's file offset.
1338 * If @start is not in a hole, store @start in @data, and the
1339 * beginning of the next hole in @hole, and return 0.
1340 * If @start is in a non-trailing hole, store @start in @hole and the
1341 * beginning of the next non-hole in @data, and return 0.
1342 * If @start is in a trailing hole or beyond EOF, return -ENXIO.
1343 * If we can't find out, return a negative errno other than -ENXIO.
1345 * (Shamefully copied from file-posix.c, only minuscule adaptions.)
1347 static int find_allocation(BlockDriverState
*bs
, off_t start
,
1348 off_t
*data
, off_t
*hole
)
1350 BDRVGlusterState
*s
= bs
->opaque
;
1352 if (!s
->supports_seek_data
) {
1356 #if defined SEEK_HOLE && defined SEEK_DATA
1361 * D1. offs == start: start is in data
1362 * D2. offs > start: start is in a hole, next data at offs
1363 * D3. offs < 0, errno = ENXIO: either start is in a trailing hole
1364 * or start is beyond EOF
1365 * If the latter happens, the file has been truncated behind
1366 * our back since we opened it. All bets are off then.
1367 * Treating like a trailing hole is simplest.
1368 * D4. offs < 0, errno != ENXIO: we learned nothing
1370 offs
= glfs_lseek(s
->fd
, start
, SEEK_DATA
);
1372 return -errno
; /* D3 or D4 */
1376 /* This is not a valid return by lseek(). We are safe to just return
1377 * -EIO in this case, and we'll treat it like D4. Unfortunately some
1378 * versions of gluster server will return offs < start, so an assert
1379 * here will unnecessarily abort QEMU. */
1384 /* D2: in hole, next data at offs */
1390 /* D1: in data, end not yet known */
1394 * H1. offs == start: start is in a hole
1395 * If this happens here, a hole has been dug behind our back
1396 * since the previous lseek().
1397 * H2. offs > start: either start is in data, next hole at offs,
1398 * or start is in trailing hole, EOF at offs
1399 * Linux treats trailing holes like any other hole: offs ==
1400 * start. Solaris seeks to EOF instead: offs > start (blech).
1401 * If that happens here, a hole has been dug behind our back
1402 * since the previous lseek().
1403 * H3. offs < 0, errno = ENXIO: start is beyond EOF
1404 * If this happens, the file has been truncated behind our
1405 * back since we opened it. Treat it like a trailing hole.
1406 * H4. offs < 0, errno != ENXIO: we learned nothing
1407 * Pretend we know nothing at all, i.e. "forget" about D1.
1409 offs
= glfs_lseek(s
->fd
, start
, SEEK_HOLE
);
1411 return -errno
; /* D1 and (H3 or H4) */
1415 /* This is not a valid return by lseek(). We are safe to just return
1416 * -EIO in this case, and we'll treat it like H4. Unfortunately some
1417 * versions of gluster server will return offs < start, so an assert
1418 * here will unnecessarily abort QEMU. */
1424 * D1 and H2: either in data, next hole at offs, or it was in
1425 * data but is now in a trailing hole. In the latter case,
1426 * all bets are off. Treating it as if it there was data all
1427 * the way to EOF is safe, so simply do that.
1443 * Returns the allocation status of the specified offset.
1445 * The block layer guarantees 'offset' and 'bytes' are within bounds.
1447 * 'pnum' is set to the number of bytes (including and immediately following
1448 * the specified offset) that are known to be in the same
1449 * allocated/unallocated state.
1451 * 'bytes' is the max value 'pnum' should be set to.
1453 * (Based on raw_co_block_status() from file-posix.c.)
1455 static int coroutine_fn
qemu_gluster_co_block_status(BlockDriverState
*bs
,
1461 BlockDriverState
**file
)
1463 BDRVGlusterState
*s
= bs
->opaque
;
1464 off_t data
= 0, hole
= 0;
1475 return BDRV_BLOCK_DATA
| BDRV_BLOCK_OFFSET_VALID
;
1478 ret
= find_allocation(bs
, offset
, &data
, &hole
);
1479 if (ret
== -ENXIO
) {
1482 ret
= BDRV_BLOCK_ZERO
;
1483 } else if (ret
< 0) {
1484 /* No info available, so pretend there are no holes */
1486 ret
= BDRV_BLOCK_DATA
;
1487 } else if (data
== offset
) {
1488 /* On a data extent, compute bytes to the end of the extent,
1489 * possibly including a partial sector at EOF. */
1490 *pnum
= MIN(bytes
, hole
- offset
);
1491 ret
= BDRV_BLOCK_DATA
;
1493 /* On a hole, compute bytes to the beginning of the next extent. */
1494 assert(hole
== offset
);
1495 *pnum
= MIN(bytes
, data
- offset
);
1496 ret
= BDRV_BLOCK_ZERO
;
1502 return ret
| BDRV_BLOCK_OFFSET_VALID
;
1506 static const char *const gluster_strong_open_opts
[] = {
1510 GLUSTER_OPT_SERVER_PATTERN
,
1521 static BlockDriver bdrv_gluster
= {
1522 .format_name
= "gluster",
1523 .protocol_name
= "gluster",
1524 .instance_size
= sizeof(BDRVGlusterState
),
1525 .bdrv_needs_filename
= false,
1526 .bdrv_file_open
= qemu_gluster_open
,
1527 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1528 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1529 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1530 .bdrv_close
= qemu_gluster_close
,
1531 .bdrv_co_create
= qemu_gluster_co_create
,
1532 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1533 .bdrv_getlength
= qemu_gluster_getlength
,
1534 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1535 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1536 .bdrv_co_readv
= qemu_gluster_co_readv
,
1537 .bdrv_co_writev
= qemu_gluster_co_writev
,
1538 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1539 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1540 #ifdef CONFIG_GLUSTERFS_DISCARD
1541 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1543 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1544 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1546 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1547 .create_opts
= &qemu_gluster_create_opts
,
1548 .strong_runtime_opts
= gluster_strong_open_opts
,
1551 static BlockDriver bdrv_gluster_tcp
= {
1552 .format_name
= "gluster",
1553 .protocol_name
= "gluster+tcp",
1554 .instance_size
= sizeof(BDRVGlusterState
),
1555 .bdrv_needs_filename
= false,
1556 .bdrv_file_open
= qemu_gluster_open
,
1557 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1558 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1559 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1560 .bdrv_close
= qemu_gluster_close
,
1561 .bdrv_co_create
= qemu_gluster_co_create
,
1562 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1563 .bdrv_getlength
= qemu_gluster_getlength
,
1564 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1565 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1566 .bdrv_co_readv
= qemu_gluster_co_readv
,
1567 .bdrv_co_writev
= qemu_gluster_co_writev
,
1568 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1569 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1570 #ifdef CONFIG_GLUSTERFS_DISCARD
1571 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1573 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1574 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1576 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1577 .create_opts
= &qemu_gluster_create_opts
,
1578 .strong_runtime_opts
= gluster_strong_open_opts
,
1581 static BlockDriver bdrv_gluster_unix
= {
1582 .format_name
= "gluster",
1583 .protocol_name
= "gluster+unix",
1584 .instance_size
= sizeof(BDRVGlusterState
),
1585 .bdrv_needs_filename
= true,
1586 .bdrv_file_open
= qemu_gluster_open
,
1587 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1588 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1589 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1590 .bdrv_close
= qemu_gluster_close
,
1591 .bdrv_co_create
= qemu_gluster_co_create
,
1592 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1593 .bdrv_getlength
= qemu_gluster_getlength
,
1594 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1595 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1596 .bdrv_co_readv
= qemu_gluster_co_readv
,
1597 .bdrv_co_writev
= qemu_gluster_co_writev
,
1598 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1599 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1600 #ifdef CONFIG_GLUSTERFS_DISCARD
1601 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1603 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1604 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1606 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1607 .create_opts
= &qemu_gluster_create_opts
,
1608 .strong_runtime_opts
= gluster_strong_open_opts
,
1611 /* rdma is deprecated (actually never supported for volfile fetch).
1612 * Let's maintain it for the protocol compatibility, to make sure things
1613 * won't break immediately. For now, gluster+rdma will fall back to gluster+tcp
1614 * protocol with a warning.
1615 * TODO: remove gluster+rdma interface support
1617 static BlockDriver bdrv_gluster_rdma
= {
1618 .format_name
= "gluster",
1619 .protocol_name
= "gluster+rdma",
1620 .instance_size
= sizeof(BDRVGlusterState
),
1621 .bdrv_needs_filename
= true,
1622 .bdrv_file_open
= qemu_gluster_open
,
1623 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1624 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1625 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1626 .bdrv_close
= qemu_gluster_close
,
1627 .bdrv_co_create
= qemu_gluster_co_create
,
1628 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1629 .bdrv_getlength
= qemu_gluster_getlength
,
1630 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1631 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1632 .bdrv_co_readv
= qemu_gluster_co_readv
,
1633 .bdrv_co_writev
= qemu_gluster_co_writev
,
1634 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1635 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1636 #ifdef CONFIG_GLUSTERFS_DISCARD
1637 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1639 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1640 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1642 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1643 .create_opts
= &qemu_gluster_create_opts
,
1644 .strong_runtime_opts
= gluster_strong_open_opts
,
1647 static void bdrv_gluster_init(void)
1649 bdrv_register(&bdrv_gluster_rdma
);
1650 bdrv_register(&bdrv_gluster_unix
);
1651 bdrv_register(&bdrv_gluster_tcp
);
1652 bdrv_register(&bdrv_gluster
);
1655 block_init(bdrv_gluster_init
);