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-io.h"
15 #include "block/block_int.h"
16 #include "block/qdict.h"
17 #include "qapi/error.h"
18 #include "qapi/qmp/qdict.h"
19 #include "qapi/qmp/qerror.h"
20 #include "qemu/error-report.h"
21 #include "qemu/module.h"
22 #include "qemu/option.h"
23 #include "qemu/cutils.h"
25 #ifdef CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT
26 # define glfs_ftruncate(fd, offset) glfs_ftruncate(fd, offset, NULL, NULL)
29 #define GLUSTER_OPT_FILENAME "filename"
30 #define GLUSTER_OPT_VOLUME "volume"
31 #define GLUSTER_OPT_PATH "path"
32 #define GLUSTER_OPT_TYPE "type"
33 #define GLUSTER_OPT_SERVER_PATTERN "server."
34 #define GLUSTER_OPT_HOST "host"
35 #define GLUSTER_OPT_PORT "port"
36 #define GLUSTER_OPT_TO "to"
37 #define GLUSTER_OPT_IPV4 "ipv4"
38 #define GLUSTER_OPT_IPV6 "ipv6"
39 #define GLUSTER_OPT_SOCKET "socket"
40 #define GLUSTER_OPT_DEBUG "debug"
41 #define GLUSTER_DEFAULT_PORT 24007
42 #define GLUSTER_DEBUG_DEFAULT 4
43 #define GLUSTER_DEBUG_MAX 9
44 #define GLUSTER_OPT_LOGFILE "logfile"
45 #define GLUSTER_LOGFILE_DEFAULT "-" /* handled in libgfapi as /dev/stderr */
47 * Several versions of GlusterFS (3.12? -> 6.0.1) fail when the transfer size
48 * is greater or equal to 1024 MiB, so we are limiting the transfer size to 512
49 * MiB to avoid this rare issue.
51 #define GLUSTER_MAX_TRANSFER (512 * MiB)
53 #define GERR_INDEX_HINT "hint: check in 'server' array index '%d'\n"
55 typedef struct GlusterAIOCB
{
59 AioContext
*aio_context
;
62 typedef struct BDRVGlusterState
{
66 bool supports_seek_data
;
70 typedef struct BDRVGlusterReopenState
{
73 } BDRVGlusterReopenState
;
76 typedef struct GlfsPreopened
{
82 typedef struct ListElement
{
83 QLIST_ENTRY(ListElement
) list
;
87 static QLIST_HEAD(, ListElement
) glfs_list
;
89 static QemuOptsList qemu_gluster_create_opts
= {
90 .name
= "qemu-gluster-create-opts",
91 .head
= QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts
.head
),
94 .name
= BLOCK_OPT_SIZE
,
95 .type
= QEMU_OPT_SIZE
,
96 .help
= "Virtual disk size"
99 .name
= BLOCK_OPT_PREALLOC
,
100 .type
= QEMU_OPT_STRING
,
101 .help
= "Preallocation mode (allowed values: off"
102 #ifdef CONFIG_GLUSTERFS_FALLOCATE
105 #ifdef CONFIG_GLUSTERFS_ZEROFILL
111 .name
= GLUSTER_OPT_DEBUG
,
112 .type
= QEMU_OPT_NUMBER
,
113 .help
= "Gluster log level, valid range is 0-9",
116 .name
= GLUSTER_OPT_LOGFILE
,
117 .type
= QEMU_OPT_STRING
,
118 .help
= "Logfile path of libgfapi",
120 { /* end of list */ }
124 static QemuOptsList runtime_opts
= {
126 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
129 .name
= GLUSTER_OPT_FILENAME
,
130 .type
= QEMU_OPT_STRING
,
131 .help
= "URL to the gluster image",
134 .name
= GLUSTER_OPT_DEBUG
,
135 .type
= QEMU_OPT_NUMBER
,
136 .help
= "Gluster log level, valid range is 0-9",
139 .name
= GLUSTER_OPT_LOGFILE
,
140 .type
= QEMU_OPT_STRING
,
141 .help
= "Logfile path of libgfapi",
143 { /* end of list */ }
147 static QemuOptsList runtime_json_opts
= {
148 .name
= "gluster_json",
149 .head
= QTAILQ_HEAD_INITIALIZER(runtime_json_opts
.head
),
152 .name
= GLUSTER_OPT_VOLUME
,
153 .type
= QEMU_OPT_STRING
,
154 .help
= "name of gluster volume where VM image resides",
157 .name
= GLUSTER_OPT_PATH
,
158 .type
= QEMU_OPT_STRING
,
159 .help
= "absolute path to image file in gluster volume",
162 .name
= GLUSTER_OPT_DEBUG
,
163 .type
= QEMU_OPT_NUMBER
,
164 .help
= "Gluster log level, valid range is 0-9",
166 { /* end of list */ }
170 static QemuOptsList runtime_type_opts
= {
171 .name
= "gluster_type",
172 .head
= QTAILQ_HEAD_INITIALIZER(runtime_type_opts
.head
),
175 .name
= GLUSTER_OPT_TYPE
,
176 .type
= QEMU_OPT_STRING
,
179 { /* end of list */ }
183 static QemuOptsList runtime_unix_opts
= {
184 .name
= "gluster_unix",
185 .head
= QTAILQ_HEAD_INITIALIZER(runtime_unix_opts
.head
),
188 .name
= GLUSTER_OPT_SOCKET
,
189 .type
= QEMU_OPT_STRING
,
190 .help
= "socket file path (legacy)",
193 .name
= GLUSTER_OPT_PATH
,
194 .type
= QEMU_OPT_STRING
,
195 .help
= "socket file path (QAPI)",
197 { /* end of list */ }
201 static QemuOptsList runtime_inet_opts
= {
202 .name
= "gluster_inet",
203 .head
= QTAILQ_HEAD_INITIALIZER(runtime_inet_opts
.head
),
206 .name
= GLUSTER_OPT_TYPE
,
207 .type
= QEMU_OPT_STRING
,
211 .name
= GLUSTER_OPT_HOST
,
212 .type
= QEMU_OPT_STRING
,
213 .help
= "host address (hostname/ipv4/ipv6 addresses)",
216 .name
= GLUSTER_OPT_PORT
,
217 .type
= QEMU_OPT_STRING
,
218 .help
= "port number on which glusterd is listening (default 24007)",
222 .type
= QEMU_OPT_NUMBER
,
223 .help
= "max port number, not supported by gluster",
227 .type
= QEMU_OPT_BOOL
,
228 .help
= "ipv4 bool value, not supported by gluster",
232 .type
= QEMU_OPT_BOOL
,
233 .help
= "ipv6 bool value, not supported by gluster",
235 { /* end of list */ }
239 static void glfs_set_preopened(const char *volume
, glfs_t
*fs
)
241 ListElement
*entry
= NULL
;
243 entry
= g_new(ListElement
, 1);
245 entry
->saved
.volume
= g_strdup(volume
);
247 entry
->saved
.fs
= fs
;
248 entry
->saved
.ref
= 1;
250 QLIST_INSERT_HEAD(&glfs_list
, entry
, list
);
253 static glfs_t
*glfs_find_preopened(const char *volume
)
255 ListElement
*entry
= NULL
;
257 QLIST_FOREACH(entry
, &glfs_list
, list
) {
258 if (strcmp(entry
->saved
.volume
, volume
) == 0) {
260 return entry
->saved
.fs
;
267 static void glfs_clear_preopened(glfs_t
*fs
)
269 ListElement
*entry
= NULL
;
276 QLIST_FOREACH_SAFE(entry
, &glfs_list
, list
, next
) {
277 if (entry
->saved
.fs
== fs
) {
278 if (--entry
->saved
.ref
) {
282 QLIST_REMOVE(entry
, list
);
284 glfs_fini(entry
->saved
.fs
);
285 g_free(entry
->saved
.volume
);
291 static int parse_volume_options(BlockdevOptionsGluster
*gconf
, const char *path
)
300 p
= q
= path
+ strspn(path
, "/");
301 p
+= strcspn(p
, "/");
305 gconf
->volume
= g_strndup(q
, p
- q
);
312 gconf
->path
= g_strdup(p
);
317 * file=gluster[+transport]://[host[:port]]/volume/path[?socket=...]
319 * 'gluster' is the protocol.
321 * 'transport' specifies the transport type used to connect to gluster
322 * management daemon (glusterd). Valid transport types are
323 * tcp or unix. If a transport type isn't specified, then tcp type is assumed.
325 * 'host' specifies the host where the volume file specification for
326 * the given volume resides. This can be either hostname or ipv4 address.
327 * If transport type is 'unix', then 'host' field should not be specified.
328 * The 'socket' field needs to be populated with the path to unix domain
331 * 'port' is the port number on which glusterd is listening. This is optional
332 * and if not specified, QEMU will send 0 which will make gluster to use the
333 * default port. If the transport type is unix, then 'port' should not be
336 * 'volume' is the name of the gluster volume which contains the VM image.
338 * 'path' is the path to the actual VM image that resides on gluster volume.
342 * file=gluster://1.2.3.4/testvol/a.img
343 * file=gluster+tcp://1.2.3.4/testvol/a.img
344 * file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
345 * file=gluster+tcp://host.domain.com:24007/testvol/dir/a.img
346 * file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
348 static int qemu_gluster_parse_uri(BlockdevOptionsGluster
*gconf
,
349 const char *filename
)
351 g_autoptr(GUri
) uri
= g_uri_parse(filename
, G_URI_FLAGS_NONE
, NULL
);
352 g_autoptr(GHashTable
) qp
= NULL
;
353 SocketAddress
*gsconf
;
354 bool is_unix
= false;
355 const char *uri_scheme
, *uri_query
, *uri_server
;
362 gsconf
= g_new0(SocketAddress
, 1);
363 QAPI_LIST_PREPEND(gconf
->server
, gsconf
);
366 uri_scheme
= g_uri_get_scheme(uri
);
367 if (!uri_scheme
|| !strcmp(uri_scheme
, "gluster")) {
368 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
369 } else if (!strcmp(uri_scheme
, "gluster+tcp")) {
370 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
371 } else if (!strcmp(uri_scheme
, "gluster+unix")) {
372 gsconf
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
378 ret
= parse_volume_options(gconf
, g_uri_get_path(uri
));
383 uri_query
= g_uri_get_query(uri
);
385 qp
= g_uri_parse_params(uri_query
, -1, "&", G_URI_PARAMS_NONE
, NULL
);
389 ret
= g_hash_table_size(qp
);
390 if (ret
> 1 || (is_unix
&& !ret
) || (!is_unix
&& ret
)) {
395 uri_server
= g_uri_get_host(uri
);
396 uri_port
= g_uri_get_port(uri
);
399 char *uri_socket
= g_hash_table_lookup(qp
, "socket");
400 if (uri_server
|| uri_port
!= -1 || !uri_socket
) {
403 gsconf
->u
.q_unix
.path
= g_strdup(uri_socket
);
405 gsconf
->u
.inet
.host
= g_strdup(uri_server
? uri_server
: "localhost");
407 gsconf
->u
.inet
.port
= g_strdup_printf("%d", uri_port
);
409 gsconf
->u
.inet
.port
= g_strdup_printf("%d", GLUSTER_DEFAULT_PORT
);
416 static struct glfs
*qemu_gluster_glfs_init(BlockdevOptionsGluster
*gconf
,
422 SocketAddressList
*server
;
425 glfs
= glfs_find_preopened(gconf
->volume
);
430 glfs
= glfs_new(gconf
->volume
);
435 glfs_set_preopened(gconf
->volume
, glfs
);
437 for (server
= gconf
->server
; server
; server
= server
->next
) {
438 switch (server
->value
->type
) {
439 case SOCKET_ADDRESS_TYPE_UNIX
:
440 ret
= glfs_set_volfile_server(glfs
, "unix",
441 server
->value
->u
.q_unix
.path
, 0);
443 case SOCKET_ADDRESS_TYPE_INET
:
444 if (parse_uint_full(server
->value
->u
.inet
.port
, 10, &port
) < 0 ||
446 error_setg(errp
, "'%s' is not a valid port number",
447 server
->value
->u
.inet
.port
);
451 ret
= glfs_set_volfile_server(glfs
, "tcp",
452 server
->value
->u
.inet
.host
,
455 case SOCKET_ADDRESS_TYPE_VSOCK
:
456 case SOCKET_ADDRESS_TYPE_FD
:
466 ret
= glfs_set_logging(glfs
, gconf
->logfile
, gconf
->debug
);
471 ret
= glfs_init(glfs
);
473 error_setg(errp
, "Gluster connection for volume %s, path %s failed"
474 " to connect", gconf
->volume
, gconf
->path
);
475 for (server
= gconf
->server
; server
; server
= server
->next
) {
476 if (server
->value
->type
== SOCKET_ADDRESS_TYPE_UNIX
) {
477 error_append_hint(errp
, "hint: failed on socket %s ",
478 server
->value
->u
.q_unix
.path
);
480 error_append_hint(errp
, "hint: failed on host %s and port %s ",
481 server
->value
->u
.inet
.host
,
482 server
->value
->u
.inet
.port
);
486 error_append_hint(errp
, "Please refer to gluster logs for more info\n");
488 /* glfs_init sometimes doesn't set errno although docs suggest that */
500 glfs_clear_preopened(glfs
);
507 * Convert the json formatted command line into qapi.
509 static int qemu_gluster_parse_json(BlockdevOptionsGluster
*gconf
,
510 QDict
*options
, Error
**errp
)
513 SocketAddress
*gsconf
= NULL
;
514 SocketAddressList
**tail
;
515 QDict
*backing_options
= NULL
;
516 Error
*local_err
= NULL
;
519 int i
, type
, num_servers
;
521 /* create opts info from runtime_json_opts list */
522 opts
= qemu_opts_create(&runtime_json_opts
, NULL
, 0, &error_abort
);
523 if (!qemu_opts_absorb_qdict(opts
, options
, errp
)) {
527 num_servers
= qdict_array_entries(options
, GLUSTER_OPT_SERVER_PATTERN
);
528 if (num_servers
< 1) {
529 error_setg(&local_err
, QERR_MISSING_PARAMETER
, "server");
533 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_VOLUME
);
535 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_VOLUME
);
538 gconf
->volume
= g_strdup(ptr
);
540 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
542 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_PATH
);
545 gconf
->path
= g_strdup(ptr
);
547 tail
= &gconf
->server
;
549 for (i
= 0; i
< num_servers
; i
++) {
550 str
= g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN
"%d.", i
);
551 qdict_extract_subqdict(options
, &backing_options
, str
);
553 /* create opts info from runtime_type_opts list */
554 opts
= qemu_opts_create(&runtime_type_opts
, NULL
, 0, &error_abort
);
555 if (!qemu_opts_absorb_qdict(opts
, backing_options
, errp
)) {
559 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TYPE
);
561 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_TYPE
);
562 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
566 gsconf
= g_new0(SocketAddress
, 1);
567 if (!strcmp(ptr
, "tcp")) {
568 ptr
= "inet"; /* accept legacy "tcp" */
570 type
= qapi_enum_parse(&SocketAddressType_lookup
, ptr
, -1, NULL
);
571 if (type
!= SOCKET_ADDRESS_TYPE_INET
572 && type
!= SOCKET_ADDRESS_TYPE_UNIX
) {
573 error_setg(&local_err
,
574 "Parameter '%s' may be 'inet' or 'unix'",
576 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
582 if (gsconf
->type
== SOCKET_ADDRESS_TYPE_INET
) {
583 /* create opts info from runtime_inet_opts list */
584 opts
= qemu_opts_create(&runtime_inet_opts
, NULL
, 0, &error_abort
);
585 if (!qemu_opts_absorb_qdict(opts
, backing_options
, errp
)) {
589 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_HOST
);
591 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
593 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
596 gsconf
->u
.inet
.host
= g_strdup(ptr
);
597 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PORT
);
599 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
601 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
604 gsconf
->u
.inet
.port
= g_strdup(ptr
);
606 /* defend for unsupported fields in InetSocketAddress,
607 * i.e. @ipv4, @ipv6 and @to
609 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TO
);
611 gsconf
->u
.inet
.has_to
= true;
613 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV4
);
615 gsconf
->u
.inet
.has_ipv4
= true;
617 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV6
);
619 gsconf
->u
.inet
.has_ipv6
= true;
621 if (gsconf
->u
.inet
.has_to
) {
622 error_setg(&local_err
, "Parameter 'to' not supported");
625 if (gsconf
->u
.inet
.has_ipv4
|| gsconf
->u
.inet
.has_ipv6
) {
626 error_setg(&local_err
, "Parameters 'ipv4/ipv6' not supported");
631 /* create opts info from runtime_unix_opts list */
632 opts
= qemu_opts_create(&runtime_unix_opts
, NULL
, 0, &error_abort
);
633 if (!qemu_opts_absorb_qdict(opts
, backing_options
, errp
)) {
637 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
639 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
);
640 } else if (qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
)) {
641 error_setg(&local_err
,
642 "Conflicting parameters 'path' and 'socket'");
643 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
647 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
649 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
652 gsconf
->u
.q_unix
.path
= g_strdup(ptr
);
656 QAPI_LIST_APPEND(tail
, gsconf
);
659 qobject_unref(backing_options
);
660 backing_options
= NULL
;
668 error_propagate(errp
, local_err
);
669 qapi_free_SocketAddress(gsconf
);
672 qobject_unref(backing_options
);
677 /* Converts options given in @filename and the @options QDict into the QAPI
679 static int qemu_gluster_parse(BlockdevOptionsGluster
*gconf
,
680 const char *filename
,
681 QDict
*options
, Error
**errp
)
685 ret
= qemu_gluster_parse_uri(gconf
, filename
);
687 error_setg(errp
, "invalid URI %s", filename
);
688 error_append_hint(errp
, "Usage: file=gluster[+transport]://"
689 "[host[:port]]volume/path[?socket=...]"
691 "[,file.logfile=/path/filename.log]\n");
695 ret
= qemu_gluster_parse_json(gconf
, options
, errp
);
697 error_append_hint(errp
, "Usage: "
698 "-drive driver=qcow2,file.driver=gluster,"
699 "file.volume=testvol,file.path=/path/a.qcow2"
701 "[,file.logfile=/path/filename.log],"
702 "file.server.0.type=inet,"
703 "file.server.0.host=1.2.3.4,"
704 "file.server.0.port=24007,"
705 "file.server.1.transport=unix,"
706 "file.server.1.path=/var/run/glusterd.socket ..."
715 static struct glfs
*qemu_gluster_init(BlockdevOptionsGluster
*gconf
,
716 const char *filename
,
717 QDict
*options
, Error
**errp
)
721 ret
= qemu_gluster_parse(gconf
, filename
, options
, errp
);
727 return qemu_gluster_glfs_init(gconf
, errp
);
731 * AIO callback routine called from GlusterFS thread.
733 static void gluster_finish_aiocb(struct glfs_fd
*fd
, ssize_t ret
,
734 #ifdef CONFIG_GLUSTERFS_IOCB_HAS_STAT
735 struct glfs_stat
*pre
, struct glfs_stat
*post
,
739 GlusterAIOCB
*acb
= (GlusterAIOCB
*)arg
;
741 if (!ret
|| ret
== acb
->size
) {
742 acb
->ret
= 0; /* Success */
743 } else if (ret
< 0) {
744 acb
->ret
= -errno
; /* Read/Write failed */
746 acb
->ret
= -EIO
; /* Partial read/write - fail it */
749 aio_co_schedule(acb
->aio_context
, acb
->coroutine
);
752 static void qemu_gluster_parse_flags(int bdrv_flags
, int *open_flags
)
754 assert(open_flags
!= NULL
);
756 *open_flags
|= O_BINARY
;
758 if (bdrv_flags
& BDRV_O_RDWR
) {
759 *open_flags
|= O_RDWR
;
761 *open_flags
|= O_RDONLY
;
764 if ((bdrv_flags
& BDRV_O_NOCACHE
)) {
765 *open_flags
|= O_DIRECT
;
770 * Do SEEK_DATA/HOLE to detect if it is functional. Older broken versions of
771 * gfapi incorrectly return the current offset when SEEK_DATA/HOLE is used.
772 * - Corrected versions return -1 and set errno to EINVAL.
773 * - Versions that support SEEK_DATA/HOLE correctly, will return -1 and set
774 * errno to ENXIO when SEEK_DATA is called with a position of EOF.
776 static bool qemu_gluster_test_seek(struct glfs_fd
*fd
)
780 #if defined SEEK_HOLE && defined SEEK_DATA
783 eof
= glfs_lseek(fd
, 0, SEEK_END
);
785 /* this should never occur */
789 /* this should always fail with ENXIO if SEEK_DATA is supported */
790 ret
= glfs_lseek(fd
, eof
, SEEK_DATA
);
793 return (ret
< 0) && (errno
== ENXIO
);
796 static int qemu_gluster_open(BlockDriverState
*bs
, QDict
*options
,
797 int bdrv_flags
, Error
**errp
)
799 BDRVGlusterState
*s
= bs
->opaque
;
802 BlockdevOptionsGluster
*gconf
= NULL
;
804 const char *filename
, *logfile
;
806 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
807 if (!qemu_opts_absorb_qdict(opts
, options
, errp
)) {
812 warn_report_once("'gluster' is deprecated");
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
);
833 s
->glfs
= qemu_gluster_init(gconf
, filename
, options
, errp
);
839 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
840 /* Without this, if fsync fails for a recoverable reason (for instance,
841 * ENOSPC), gluster will dump its cache, preventing retries. This means
842 * almost certain data loss. Not all gluster versions support the
843 * 'resync-failed-syncs-after-fsync' key value, but there is no way to
844 * discover during runtime if it is supported (this api returns success for
845 * unknown key/value pairs) */
846 ret
= glfs_set_xlator_option(s
->glfs
, "*-write-behind",
847 "resync-failed-syncs-after-fsync",
850 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
856 qemu_gluster_parse_flags(bdrv_flags
, &open_flags
);
858 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
859 ret
= s
->fd
? 0 : -errno
;
861 if (ret
== -EACCES
|| ret
== -EROFS
) {
862 /* Try to degrade to read-only, but if it doesn't work, still use the
863 * normal error message. */
864 bdrv_graph_rdlock_main_loop();
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
;
870 bdrv_graph_rdunlock_main_loop();
873 s
->supports_seek_data
= qemu_gluster_test_seek(s
->fd
);
877 qapi_free_BlockdevOptionsGluster(gconf
);
886 glfs_clear_preopened(s
->glfs
);
891 static void qemu_gluster_refresh_limits(BlockDriverState
*bs
, Error
**errp
)
893 bs
->bl
.max_transfer
= GLUSTER_MAX_TRANSFER
;
894 bs
->bl
.max_pdiscard
= MIN(SIZE_MAX
, INT64_MAX
);
897 static int qemu_gluster_reopen_prepare(BDRVReopenState
*state
,
898 BlockReopenQueue
*queue
, Error
**errp
)
902 BDRVGlusterReopenState
*reop_s
;
903 BlockdevOptionsGluster
*gconf
;
906 assert(state
!= NULL
);
907 assert(state
->bs
!= NULL
);
909 s
= state
->bs
->opaque
;
911 state
->opaque
= g_new0(BDRVGlusterReopenState
, 1);
912 reop_s
= state
->opaque
;
914 qemu_gluster_parse_flags(state
->flags
, &open_flags
);
916 gconf
= g_new0(BlockdevOptionsGluster
, 1);
917 gconf
->debug
= s
->debug
;
918 gconf
->has_debug
= true;
919 gconf
->logfile
= g_strdup(s
->logfile
);
922 * If 'state->bs->exact_filename' is empty, 'state->options' should contain
923 * the JSON parameters already parsed.
925 if (state
->bs
->exact_filename
[0] != '\0') {
926 reop_s
->glfs
= qemu_gluster_init(gconf
, state
->bs
->exact_filename
, NULL
,
929 reop_s
->glfs
= qemu_gluster_init(gconf
, NULL
, state
->options
, errp
);
931 if (reop_s
->glfs
== NULL
) {
936 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
937 ret
= glfs_set_xlator_option(reop_s
->glfs
, "*-write-behind",
938 "resync-failed-syncs-after-fsync", "on");
940 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
946 reop_s
->fd
= glfs_open(reop_s
->glfs
, gconf
->path
, open_flags
);
947 if (reop_s
->fd
== NULL
) {
948 /* reops->glfs will be cleaned up in _abort */
954 /* state->opaque will be freed in either the _abort or _commit */
955 qapi_free_BlockdevOptionsGluster(gconf
);
959 static void qemu_gluster_reopen_commit(BDRVReopenState
*state
)
961 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
962 BDRVGlusterState
*s
= state
->bs
->opaque
;
970 glfs_clear_preopened(s
->glfs
);
972 /* use the newly opened image / connection */
974 s
->glfs
= reop_s
->glfs
;
976 g_free(state
->opaque
);
977 state
->opaque
= NULL
;
983 static void qemu_gluster_reopen_abort(BDRVReopenState
*state
)
985 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
987 if (reop_s
== NULL
) {
992 glfs_close(reop_s
->fd
);
995 glfs_clear_preopened(reop_s
->glfs
);
997 g_free(state
->opaque
);
998 state
->opaque
= NULL
;
1003 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1004 static coroutine_fn
int qemu_gluster_co_pwrite_zeroes(BlockDriverState
*bs
,
1007 BdrvRequestFlags flags
)
1011 BDRVGlusterState
*s
= bs
->opaque
;
1015 acb
.coroutine
= qemu_coroutine_self();
1016 acb
.aio_context
= bdrv_get_aio_context(bs
);
1018 ret
= glfs_zerofill_async(s
->fd
, offset
, bytes
, gluster_finish_aiocb
, &acb
);
1023 qemu_coroutine_yield();
1028 static int qemu_gluster_do_truncate(struct glfs_fd
*fd
, int64_t offset
,
1029 PreallocMode prealloc
, Error
**errp
)
1031 int64_t current_length
;
1033 current_length
= glfs_lseek(fd
, 0, SEEK_END
);
1034 if (current_length
< 0) {
1035 error_setg_errno(errp
, errno
, "Failed to determine current size");
1039 if (current_length
> offset
&& prealloc
!= PREALLOC_MODE_OFF
) {
1040 error_setg(errp
, "Cannot use preallocation for shrinking files");
1044 if (current_length
== offset
) {
1049 #ifdef CONFIG_GLUSTERFS_FALLOCATE
1050 case PREALLOC_MODE_FALLOC
:
1051 if (glfs_fallocate(fd
, 0, current_length
, offset
- current_length
)) {
1052 error_setg_errno(errp
, errno
, "Could not preallocate data");
1056 #endif /* CONFIG_GLUSTERFS_FALLOCATE */
1057 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1058 case PREALLOC_MODE_FULL
:
1059 if (glfs_ftruncate(fd
, offset
)) {
1060 error_setg_errno(errp
, errno
, "Could not resize file");
1063 if (glfs_zerofill(fd
, current_length
, offset
- current_length
)) {
1064 error_setg_errno(errp
, errno
, "Could not zerofill the new area");
1068 #endif /* CONFIG_GLUSTERFS_ZEROFILL */
1069 case PREALLOC_MODE_OFF
:
1070 if (glfs_ftruncate(fd
, offset
)) {
1071 error_setg_errno(errp
, errno
, "Could not resize file");
1076 error_setg(errp
, "Unsupported preallocation mode: %s",
1077 PreallocMode_str(prealloc
));
1084 static int qemu_gluster_co_create(BlockdevCreateOptions
*options
,
1087 BlockdevCreateOptionsGluster
*opts
= &options
->u
.gluster
;
1089 struct glfs_fd
*fd
= NULL
;
1092 assert(options
->driver
== BLOCKDEV_DRIVER_GLUSTER
);
1094 glfs
= qemu_gluster_glfs_init(opts
->location
, errp
);
1100 fd
= glfs_creat(glfs
, opts
->location
->path
,
1101 O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, S_IRUSR
| S_IWUSR
);
1107 ret
= qemu_gluster_do_truncate(fd
, opts
->size
, opts
->preallocation
, errp
);
1111 if (glfs_close(fd
) != 0 && ret
== 0) {
1115 glfs_clear_preopened(glfs
);
1119 static int coroutine_fn
qemu_gluster_co_create_opts(BlockDriver
*drv
,
1120 const char *filename
,
1124 BlockdevCreateOptions
*options
;
1125 BlockdevCreateOptionsGluster
*gopts
;
1126 BlockdevOptionsGluster
*gconf
;
1128 Error
*local_err
= NULL
;
1131 options
= g_new0(BlockdevCreateOptions
, 1);
1132 options
->driver
= BLOCKDEV_DRIVER_GLUSTER
;
1133 gopts
= &options
->u
.gluster
;
1135 gconf
= g_new0(BlockdevOptionsGluster
, 1);
1136 gopts
->location
= gconf
;
1138 gopts
->size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
1141 tmp
= qemu_opt_get_del(opts
, BLOCK_OPT_PREALLOC
);
1142 gopts
->preallocation
= qapi_enum_parse(&PreallocMode_lookup
, tmp
,
1143 PREALLOC_MODE_OFF
, &local_err
);
1146 error_propagate(errp
, local_err
);
1151 gconf
->debug
= qemu_opt_get_number_del(opts
, GLUSTER_OPT_DEBUG
,
1152 GLUSTER_DEBUG_DEFAULT
);
1153 if (gconf
->debug
< 0) {
1155 } else if (gconf
->debug
> GLUSTER_DEBUG_MAX
) {
1156 gconf
->debug
= GLUSTER_DEBUG_MAX
;
1158 gconf
->has_debug
= true;
1160 gconf
->logfile
= qemu_opt_get_del(opts
, GLUSTER_OPT_LOGFILE
);
1161 if (!gconf
->logfile
) {
1162 gconf
->logfile
= g_strdup(GLUSTER_LOGFILE_DEFAULT
);
1165 ret
= qemu_gluster_parse(gconf
, filename
, NULL
, errp
);
1170 ret
= qemu_gluster_co_create(options
, errp
);
1177 qapi_free_BlockdevCreateOptions(options
);
1181 static coroutine_fn
int qemu_gluster_co_rw(BlockDriverState
*bs
,
1182 int64_t sector_num
, int nb_sectors
,
1183 QEMUIOVector
*qiov
, int write
)
1187 BDRVGlusterState
*s
= bs
->opaque
;
1188 size_t size
= nb_sectors
* BDRV_SECTOR_SIZE
;
1189 off_t offset
= sector_num
* BDRV_SECTOR_SIZE
;
1193 acb
.coroutine
= qemu_coroutine_self();
1194 acb
.aio_context
= bdrv_get_aio_context(bs
);
1197 ret
= glfs_pwritev_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1198 gluster_finish_aiocb
, &acb
);
1200 ret
= glfs_preadv_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1201 gluster_finish_aiocb
, &acb
);
1208 qemu_coroutine_yield();
1212 static coroutine_fn
int qemu_gluster_co_truncate(BlockDriverState
*bs
,
1215 PreallocMode prealloc
,
1216 BdrvRequestFlags flags
,
1219 BDRVGlusterState
*s
= bs
->opaque
;
1220 return qemu_gluster_do_truncate(s
->fd
, offset
, prealloc
, errp
);
1223 static coroutine_fn
int qemu_gluster_co_readv(BlockDriverState
*bs
,
1228 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 0);
1231 static coroutine_fn
int qemu_gluster_co_writev(BlockDriverState
*bs
,
1237 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 1);
1240 static void qemu_gluster_close(BlockDriverState
*bs
)
1242 BDRVGlusterState
*s
= bs
->opaque
;
1249 glfs_clear_preopened(s
->glfs
);
1252 static coroutine_fn
int qemu_gluster_co_flush_to_disk(BlockDriverState
*bs
)
1256 BDRVGlusterState
*s
= bs
->opaque
;
1260 acb
.coroutine
= qemu_coroutine_self();
1261 acb
.aio_context
= bdrv_get_aio_context(bs
);
1263 ret
= glfs_fsync_async(s
->fd
, gluster_finish_aiocb
, &acb
);
1269 qemu_coroutine_yield();
1278 /* Some versions of Gluster (3.5.6 -> 3.5.8?) will not retain its cache
1279 * after a fsync failure, so we have no way of allowing the guest to safely
1280 * continue. Gluster versions prior to 3.5.6 don't retain the cache
1281 * either, but will invalidate the fd on error, so this is again our only
1284 * The 'resync-failed-syncs-after-fsync' xlator option for the
1285 * write-behind cache will cause later gluster versions to retain its
1286 * cache after error, so long as the fd remains open. However, we
1287 * currently have no way of knowing if this option is supported.
1289 * TODO: Once gluster provides a way for us to determine if the option
1290 * is supported, bypass the closure and setting drv to NULL. */
1291 qemu_gluster_close(bs
);
1296 #ifdef CONFIG_GLUSTERFS_DISCARD
1297 static coroutine_fn
int qemu_gluster_co_pdiscard(BlockDriverState
*bs
,
1298 int64_t offset
, int64_t bytes
)
1302 BDRVGlusterState
*s
= bs
->opaque
;
1304 assert(bytes
<= SIZE_MAX
); /* rely on max_pdiscard */
1308 acb
.coroutine
= qemu_coroutine_self();
1309 acb
.aio_context
= bdrv_get_aio_context(bs
);
1311 ret
= glfs_discard_async(s
->fd
, offset
, bytes
, gluster_finish_aiocb
, &acb
);
1316 qemu_coroutine_yield();
1321 static int64_t coroutine_fn
qemu_gluster_co_getlength(BlockDriverState
*bs
)
1323 BDRVGlusterState
*s
= bs
->opaque
;
1326 ret
= glfs_lseek(s
->fd
, 0, SEEK_END
);
1334 static int64_t coroutine_fn
1335 qemu_gluster_co_get_allocated_file_size(BlockDriverState
*bs
)
1337 BDRVGlusterState
*s
= bs
->opaque
;
1341 ret
= glfs_fstat(s
->fd
, &st
);
1345 return st
.st_blocks
* 512;
1350 * Find allocation range in @bs around offset @start.
1351 * May change underlying file descriptor's file offset.
1352 * If @start is not in a hole, store @start in @data, and the
1353 * beginning of the next hole in @hole, and return 0.
1354 * If @start is in a non-trailing hole, store @start in @hole and the
1355 * beginning of the next non-hole in @data, and return 0.
1356 * If @start is in a trailing hole or beyond EOF, return -ENXIO.
1357 * If we can't find out, return a negative errno other than -ENXIO.
1359 * (Shamefully copied from file-posix.c, only minuscule adaptions.)
1361 static int find_allocation(BlockDriverState
*bs
, off_t start
,
1362 off_t
*data
, off_t
*hole
)
1364 BDRVGlusterState
*s
= bs
->opaque
;
1366 if (!s
->supports_seek_data
) {
1370 #if defined SEEK_HOLE && defined SEEK_DATA
1375 * D1. offs == start: start is in data
1376 * D2. offs > start: start is in a hole, next data at offs
1377 * D3. offs < 0, errno = ENXIO: either start is in a trailing hole
1378 * or start is beyond EOF
1379 * If the latter happens, the file has been truncated behind
1380 * our back since we opened it. All bets are off then.
1381 * Treating like a trailing hole is simplest.
1382 * D4. offs < 0, errno != ENXIO: we learned nothing
1384 offs
= glfs_lseek(s
->fd
, start
, SEEK_DATA
);
1386 return -errno
; /* D3 or D4 */
1390 /* This is not a valid return by lseek(). We are safe to just return
1391 * -EIO in this case, and we'll treat it like D4. Unfortunately some
1392 * versions of gluster server will return offs < start, so an assert
1393 * here will unnecessarily abort QEMU. */
1398 /* D2: in hole, next data at offs */
1404 /* D1: in data, end not yet known */
1408 * H1. offs == start: start is in a hole
1409 * If this happens here, a hole has been dug behind our back
1410 * since the previous lseek().
1411 * H2. offs > start: either start is in data, next hole at offs,
1412 * or start is in trailing hole, EOF at offs
1413 * Linux treats trailing holes like any other hole: offs ==
1414 * start. Solaris seeks to EOF instead: offs > start (blech).
1415 * If that happens here, a hole has been dug behind our back
1416 * since the previous lseek().
1417 * H3. offs < 0, errno = ENXIO: start is beyond EOF
1418 * If this happens, the file has been truncated behind our
1419 * back since we opened it. Treat it like a trailing hole.
1420 * H4. offs < 0, errno != ENXIO: we learned nothing
1421 * Pretend we know nothing at all, i.e. "forget" about D1.
1423 offs
= glfs_lseek(s
->fd
, start
, SEEK_HOLE
);
1425 return -errno
; /* D1 and (H3 or H4) */
1429 /* This is not a valid return by lseek(). We are safe to just return
1430 * -EIO in this case, and we'll treat it like H4. Unfortunately some
1431 * versions of gluster server will return offs < start, so an assert
1432 * here will unnecessarily abort QEMU. */
1438 * D1 and H2: either in data, next hole at offs, or it was in
1439 * data but is now in a trailing hole. In the latter case,
1440 * all bets are off. Treating it as if it there was data all
1441 * the way to EOF is safe, so simply do that.
1457 * Returns the allocation status of the specified offset.
1459 * The block layer guarantees 'offset' and 'bytes' are within bounds.
1461 * 'pnum' is set to the number of bytes (including and immediately following
1462 * the specified offset) that are known to be in the same
1463 * allocated/unallocated state.
1465 * 'bytes' is a soft cap for 'pnum'. If the information is free, 'pnum' may
1468 * (Based on raw_co_block_status() from file-posix.c.)
1470 static int coroutine_fn
qemu_gluster_co_block_status(BlockDriverState
*bs
,
1476 BlockDriverState
**file
)
1478 BDRVGlusterState
*s
= bs
->opaque
;
1479 off_t data
= 0, hole
= 0;
1482 assert(QEMU_IS_ALIGNED(offset
| bytes
, bs
->bl
.request_alignment
));
1492 return BDRV_BLOCK_DATA
| BDRV_BLOCK_OFFSET_VALID
;
1495 ret
= find_allocation(bs
, offset
, &data
, &hole
);
1496 if (ret
== -ENXIO
) {
1499 ret
= BDRV_BLOCK_ZERO
;
1500 } else if (ret
< 0) {
1501 /* No info available, so pretend there are no holes */
1503 ret
= BDRV_BLOCK_DATA
;
1504 } else if (data
== offset
) {
1505 /* On a data extent, compute bytes to the end of the extent,
1506 * possibly including a partial sector at EOF. */
1507 *pnum
= hole
- offset
;
1510 * We are not allowed to return partial sectors, though, so
1511 * round up if necessary.
1513 if (!QEMU_IS_ALIGNED(*pnum
, bs
->bl
.request_alignment
)) {
1514 int64_t file_length
= qemu_gluster_co_getlength(bs
);
1515 if (file_length
> 0) {
1516 /* Ignore errors, this is just a safeguard */
1517 assert(hole
== file_length
);
1519 *pnum
= ROUND_UP(*pnum
, bs
->bl
.request_alignment
);
1522 ret
= BDRV_BLOCK_DATA
;
1524 /* On a hole, compute bytes to the beginning of the next extent. */
1525 assert(hole
== offset
);
1526 *pnum
= data
- offset
;
1527 ret
= BDRV_BLOCK_ZERO
;
1533 return ret
| BDRV_BLOCK_OFFSET_VALID
;
1537 static const char *const gluster_strong_open_opts
[] = {
1541 GLUSTER_OPT_SERVER_PATTERN
,
1552 static BlockDriver bdrv_gluster
= {
1553 .format_name
= "gluster",
1554 .protocol_name
= "gluster",
1555 .instance_size
= sizeof(BDRVGlusterState
),
1556 .bdrv_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_co_getlength
= qemu_gluster_co_getlength
,
1564 .bdrv_co_get_allocated_file_size
= qemu_gluster_co_get_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 #ifdef CONFIG_GLUSTERFS_DISCARD
1570 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1572 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1573 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1575 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1576 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1577 .create_opts
= &qemu_gluster_create_opts
,
1578 .strong_runtime_opts
= gluster_strong_open_opts
,
1581 static BlockDriver bdrv_gluster_tcp
= {
1582 .format_name
= "gluster",
1583 .protocol_name
= "gluster+tcp",
1584 .instance_size
= sizeof(BDRVGlusterState
),
1585 .bdrv_open
= qemu_gluster_open
,
1586 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1587 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1588 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1589 .bdrv_close
= qemu_gluster_close
,
1590 .bdrv_co_create
= qemu_gluster_co_create
,
1591 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1592 .bdrv_co_getlength
= qemu_gluster_co_getlength
,
1593 .bdrv_co_get_allocated_file_size
= qemu_gluster_co_get_allocated_file_size
,
1594 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1595 .bdrv_co_readv
= qemu_gluster_co_readv
,
1596 .bdrv_co_writev
= qemu_gluster_co_writev
,
1597 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1598 #ifdef CONFIG_GLUSTERFS_DISCARD
1599 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1601 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1602 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1604 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1605 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1606 .create_opts
= &qemu_gluster_create_opts
,
1607 .strong_runtime_opts
= gluster_strong_open_opts
,
1610 static BlockDriver bdrv_gluster_unix
= {
1611 .format_name
= "gluster",
1612 .protocol_name
= "gluster+unix",
1613 .instance_size
= sizeof(BDRVGlusterState
),
1614 .bdrv_open
= qemu_gluster_open
,
1615 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1616 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1617 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1618 .bdrv_close
= qemu_gluster_close
,
1619 .bdrv_co_create
= qemu_gluster_co_create
,
1620 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1621 .bdrv_co_getlength
= qemu_gluster_co_getlength
,
1622 .bdrv_co_get_allocated_file_size
= qemu_gluster_co_get_allocated_file_size
,
1623 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1624 .bdrv_co_readv
= qemu_gluster_co_readv
,
1625 .bdrv_co_writev
= qemu_gluster_co_writev
,
1626 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1627 #ifdef CONFIG_GLUSTERFS_DISCARD
1628 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1630 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1631 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1633 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1634 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1635 .create_opts
= &qemu_gluster_create_opts
,
1636 .strong_runtime_opts
= gluster_strong_open_opts
,
1639 static void bdrv_gluster_init(void)
1641 bdrv_register(&bdrv_gluster_unix
);
1642 bdrv_register(&bdrv_gluster_tcp
);
1643 bdrv_register(&bdrv_gluster
);
1646 block_init(bdrv_gluster_init
);