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, full)"
104 .name
= GLUSTER_OPT_DEBUG
,
105 .type
= QEMU_OPT_NUMBER
,
106 .help
= "Gluster log level, valid range is 0-9",
109 .name
= GLUSTER_OPT_LOGFILE
,
110 .type
= QEMU_OPT_STRING
,
111 .help
= "Logfile path of libgfapi",
113 { /* end of list */ }
117 static QemuOptsList runtime_opts
= {
119 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
122 .name
= GLUSTER_OPT_FILENAME
,
123 .type
= QEMU_OPT_STRING
,
124 .help
= "URL to the gluster image",
127 .name
= GLUSTER_OPT_DEBUG
,
128 .type
= QEMU_OPT_NUMBER
,
129 .help
= "Gluster log level, valid range is 0-9",
132 .name
= GLUSTER_OPT_LOGFILE
,
133 .type
= QEMU_OPT_STRING
,
134 .help
= "Logfile path of libgfapi",
136 { /* end of list */ }
140 static QemuOptsList runtime_json_opts
= {
141 .name
= "gluster_json",
142 .head
= QTAILQ_HEAD_INITIALIZER(runtime_json_opts
.head
),
145 .name
= GLUSTER_OPT_VOLUME
,
146 .type
= QEMU_OPT_STRING
,
147 .help
= "name of gluster volume where VM image resides",
150 .name
= GLUSTER_OPT_PATH
,
151 .type
= QEMU_OPT_STRING
,
152 .help
= "absolute path to image file in gluster volume",
155 .name
= GLUSTER_OPT_DEBUG
,
156 .type
= QEMU_OPT_NUMBER
,
157 .help
= "Gluster log level, valid range is 0-9",
159 { /* end of list */ }
163 static QemuOptsList runtime_type_opts
= {
164 .name
= "gluster_type",
165 .head
= QTAILQ_HEAD_INITIALIZER(runtime_type_opts
.head
),
168 .name
= GLUSTER_OPT_TYPE
,
169 .type
= QEMU_OPT_STRING
,
172 { /* end of list */ }
176 static QemuOptsList runtime_unix_opts
= {
177 .name
= "gluster_unix",
178 .head
= QTAILQ_HEAD_INITIALIZER(runtime_unix_opts
.head
),
181 .name
= GLUSTER_OPT_SOCKET
,
182 .type
= QEMU_OPT_STRING
,
183 .help
= "socket file path (legacy)",
186 .name
= GLUSTER_OPT_PATH
,
187 .type
= QEMU_OPT_STRING
,
188 .help
= "socket file path (QAPI)",
190 { /* end of list */ }
194 static QemuOptsList runtime_inet_opts
= {
195 .name
= "gluster_inet",
196 .head
= QTAILQ_HEAD_INITIALIZER(runtime_inet_opts
.head
),
199 .name
= GLUSTER_OPT_TYPE
,
200 .type
= QEMU_OPT_STRING
,
204 .name
= GLUSTER_OPT_HOST
,
205 .type
= QEMU_OPT_STRING
,
206 .help
= "host address (hostname/ipv4/ipv6 addresses)",
209 .name
= GLUSTER_OPT_PORT
,
210 .type
= QEMU_OPT_STRING
,
211 .help
= "port number on which glusterd is listening (default 24007)",
215 .type
= QEMU_OPT_NUMBER
,
216 .help
= "max port number, not supported by gluster",
220 .type
= QEMU_OPT_BOOL
,
221 .help
= "ipv4 bool value, not supported by gluster",
225 .type
= QEMU_OPT_BOOL
,
226 .help
= "ipv6 bool value, not supported by gluster",
228 { /* end of list */ }
232 static void glfs_set_preopened(const char *volume
, glfs_t
*fs
)
234 ListElement
*entry
= NULL
;
236 entry
= g_new(ListElement
, 1);
238 entry
->saved
.volume
= g_strdup(volume
);
240 entry
->saved
.fs
= fs
;
241 entry
->saved
.ref
= 1;
243 QLIST_INSERT_HEAD(&glfs_list
, entry
, list
);
246 static glfs_t
*glfs_find_preopened(const char *volume
)
248 ListElement
*entry
= NULL
;
250 QLIST_FOREACH(entry
, &glfs_list
, list
) {
251 if (strcmp(entry
->saved
.volume
, volume
) == 0) {
253 return entry
->saved
.fs
;
260 static void glfs_clear_preopened(glfs_t
*fs
)
262 ListElement
*entry
= NULL
;
269 QLIST_FOREACH_SAFE(entry
, &glfs_list
, list
, next
) {
270 if (entry
->saved
.fs
== fs
) {
271 if (--entry
->saved
.ref
) {
275 QLIST_REMOVE(entry
, list
);
277 glfs_fini(entry
->saved
.fs
);
278 g_free(entry
->saved
.volume
);
284 static int parse_volume_options(BlockdevOptionsGluster
*gconf
, char *path
)
293 p
= q
= path
+ strspn(path
, "/");
294 p
+= strcspn(p
, "/");
298 gconf
->volume
= g_strndup(q
, p
- q
);
305 gconf
->path
= g_strdup(p
);
310 * file=gluster[+transport]://[host[:port]]/volume/path[?socket=...]
312 * 'gluster' is the protocol.
314 * 'transport' specifies the transport type used to connect to gluster
315 * management daemon (glusterd). Valid transport types are
316 * tcp or unix. If a transport type isn't specified, then tcp type is assumed.
318 * 'host' specifies the host where the volume file specification for
319 * the given volume resides. This can be either hostname or ipv4 address.
320 * If transport type is 'unix', then 'host' field should not be specified.
321 * The 'socket' field needs to be populated with the path to unix domain
324 * 'port' is the port number on which glusterd is listening. This is optional
325 * and if not specified, QEMU will send 0 which will make gluster to use the
326 * default port. If the transport type is unix, then 'port' should not be
329 * 'volume' is the name of the gluster volume which contains the VM image.
331 * 'path' is the path to the actual VM image that resides on gluster volume.
335 * file=gluster://1.2.3.4/testvol/a.img
336 * file=gluster+tcp://1.2.3.4/testvol/a.img
337 * file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
338 * file=gluster+tcp://host.domain.com:24007/testvol/dir/a.img
339 * file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
341 static int qemu_gluster_parse_uri(BlockdevOptionsGluster
*gconf
,
342 const char *filename
)
344 SocketAddress
*gsconf
;
346 QueryParams
*qp
= NULL
;
347 bool is_unix
= false;
350 uri
= uri_parse(filename
);
355 gconf
->server
= g_new0(SocketAddressList
, 1);
356 gconf
->server
->value
= gsconf
= g_new0(SocketAddress
, 1);
359 if (!uri
->scheme
|| !strcmp(uri
->scheme
, "gluster")) {
360 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
361 } else if (!strcmp(uri
->scheme
, "gluster+tcp")) {
362 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
363 } else if (!strcmp(uri
->scheme
, "gluster+unix")) {
364 gsconf
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
366 } else if (!strcmp(uri
->scheme
, "gluster+rdma")) {
367 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
368 warn_report("rdma feature is not supported, falling back to tcp");
374 ret
= parse_volume_options(gconf
, uri
->path
);
379 qp
= query_params_parse(uri
->query
);
380 if (qp
->n
> 1 || (is_unix
&& !qp
->n
) || (!is_unix
&& qp
->n
)) {
386 if (uri
->server
|| uri
->port
) {
390 if (strcmp(qp
->p
[0].name
, "socket")) {
394 gsconf
->u
.q_unix
.path
= g_strdup(qp
->p
[0].value
);
396 gsconf
->u
.inet
.host
= g_strdup(uri
->server
? uri
->server
: "localhost");
398 gsconf
->u
.inet
.port
= g_strdup_printf("%d", uri
->port
);
400 gsconf
->u
.inet
.port
= g_strdup_printf("%d", GLUSTER_DEFAULT_PORT
);
406 query_params_free(qp
);
412 static struct glfs
*qemu_gluster_glfs_init(BlockdevOptionsGluster
*gconf
,
418 SocketAddressList
*server
;
419 unsigned long long port
;
421 glfs
= glfs_find_preopened(gconf
->volume
);
426 glfs
= glfs_new(gconf
->volume
);
431 glfs_set_preopened(gconf
->volume
, glfs
);
433 for (server
= gconf
->server
; server
; server
= server
->next
) {
434 switch (server
->value
->type
) {
435 case SOCKET_ADDRESS_TYPE_UNIX
:
436 ret
= glfs_set_volfile_server(glfs
, "unix",
437 server
->value
->u
.q_unix
.path
, 0);
439 case SOCKET_ADDRESS_TYPE_INET
:
440 if (parse_uint_full(server
->value
->u
.inet
.port
, &port
, 10) < 0 ||
442 error_setg(errp
, "'%s' is not a valid port number",
443 server
->value
->u
.inet
.port
);
447 ret
= glfs_set_volfile_server(glfs
, "tcp",
448 server
->value
->u
.inet
.host
,
451 case SOCKET_ADDRESS_TYPE_VSOCK
:
452 case SOCKET_ADDRESS_TYPE_FD
:
462 ret
= glfs_set_logging(glfs
, gconf
->logfile
, gconf
->debug
);
467 ret
= glfs_init(glfs
);
469 error_setg(errp
, "Gluster connection for volume %s, path %s failed"
470 " to connect", gconf
->volume
, gconf
->path
);
471 for (server
= gconf
->server
; server
; server
= server
->next
) {
472 if (server
->value
->type
== SOCKET_ADDRESS_TYPE_UNIX
) {
473 error_append_hint(errp
, "hint: failed on socket %s ",
474 server
->value
->u
.q_unix
.path
);
476 error_append_hint(errp
, "hint: failed on host %s and port %s ",
477 server
->value
->u
.inet
.host
,
478 server
->value
->u
.inet
.port
);
482 error_append_hint(errp
, "Please refer to gluster logs for more info\n");
484 /* glfs_init sometimes doesn't set errno although docs suggest that */
496 glfs_clear_preopened(glfs
);
503 * Convert the json formatted command line into qapi.
505 static int qemu_gluster_parse_json(BlockdevOptionsGluster
*gconf
,
506 QDict
*options
, Error
**errp
)
509 SocketAddress
*gsconf
= NULL
;
510 SocketAddressList
*curr
= NULL
;
511 QDict
*backing_options
= NULL
;
512 Error
*local_err
= NULL
;
515 int i
, type
, num_servers
;
517 /* create opts info from runtime_json_opts list */
518 opts
= qemu_opts_create(&runtime_json_opts
, NULL
, 0, &error_abort
);
519 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
524 num_servers
= qdict_array_entries(options
, GLUSTER_OPT_SERVER_PATTERN
);
525 if (num_servers
< 1) {
526 error_setg(&local_err
, QERR_MISSING_PARAMETER
, "server");
530 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_VOLUME
);
532 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_VOLUME
);
535 gconf
->volume
= g_strdup(ptr
);
537 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
539 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_PATH
);
542 gconf
->path
= g_strdup(ptr
);
545 for (i
= 0; i
< num_servers
; i
++) {
546 str
= g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN
"%d.", i
);
547 qdict_extract_subqdict(options
, &backing_options
, str
);
549 /* create opts info from runtime_type_opts list */
550 opts
= qemu_opts_create(&runtime_type_opts
, NULL
, 0, &error_abort
);
551 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
556 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TYPE
);
558 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_TYPE
);
559 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
563 gsconf
= g_new0(SocketAddress
, 1);
564 if (!strcmp(ptr
, "tcp")) {
565 ptr
= "inet"; /* accept legacy "tcp" */
567 type
= qapi_enum_parse(&SocketAddressType_lookup
, ptr
, -1, NULL
);
568 if (type
!= SOCKET_ADDRESS_TYPE_INET
569 && type
!= SOCKET_ADDRESS_TYPE_UNIX
) {
570 error_setg(&local_err
,
571 "Parameter '%s' may be 'inet' or 'unix'",
573 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
579 if (gsconf
->type
== SOCKET_ADDRESS_TYPE_INET
) {
580 /* create opts info from runtime_inet_opts list */
581 opts
= qemu_opts_create(&runtime_inet_opts
, NULL
, 0, &error_abort
);
582 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
587 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_HOST
);
589 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
591 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
594 gsconf
->u
.inet
.host
= g_strdup(ptr
);
595 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PORT
);
597 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
599 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
602 gsconf
->u
.inet
.port
= g_strdup(ptr
);
604 /* defend for unsupported fields in InetSocketAddress,
605 * i.e. @ipv4, @ipv6 and @to
607 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TO
);
609 gsconf
->u
.inet
.has_to
= true;
611 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV4
);
613 gsconf
->u
.inet
.has_ipv4
= true;
615 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV6
);
617 gsconf
->u
.inet
.has_ipv6
= true;
619 if (gsconf
->u
.inet
.has_to
) {
620 error_setg(&local_err
, "Parameter 'to' not supported");
623 if (gsconf
->u
.inet
.has_ipv4
|| gsconf
->u
.inet
.has_ipv6
) {
624 error_setg(&local_err
, "Parameters 'ipv4/ipv6' not supported");
629 /* create opts info from runtime_unix_opts list */
630 opts
= qemu_opts_create(&runtime_unix_opts
, NULL
, 0, &error_abort
);
631 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
636 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
638 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
);
639 } else if (qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
)) {
640 error_setg(&local_err
,
641 "Conflicting parameters 'path' and 'socket'");
642 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
646 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
648 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
651 gsconf
->u
.q_unix
.path
= g_strdup(ptr
);
655 if (gconf
->server
== NULL
) {
656 gconf
->server
= g_new0(SocketAddressList
, 1);
657 gconf
->server
->value
= gsconf
;
658 curr
= gconf
->server
;
660 curr
->next
= g_new0(SocketAddressList
, 1);
661 curr
->next
->value
= gsconf
;
666 qobject_unref(backing_options
);
667 backing_options
= NULL
;
675 error_propagate(errp
, local_err
);
676 qapi_free_SocketAddress(gsconf
);
679 qobject_unref(backing_options
);
684 /* Converts options given in @filename and the @options QDict into the QAPI
686 static int qemu_gluster_parse(BlockdevOptionsGluster
*gconf
,
687 const char *filename
,
688 QDict
*options
, Error
**errp
)
692 ret
= qemu_gluster_parse_uri(gconf
, filename
);
694 error_setg(errp
, "invalid URI %s", filename
);
695 error_append_hint(errp
, "Usage: file=gluster[+transport]://"
696 "[host[:port]]volume/path[?socket=...]"
698 "[,file.logfile=/path/filename.log]\n");
702 ret
= qemu_gluster_parse_json(gconf
, options
, errp
);
704 error_append_hint(errp
, "Usage: "
705 "-drive driver=qcow2,file.driver=gluster,"
706 "file.volume=testvol,file.path=/path/a.qcow2"
708 "[,file.logfile=/path/filename.log],"
709 "file.server.0.type=inet,"
710 "file.server.0.host=1.2.3.4,"
711 "file.server.0.port=24007,"
712 "file.server.1.transport=unix,"
713 "file.server.1.path=/var/run/glusterd.socket ..."
722 static struct glfs
*qemu_gluster_init(BlockdevOptionsGluster
*gconf
,
723 const char *filename
,
724 QDict
*options
, Error
**errp
)
728 ret
= qemu_gluster_parse(gconf
, filename
, options
, errp
);
734 return qemu_gluster_glfs_init(gconf
, errp
);
738 * AIO callback routine called from GlusterFS thread.
740 static void gluster_finish_aiocb(struct glfs_fd
*fd
, ssize_t ret
,
741 #ifdef CONFIG_GLUSTERFS_IOCB_HAS_STAT
742 struct glfs_stat
*pre
, struct glfs_stat
*post
,
746 GlusterAIOCB
*acb
= (GlusterAIOCB
*)arg
;
748 if (!ret
|| ret
== acb
->size
) {
749 acb
->ret
= 0; /* Success */
750 } else if (ret
< 0) {
751 acb
->ret
= -errno
; /* Read/Write failed */
753 acb
->ret
= -EIO
; /* Partial read/write - fail it */
756 aio_co_schedule(acb
->aio_context
, acb
->coroutine
);
759 static void qemu_gluster_parse_flags(int bdrv_flags
, int *open_flags
)
761 assert(open_flags
!= NULL
);
763 *open_flags
|= O_BINARY
;
765 if (bdrv_flags
& BDRV_O_RDWR
) {
766 *open_flags
|= O_RDWR
;
768 *open_flags
|= O_RDONLY
;
771 if ((bdrv_flags
& BDRV_O_NOCACHE
)) {
772 *open_flags
|= O_DIRECT
;
777 * Do SEEK_DATA/HOLE to detect if it is functional. Older broken versions of
778 * gfapi incorrectly return the current offset when SEEK_DATA/HOLE is used.
779 * - Corrected versions return -1 and set errno to EINVAL.
780 * - Versions that support SEEK_DATA/HOLE correctly, will return -1 and set
781 * errno to ENXIO when SEEK_DATA is called with a position of EOF.
783 static bool qemu_gluster_test_seek(struct glfs_fd
*fd
)
787 #if defined SEEK_HOLE && defined SEEK_DATA
790 eof
= glfs_lseek(fd
, 0, SEEK_END
);
792 /* this should never occur */
796 /* this should always fail with ENXIO if SEEK_DATA is supported */
797 ret
= glfs_lseek(fd
, eof
, SEEK_DATA
);
800 return (ret
< 0) && (errno
== ENXIO
);
803 static int qemu_gluster_open(BlockDriverState
*bs
, QDict
*options
,
804 int bdrv_flags
, Error
**errp
)
806 BDRVGlusterState
*s
= bs
->opaque
;
809 BlockdevOptionsGluster
*gconf
= NULL
;
811 Error
*local_err
= NULL
;
812 const char *filename
, *logfile
;
814 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
815 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
817 error_propagate(errp
, local_err
);
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;
927 reop_s
->glfs
= qemu_gluster_init(gconf
, state
->bs
->filename
, NULL
, errp
);
928 if (reop_s
->glfs
== NULL
) {
933 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
934 ret
= glfs_set_xlator_option(reop_s
->glfs
, "*-write-behind",
935 "resync-failed-syncs-after-fsync", "on");
937 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
943 reop_s
->fd
= glfs_open(reop_s
->glfs
, gconf
->path
, open_flags
);
944 if (reop_s
->fd
== NULL
) {
945 /* reops->glfs will be cleaned up in _abort */
951 /* state->opaque will be freed in either the _abort or _commit */
952 qapi_free_BlockdevOptionsGluster(gconf
);
956 static void qemu_gluster_reopen_commit(BDRVReopenState
*state
)
958 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
959 BDRVGlusterState
*s
= state
->bs
->opaque
;
967 glfs_clear_preopened(s
->glfs
);
969 /* use the newly opened image / connection */
971 s
->glfs
= reop_s
->glfs
;
973 g_free(state
->opaque
);
974 state
->opaque
= NULL
;
980 static void qemu_gluster_reopen_abort(BDRVReopenState
*state
)
982 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
984 if (reop_s
== NULL
) {
989 glfs_close(reop_s
->fd
);
992 glfs_clear_preopened(reop_s
->glfs
);
994 g_free(state
->opaque
);
995 state
->opaque
= NULL
;
1000 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1001 static coroutine_fn
int qemu_gluster_co_pwrite_zeroes(BlockDriverState
*bs
,
1004 BdrvRequestFlags flags
)
1008 BDRVGlusterState
*s
= bs
->opaque
;
1012 acb
.coroutine
= qemu_coroutine_self();
1013 acb
.aio_context
= bdrv_get_aio_context(bs
);
1015 ret
= glfs_zerofill_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1020 qemu_coroutine_yield();
1025 static int qemu_gluster_do_truncate(struct glfs_fd
*fd
, int64_t offset
,
1026 PreallocMode prealloc
, Error
**errp
)
1028 int64_t current_length
;
1030 current_length
= glfs_lseek(fd
, 0, SEEK_END
);
1031 if (current_length
< 0) {
1032 error_setg_errno(errp
, errno
, "Failed to determine current size");
1036 if (current_length
> offset
&& prealloc
!= PREALLOC_MODE_OFF
) {
1037 error_setg(errp
, "Cannot use preallocation for shrinking files");
1041 if (current_length
== offset
) {
1046 #ifdef CONFIG_GLUSTERFS_FALLOCATE
1047 case PREALLOC_MODE_FALLOC
:
1048 if (glfs_fallocate(fd
, 0, current_length
, offset
- current_length
)) {
1049 error_setg_errno(errp
, errno
, "Could not preallocate data");
1053 #endif /* CONFIG_GLUSTERFS_FALLOCATE */
1054 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1055 case PREALLOC_MODE_FULL
:
1056 if (glfs_ftruncate(fd
, offset
)) {
1057 error_setg_errno(errp
, errno
, "Could not resize file");
1060 if (glfs_zerofill(fd
, current_length
, offset
- current_length
)) {
1061 error_setg_errno(errp
, errno
, "Could not zerofill the new area");
1065 #endif /* CONFIG_GLUSTERFS_ZEROFILL */
1066 case PREALLOC_MODE_OFF
:
1067 if (glfs_ftruncate(fd
, offset
)) {
1068 error_setg_errno(errp
, errno
, "Could not resize file");
1073 error_setg(errp
, "Unsupported preallocation mode: %s",
1074 PreallocMode_str(prealloc
));
1081 static int qemu_gluster_co_create(BlockdevCreateOptions
*options
,
1084 BlockdevCreateOptionsGluster
*opts
= &options
->u
.gluster
;
1086 struct glfs_fd
*fd
= NULL
;
1089 assert(options
->driver
== BLOCKDEV_DRIVER_GLUSTER
);
1091 glfs
= qemu_gluster_glfs_init(opts
->location
, errp
);
1097 fd
= glfs_creat(glfs
, opts
->location
->path
,
1098 O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, S_IRUSR
| S_IWUSR
);
1104 ret
= qemu_gluster_do_truncate(fd
, opts
->size
, opts
->preallocation
, errp
);
1108 if (glfs_close(fd
) != 0 && ret
== 0) {
1112 glfs_clear_preopened(glfs
);
1116 static int coroutine_fn
qemu_gluster_co_create_opts(const char *filename
,
1120 BlockdevCreateOptions
*options
;
1121 BlockdevCreateOptionsGluster
*gopts
;
1122 BlockdevOptionsGluster
*gconf
;
1124 Error
*local_err
= NULL
;
1127 options
= g_new0(BlockdevCreateOptions
, 1);
1128 options
->driver
= BLOCKDEV_DRIVER_GLUSTER
;
1129 gopts
= &options
->u
.gluster
;
1131 gconf
= g_new0(BlockdevOptionsGluster
, 1);
1132 gopts
->location
= gconf
;
1134 gopts
->size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
1137 tmp
= qemu_opt_get_del(opts
, BLOCK_OPT_PREALLOC
);
1138 gopts
->preallocation
= qapi_enum_parse(&PreallocMode_lookup
, tmp
,
1139 PREALLOC_MODE_OFF
, &local_err
);
1142 error_propagate(errp
, local_err
);
1147 gconf
->debug
= qemu_opt_get_number_del(opts
, GLUSTER_OPT_DEBUG
,
1148 GLUSTER_DEBUG_DEFAULT
);
1149 if (gconf
->debug
< 0) {
1151 } else if (gconf
->debug
> GLUSTER_DEBUG_MAX
) {
1152 gconf
->debug
= GLUSTER_DEBUG_MAX
;
1154 gconf
->has_debug
= true;
1156 gconf
->logfile
= qemu_opt_get_del(opts
, GLUSTER_OPT_LOGFILE
);
1157 if (!gconf
->logfile
) {
1158 gconf
->logfile
= g_strdup(GLUSTER_LOGFILE_DEFAULT
);
1160 gconf
->has_logfile
= true;
1162 ret
= qemu_gluster_parse(gconf
, filename
, NULL
, errp
);
1167 ret
= qemu_gluster_co_create(options
, errp
);
1174 qapi_free_BlockdevCreateOptions(options
);
1178 static coroutine_fn
int qemu_gluster_co_rw(BlockDriverState
*bs
,
1179 int64_t sector_num
, int nb_sectors
,
1180 QEMUIOVector
*qiov
, int write
)
1184 BDRVGlusterState
*s
= bs
->opaque
;
1185 size_t size
= nb_sectors
* BDRV_SECTOR_SIZE
;
1186 off_t offset
= sector_num
* BDRV_SECTOR_SIZE
;
1190 acb
.coroutine
= qemu_coroutine_self();
1191 acb
.aio_context
= bdrv_get_aio_context(bs
);
1194 ret
= glfs_pwritev_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1195 gluster_finish_aiocb
, &acb
);
1197 ret
= glfs_preadv_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1198 gluster_finish_aiocb
, &acb
);
1205 qemu_coroutine_yield();
1209 static coroutine_fn
int qemu_gluster_co_truncate(BlockDriverState
*bs
,
1211 PreallocMode prealloc
,
1214 BDRVGlusterState
*s
= bs
->opaque
;
1215 return qemu_gluster_do_truncate(s
->fd
, offset
, prealloc
, errp
);
1218 static coroutine_fn
int qemu_gluster_co_readv(BlockDriverState
*bs
,
1223 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 0);
1226 static coroutine_fn
int qemu_gluster_co_writev(BlockDriverState
*bs
,
1233 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 1);
1236 static void qemu_gluster_close(BlockDriverState
*bs
)
1238 BDRVGlusterState
*s
= bs
->opaque
;
1245 glfs_clear_preopened(s
->glfs
);
1248 static coroutine_fn
int qemu_gluster_co_flush_to_disk(BlockDriverState
*bs
)
1252 BDRVGlusterState
*s
= bs
->opaque
;
1256 acb
.coroutine
= qemu_coroutine_self();
1257 acb
.aio_context
= bdrv_get_aio_context(bs
);
1259 ret
= glfs_fsync_async(s
->fd
, gluster_finish_aiocb
, &acb
);
1265 qemu_coroutine_yield();
1274 /* Some versions of Gluster (3.5.6 -> 3.5.8?) will not retain its cache
1275 * after a fsync failure, so we have no way of allowing the guest to safely
1276 * continue. Gluster versions prior to 3.5.6 don't retain the cache
1277 * either, but will invalidate the fd on error, so this is again our only
1280 * The 'resync-failed-syncs-after-fsync' xlator option for the
1281 * write-behind cache will cause later gluster versions to retain its
1282 * cache after error, so long as the fd remains open. However, we
1283 * currently have no way of knowing if this option is supported.
1285 * TODO: Once gluster provides a way for us to determine if the option
1286 * is supported, bypass the closure and setting drv to NULL. */
1287 qemu_gluster_close(bs
);
1292 #ifdef CONFIG_GLUSTERFS_DISCARD
1293 static coroutine_fn
int qemu_gluster_co_pdiscard(BlockDriverState
*bs
,
1294 int64_t offset
, int size
)
1298 BDRVGlusterState
*s
= bs
->opaque
;
1302 acb
.coroutine
= qemu_coroutine_self();
1303 acb
.aio_context
= bdrv_get_aio_context(bs
);
1305 ret
= glfs_discard_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1310 qemu_coroutine_yield();
1315 static int64_t qemu_gluster_getlength(BlockDriverState
*bs
)
1317 BDRVGlusterState
*s
= bs
->opaque
;
1320 ret
= glfs_lseek(s
->fd
, 0, SEEK_END
);
1328 static int64_t qemu_gluster_allocated_file_size(BlockDriverState
*bs
)
1330 BDRVGlusterState
*s
= bs
->opaque
;
1334 ret
= glfs_fstat(s
->fd
, &st
);
1338 return st
.st_blocks
* 512;
1342 static int qemu_gluster_has_zero_init(BlockDriverState
*bs
)
1344 /* GlusterFS volume could be backed by a block device */
1349 * Find allocation range in @bs around offset @start.
1350 * May change underlying file descriptor's file offset.
1351 * If @start is not in a hole, store @start in @data, and the
1352 * beginning of the next hole in @hole, and return 0.
1353 * If @start is in a non-trailing hole, store @start in @hole and the
1354 * beginning of the next non-hole in @data, and return 0.
1355 * If @start is in a trailing hole or beyond EOF, return -ENXIO.
1356 * If we can't find out, return a negative errno other than -ENXIO.
1358 * (Shamefully copied from file-posix.c, only minuscule adaptions.)
1360 static int find_allocation(BlockDriverState
*bs
, off_t start
,
1361 off_t
*data
, off_t
*hole
)
1363 BDRVGlusterState
*s
= bs
->opaque
;
1365 if (!s
->supports_seek_data
) {
1369 #if defined SEEK_HOLE && defined SEEK_DATA
1374 * D1. offs == start: start is in data
1375 * D2. offs > start: start is in a hole, next data at offs
1376 * D3. offs < 0, errno = ENXIO: either start is in a trailing hole
1377 * or start is beyond EOF
1378 * If the latter happens, the file has been truncated behind
1379 * our back since we opened it. All bets are off then.
1380 * Treating like a trailing hole is simplest.
1381 * D4. offs < 0, errno != ENXIO: we learned nothing
1383 offs
= glfs_lseek(s
->fd
, start
, SEEK_DATA
);
1385 return -errno
; /* D3 or D4 */
1389 /* This is not a valid return by lseek(). We are safe to just return
1390 * -EIO in this case, and we'll treat it like D4. Unfortunately some
1391 * versions of gluster server will return offs < start, so an assert
1392 * here will unnecessarily abort QEMU. */
1397 /* D2: in hole, next data at offs */
1403 /* D1: in data, end not yet known */
1407 * H1. offs == start: start is in a hole
1408 * If this happens here, a hole has been dug behind our back
1409 * since the previous lseek().
1410 * H2. offs > start: either start is in data, next hole at offs,
1411 * or start is in trailing hole, EOF at offs
1412 * Linux treats trailing holes like any other hole: offs ==
1413 * start. Solaris seeks to EOF instead: offs > start (blech).
1414 * If that happens here, a hole has been dug behind our back
1415 * since the previous lseek().
1416 * H3. offs < 0, errno = ENXIO: start is beyond EOF
1417 * If this happens, the file has been truncated behind our
1418 * back since we opened it. Treat it like a trailing hole.
1419 * H4. offs < 0, errno != ENXIO: we learned nothing
1420 * Pretend we know nothing at all, i.e. "forget" about D1.
1422 offs
= glfs_lseek(s
->fd
, start
, SEEK_HOLE
);
1424 return -errno
; /* D1 and (H3 or H4) */
1428 /* This is not a valid return by lseek(). We are safe to just return
1429 * -EIO in this case, and we'll treat it like H4. Unfortunately some
1430 * versions of gluster server will return offs < start, so an assert
1431 * here will unnecessarily abort QEMU. */
1437 * D1 and H2: either in data, next hole at offs, or it was in
1438 * data but is now in a trailing hole. In the latter case,
1439 * all bets are off. Treating it as if it there was data all
1440 * the way to EOF is safe, so simply do that.
1456 * Returns the allocation status of the specified offset.
1458 * The block layer guarantees 'offset' and 'bytes' are within bounds.
1460 * 'pnum' is set to the number of bytes (including and immediately following
1461 * the specified offset) that are known to be in the same
1462 * allocated/unallocated state.
1464 * 'bytes' is the max value 'pnum' should be set to.
1466 * (Based on raw_co_block_status() from file-posix.c.)
1468 static int coroutine_fn
qemu_gluster_co_block_status(BlockDriverState
*bs
,
1474 BlockDriverState
**file
)
1476 BDRVGlusterState
*s
= bs
->opaque
;
1477 off_t data
= 0, hole
= 0;
1488 return BDRV_BLOCK_DATA
| BDRV_BLOCK_OFFSET_VALID
;
1491 ret
= find_allocation(bs
, offset
, &data
, &hole
);
1492 if (ret
== -ENXIO
) {
1495 ret
= BDRV_BLOCK_ZERO
;
1496 } else if (ret
< 0) {
1497 /* No info available, so pretend there are no holes */
1499 ret
= BDRV_BLOCK_DATA
;
1500 } else if (data
== offset
) {
1501 /* On a data extent, compute bytes to the end of the extent,
1502 * possibly including a partial sector at EOF. */
1503 *pnum
= MIN(bytes
, hole
- offset
);
1504 ret
= BDRV_BLOCK_DATA
;
1506 /* On a hole, compute bytes to the beginning of the next extent. */
1507 assert(hole
== offset
);
1508 *pnum
= MIN(bytes
, data
- offset
);
1509 ret
= BDRV_BLOCK_ZERO
;
1515 return ret
| BDRV_BLOCK_OFFSET_VALID
;
1519 static const char *const gluster_strong_open_opts
[] = {
1523 GLUSTER_OPT_SERVER_PATTERN
,
1534 static BlockDriver bdrv_gluster
= {
1535 .format_name
= "gluster",
1536 .protocol_name
= "gluster",
1537 .instance_size
= sizeof(BDRVGlusterState
),
1538 .bdrv_needs_filename
= false,
1539 .bdrv_file_open
= qemu_gluster_open
,
1540 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1541 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1542 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1543 .bdrv_close
= qemu_gluster_close
,
1544 .bdrv_co_create
= qemu_gluster_co_create
,
1545 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1546 .bdrv_getlength
= qemu_gluster_getlength
,
1547 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1548 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1549 .bdrv_co_readv
= qemu_gluster_co_readv
,
1550 .bdrv_co_writev
= qemu_gluster_co_writev
,
1551 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1552 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1553 #ifdef CONFIG_GLUSTERFS_DISCARD
1554 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1556 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1557 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1559 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1560 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1561 .create_opts
= &qemu_gluster_create_opts
,
1562 .strong_runtime_opts
= gluster_strong_open_opts
,
1565 static BlockDriver bdrv_gluster_tcp
= {
1566 .format_name
= "gluster",
1567 .protocol_name
= "gluster+tcp",
1568 .instance_size
= sizeof(BDRVGlusterState
),
1569 .bdrv_needs_filename
= false,
1570 .bdrv_file_open
= qemu_gluster_open
,
1571 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1572 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1573 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1574 .bdrv_close
= qemu_gluster_close
,
1575 .bdrv_co_create
= qemu_gluster_co_create
,
1576 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1577 .bdrv_getlength
= qemu_gluster_getlength
,
1578 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1579 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1580 .bdrv_co_readv
= qemu_gluster_co_readv
,
1581 .bdrv_co_writev
= qemu_gluster_co_writev
,
1582 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1583 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1584 #ifdef CONFIG_GLUSTERFS_DISCARD
1585 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1587 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1588 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1590 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1591 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1592 .create_opts
= &qemu_gluster_create_opts
,
1593 .strong_runtime_opts
= gluster_strong_open_opts
,
1596 static BlockDriver bdrv_gluster_unix
= {
1597 .format_name
= "gluster",
1598 .protocol_name
= "gluster+unix",
1599 .instance_size
= sizeof(BDRVGlusterState
),
1600 .bdrv_needs_filename
= true,
1601 .bdrv_file_open
= qemu_gluster_open
,
1602 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1603 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1604 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1605 .bdrv_close
= qemu_gluster_close
,
1606 .bdrv_co_create
= qemu_gluster_co_create
,
1607 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1608 .bdrv_getlength
= qemu_gluster_getlength
,
1609 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1610 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1611 .bdrv_co_readv
= qemu_gluster_co_readv
,
1612 .bdrv_co_writev
= qemu_gluster_co_writev
,
1613 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1614 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1615 #ifdef CONFIG_GLUSTERFS_DISCARD
1616 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1618 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1619 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1621 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1622 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1623 .create_opts
= &qemu_gluster_create_opts
,
1624 .strong_runtime_opts
= gluster_strong_open_opts
,
1627 /* rdma is deprecated (actually never supported for volfile fetch).
1628 * Let's maintain it for the protocol compatibility, to make sure things
1629 * won't break immediately. For now, gluster+rdma will fall back to gluster+tcp
1630 * protocol with a warning.
1631 * TODO: remove gluster+rdma interface support
1633 static BlockDriver bdrv_gluster_rdma
= {
1634 .format_name
= "gluster",
1635 .protocol_name
= "gluster+rdma",
1636 .instance_size
= sizeof(BDRVGlusterState
),
1637 .bdrv_needs_filename
= true,
1638 .bdrv_file_open
= qemu_gluster_open
,
1639 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1640 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1641 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1642 .bdrv_close
= qemu_gluster_close
,
1643 .bdrv_co_create
= qemu_gluster_co_create
,
1644 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1645 .bdrv_getlength
= qemu_gluster_getlength
,
1646 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1647 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1648 .bdrv_co_readv
= qemu_gluster_co_readv
,
1649 .bdrv_co_writev
= qemu_gluster_co_writev
,
1650 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1651 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1652 #ifdef CONFIG_GLUSTERFS_DISCARD
1653 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1655 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1656 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1658 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1659 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1660 .create_opts
= &qemu_gluster_create_opts
,
1661 .strong_runtime_opts
= gluster_strong_open_opts
,
1664 static void bdrv_gluster_init(void)
1666 bdrv_register(&bdrv_gluster_rdma
);
1667 bdrv_register(&bdrv_gluster_unix
);
1668 bdrv_register(&bdrv_gluster_tcp
);
1669 bdrv_register(&bdrv_gluster
);
1672 block_init(bdrv_gluster_init
);