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/option.h"
22 #include "qemu/cutils.h"
24 #ifdef CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT
25 # define glfs_ftruncate(fd, offset) glfs_ftruncate(fd, offset, NULL, NULL)
28 #define GLUSTER_OPT_FILENAME "filename"
29 #define GLUSTER_OPT_VOLUME "volume"
30 #define GLUSTER_OPT_PATH "path"
31 #define GLUSTER_OPT_TYPE "type"
32 #define GLUSTER_OPT_SERVER_PATTERN "server."
33 #define GLUSTER_OPT_HOST "host"
34 #define GLUSTER_OPT_PORT "port"
35 #define GLUSTER_OPT_TO "to"
36 #define GLUSTER_OPT_IPV4 "ipv4"
37 #define GLUSTER_OPT_IPV6 "ipv6"
38 #define GLUSTER_OPT_SOCKET "socket"
39 #define GLUSTER_OPT_DEBUG "debug"
40 #define GLUSTER_DEFAULT_PORT 24007
41 #define GLUSTER_DEBUG_DEFAULT 4
42 #define GLUSTER_DEBUG_MAX 9
43 #define GLUSTER_OPT_LOGFILE "logfile"
44 #define GLUSTER_LOGFILE_DEFAULT "-" /* handled in libgfapi as /dev/stderr */
46 * Several versions of GlusterFS (3.12? -> 6.0.1) fail when the transfer size
47 * is greater or equal to 1024 MiB, so we are limiting the transfer size to 512
48 * MiB to avoid this rare issue.
50 #define GLUSTER_MAX_TRANSFER (512 * MiB)
52 #define GERR_INDEX_HINT "hint: check in 'server' array index '%d'\n"
54 typedef struct GlusterAIOCB
{
58 AioContext
*aio_context
;
61 typedef struct BDRVGlusterState
{
65 bool supports_seek_data
;
69 typedef struct BDRVGlusterReopenState
{
72 } BDRVGlusterReopenState
;
75 typedef struct GlfsPreopened
{
81 typedef struct ListElement
{
82 QLIST_ENTRY(ListElement
) list
;
86 static QLIST_HEAD(, ListElement
) glfs_list
;
88 static QemuOptsList qemu_gluster_create_opts
= {
89 .name
= "qemu-gluster-create-opts",
90 .head
= QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts
.head
),
93 .name
= BLOCK_OPT_SIZE
,
94 .type
= QEMU_OPT_SIZE
,
95 .help
= "Virtual disk size"
98 .name
= BLOCK_OPT_PREALLOC
,
99 .type
= QEMU_OPT_STRING
,
100 .help
= "Preallocation mode (allowed values: off, full)"
103 .name
= GLUSTER_OPT_DEBUG
,
104 .type
= QEMU_OPT_NUMBER
,
105 .help
= "Gluster log level, valid range is 0-9",
108 .name
= GLUSTER_OPT_LOGFILE
,
109 .type
= QEMU_OPT_STRING
,
110 .help
= "Logfile path of libgfapi",
112 { /* end of list */ }
116 static QemuOptsList runtime_opts
= {
118 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
121 .name
= GLUSTER_OPT_FILENAME
,
122 .type
= QEMU_OPT_STRING
,
123 .help
= "URL to the gluster image",
126 .name
= GLUSTER_OPT_DEBUG
,
127 .type
= QEMU_OPT_NUMBER
,
128 .help
= "Gluster log level, valid range is 0-9",
131 .name
= GLUSTER_OPT_LOGFILE
,
132 .type
= QEMU_OPT_STRING
,
133 .help
= "Logfile path of libgfapi",
135 { /* end of list */ }
139 static QemuOptsList runtime_json_opts
= {
140 .name
= "gluster_json",
141 .head
= QTAILQ_HEAD_INITIALIZER(runtime_json_opts
.head
),
144 .name
= GLUSTER_OPT_VOLUME
,
145 .type
= QEMU_OPT_STRING
,
146 .help
= "name of gluster volume where VM image resides",
149 .name
= GLUSTER_OPT_PATH
,
150 .type
= QEMU_OPT_STRING
,
151 .help
= "absolute path to image file in gluster volume",
154 .name
= GLUSTER_OPT_DEBUG
,
155 .type
= QEMU_OPT_NUMBER
,
156 .help
= "Gluster log level, valid range is 0-9",
158 { /* end of list */ }
162 static QemuOptsList runtime_type_opts
= {
163 .name
= "gluster_type",
164 .head
= QTAILQ_HEAD_INITIALIZER(runtime_type_opts
.head
),
167 .name
= GLUSTER_OPT_TYPE
,
168 .type
= QEMU_OPT_STRING
,
171 { /* end of list */ }
175 static QemuOptsList runtime_unix_opts
= {
176 .name
= "gluster_unix",
177 .head
= QTAILQ_HEAD_INITIALIZER(runtime_unix_opts
.head
),
180 .name
= GLUSTER_OPT_SOCKET
,
181 .type
= QEMU_OPT_STRING
,
182 .help
= "socket file path (legacy)",
185 .name
= GLUSTER_OPT_PATH
,
186 .type
= QEMU_OPT_STRING
,
187 .help
= "socket file path (QAPI)",
189 { /* end of list */ }
193 static QemuOptsList runtime_inet_opts
= {
194 .name
= "gluster_inet",
195 .head
= QTAILQ_HEAD_INITIALIZER(runtime_inet_opts
.head
),
198 .name
= GLUSTER_OPT_TYPE
,
199 .type
= QEMU_OPT_STRING
,
203 .name
= GLUSTER_OPT_HOST
,
204 .type
= QEMU_OPT_STRING
,
205 .help
= "host address (hostname/ipv4/ipv6 addresses)",
208 .name
= GLUSTER_OPT_PORT
,
209 .type
= QEMU_OPT_STRING
,
210 .help
= "port number on which glusterd is listening (default 24007)",
214 .type
= QEMU_OPT_NUMBER
,
215 .help
= "max port number, not supported by gluster",
219 .type
= QEMU_OPT_BOOL
,
220 .help
= "ipv4 bool value, not supported by gluster",
224 .type
= QEMU_OPT_BOOL
,
225 .help
= "ipv6 bool value, not supported by gluster",
227 { /* end of list */ }
231 static void glfs_set_preopened(const char *volume
, glfs_t
*fs
)
233 ListElement
*entry
= NULL
;
235 entry
= g_new(ListElement
, 1);
237 entry
->saved
.volume
= g_strdup(volume
);
239 entry
->saved
.fs
= fs
;
240 entry
->saved
.ref
= 1;
242 QLIST_INSERT_HEAD(&glfs_list
, entry
, list
);
245 static glfs_t
*glfs_find_preopened(const char *volume
)
247 ListElement
*entry
= NULL
;
249 QLIST_FOREACH(entry
, &glfs_list
, list
) {
250 if (strcmp(entry
->saved
.volume
, volume
) == 0) {
252 return entry
->saved
.fs
;
259 static void glfs_clear_preopened(glfs_t
*fs
)
261 ListElement
*entry
= NULL
;
268 QLIST_FOREACH_SAFE(entry
, &glfs_list
, list
, next
) {
269 if (entry
->saved
.fs
== fs
) {
270 if (--entry
->saved
.ref
) {
274 QLIST_REMOVE(entry
, list
);
276 glfs_fini(entry
->saved
.fs
);
277 g_free(entry
->saved
.volume
);
283 static int parse_volume_options(BlockdevOptionsGluster
*gconf
, char *path
)
292 p
= q
= path
+ strspn(path
, "/");
293 p
+= strcspn(p
, "/");
297 gconf
->volume
= g_strndup(q
, p
- q
);
304 gconf
->path
= g_strdup(p
);
309 * file=gluster[+transport]://[host[:port]]/volume/path[?socket=...]
311 * 'gluster' is the protocol.
313 * 'transport' specifies the transport type used to connect to gluster
314 * management daemon (glusterd). Valid transport types are
315 * tcp or unix. If a transport type isn't specified, then tcp type is assumed.
317 * 'host' specifies the host where the volume file specification for
318 * the given volume resides. This can be either hostname or ipv4 address.
319 * If transport type is 'unix', then 'host' field should not be specified.
320 * The 'socket' field needs to be populated with the path to unix domain
323 * 'port' is the port number on which glusterd is listening. This is optional
324 * and if not specified, QEMU will send 0 which will make gluster to use the
325 * default port. If the transport type is unix, then 'port' should not be
328 * 'volume' is the name of the gluster volume which contains the VM image.
330 * 'path' is the path to the actual VM image that resides on gluster volume.
334 * file=gluster://1.2.3.4/testvol/a.img
335 * file=gluster+tcp://1.2.3.4/testvol/a.img
336 * file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
337 * file=gluster+tcp://host.domain.com:24007/testvol/dir/a.img
338 * file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
340 static int qemu_gluster_parse_uri(BlockdevOptionsGluster
*gconf
,
341 const char *filename
)
343 SocketAddress
*gsconf
;
345 QueryParams
*qp
= NULL
;
346 bool is_unix
= false;
349 uri
= uri_parse(filename
);
354 gconf
->server
= g_new0(SocketAddressList
, 1);
355 gconf
->server
->value
= gsconf
= g_new0(SocketAddress
, 1);
358 if (!uri
->scheme
|| !strcmp(uri
->scheme
, "gluster")) {
359 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
360 } else if (!strcmp(uri
->scheme
, "gluster+tcp")) {
361 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
362 } else if (!strcmp(uri
->scheme
, "gluster+unix")) {
363 gsconf
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
365 } else if (!strcmp(uri
->scheme
, "gluster+rdma")) {
366 gsconf
->type
= SOCKET_ADDRESS_TYPE_INET
;
367 warn_report("rdma feature is not supported, falling back to tcp");
373 ret
= parse_volume_options(gconf
, uri
->path
);
378 qp
= query_params_parse(uri
->query
);
379 if (qp
->n
> 1 || (is_unix
&& !qp
->n
) || (!is_unix
&& qp
->n
)) {
385 if (uri
->server
|| uri
->port
) {
389 if (strcmp(qp
->p
[0].name
, "socket")) {
393 gsconf
->u
.q_unix
.path
= g_strdup(qp
->p
[0].value
);
395 gsconf
->u
.inet
.host
= g_strdup(uri
->server
? uri
->server
: "localhost");
397 gsconf
->u
.inet
.port
= g_strdup_printf("%d", uri
->port
);
399 gsconf
->u
.inet
.port
= g_strdup_printf("%d", GLUSTER_DEFAULT_PORT
);
405 query_params_free(qp
);
411 static struct glfs
*qemu_gluster_glfs_init(BlockdevOptionsGluster
*gconf
,
417 SocketAddressList
*server
;
418 unsigned long long port
;
420 glfs
= glfs_find_preopened(gconf
->volume
);
425 glfs
= glfs_new(gconf
->volume
);
430 glfs_set_preopened(gconf
->volume
, glfs
);
432 for (server
= gconf
->server
; server
; server
= server
->next
) {
433 switch (server
->value
->type
) {
434 case SOCKET_ADDRESS_TYPE_UNIX
:
435 ret
= glfs_set_volfile_server(glfs
, "unix",
436 server
->value
->u
.q_unix
.path
, 0);
438 case SOCKET_ADDRESS_TYPE_INET
:
439 if (parse_uint_full(server
->value
->u
.inet
.port
, &port
, 10) < 0 ||
441 error_setg(errp
, "'%s' is not a valid port number",
442 server
->value
->u
.inet
.port
);
446 ret
= glfs_set_volfile_server(glfs
, "tcp",
447 server
->value
->u
.inet
.host
,
450 case SOCKET_ADDRESS_TYPE_VSOCK
:
451 case SOCKET_ADDRESS_TYPE_FD
:
461 ret
= glfs_set_logging(glfs
, gconf
->logfile
, gconf
->debug
);
466 ret
= glfs_init(glfs
);
468 error_setg(errp
, "Gluster connection for volume %s, path %s failed"
469 " to connect", gconf
->volume
, gconf
->path
);
470 for (server
= gconf
->server
; server
; server
= server
->next
) {
471 if (server
->value
->type
== SOCKET_ADDRESS_TYPE_UNIX
) {
472 error_append_hint(errp
, "hint: failed on socket %s ",
473 server
->value
->u
.q_unix
.path
);
475 error_append_hint(errp
, "hint: failed on host %s and port %s ",
476 server
->value
->u
.inet
.host
,
477 server
->value
->u
.inet
.port
);
481 error_append_hint(errp
, "Please refer to gluster logs for more info\n");
483 /* glfs_init sometimes doesn't set errno although docs suggest that */
495 glfs_clear_preopened(glfs
);
502 * Convert the json formatted command line into qapi.
504 static int qemu_gluster_parse_json(BlockdevOptionsGluster
*gconf
,
505 QDict
*options
, Error
**errp
)
508 SocketAddress
*gsconf
= NULL
;
509 SocketAddressList
*curr
= NULL
;
510 QDict
*backing_options
= NULL
;
511 Error
*local_err
= NULL
;
514 int i
, type
, num_servers
;
516 /* create opts info from runtime_json_opts list */
517 opts
= qemu_opts_create(&runtime_json_opts
, NULL
, 0, &error_abort
);
518 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
523 num_servers
= qdict_array_entries(options
, GLUSTER_OPT_SERVER_PATTERN
);
524 if (num_servers
< 1) {
525 error_setg(&local_err
, QERR_MISSING_PARAMETER
, "server");
529 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_VOLUME
);
531 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_VOLUME
);
534 gconf
->volume
= g_strdup(ptr
);
536 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
538 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_PATH
);
541 gconf
->path
= g_strdup(ptr
);
544 for (i
= 0; i
< num_servers
; i
++) {
545 str
= g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN
"%d.", i
);
546 qdict_extract_subqdict(options
, &backing_options
, str
);
548 /* create opts info from runtime_type_opts list */
549 opts
= qemu_opts_create(&runtime_type_opts
, NULL
, 0, &error_abort
);
550 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
555 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TYPE
);
557 error_setg(&local_err
, QERR_MISSING_PARAMETER
, GLUSTER_OPT_TYPE
);
558 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
562 gsconf
= g_new0(SocketAddress
, 1);
563 if (!strcmp(ptr
, "tcp")) {
564 ptr
= "inet"; /* accept legacy "tcp" */
566 type
= qapi_enum_parse(&SocketAddressType_lookup
, ptr
, -1, NULL
);
567 if (type
!= SOCKET_ADDRESS_TYPE_INET
568 && type
!= SOCKET_ADDRESS_TYPE_UNIX
) {
569 error_setg(&local_err
,
570 "Parameter '%s' may be 'inet' or 'unix'",
572 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
578 if (gsconf
->type
== SOCKET_ADDRESS_TYPE_INET
) {
579 /* create opts info from runtime_inet_opts list */
580 opts
= qemu_opts_create(&runtime_inet_opts
, NULL
, 0, &error_abort
);
581 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
586 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_HOST
);
588 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
590 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
593 gsconf
->u
.inet
.host
= g_strdup(ptr
);
594 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PORT
);
596 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
598 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
601 gsconf
->u
.inet
.port
= g_strdup(ptr
);
603 /* defend for unsupported fields in InetSocketAddress,
604 * i.e. @ipv4, @ipv6 and @to
606 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_TO
);
608 gsconf
->u
.inet
.has_to
= true;
610 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV4
);
612 gsconf
->u
.inet
.has_ipv4
= true;
614 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_IPV6
);
616 gsconf
->u
.inet
.has_ipv6
= true;
618 if (gsconf
->u
.inet
.has_to
) {
619 error_setg(&local_err
, "Parameter 'to' not supported");
622 if (gsconf
->u
.inet
.has_ipv4
|| gsconf
->u
.inet
.has_ipv6
) {
623 error_setg(&local_err
, "Parameters 'ipv4/ipv6' not supported");
628 /* create opts info from runtime_unix_opts list */
629 opts
= qemu_opts_create(&runtime_unix_opts
, NULL
, 0, &error_abort
);
630 qemu_opts_absorb_qdict(opts
, backing_options
, &local_err
);
635 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_PATH
);
637 ptr
= qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
);
638 } else if (qemu_opt_get(opts
, GLUSTER_OPT_SOCKET
)) {
639 error_setg(&local_err
,
640 "Conflicting parameters 'path' and 'socket'");
641 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
645 error_setg(&local_err
, QERR_MISSING_PARAMETER
,
647 error_append_hint(&local_err
, GERR_INDEX_HINT
, i
);
650 gsconf
->u
.q_unix
.path
= g_strdup(ptr
);
654 if (gconf
->server
== NULL
) {
655 gconf
->server
= g_new0(SocketAddressList
, 1);
656 gconf
->server
->value
= gsconf
;
657 curr
= gconf
->server
;
659 curr
->next
= g_new0(SocketAddressList
, 1);
660 curr
->next
->value
= gsconf
;
665 qobject_unref(backing_options
);
666 backing_options
= NULL
;
674 error_propagate(errp
, local_err
);
675 qapi_free_SocketAddress(gsconf
);
678 qobject_unref(backing_options
);
683 /* Converts options given in @filename and the @options QDict into the QAPI
685 static int qemu_gluster_parse(BlockdevOptionsGluster
*gconf
,
686 const char *filename
,
687 QDict
*options
, Error
**errp
)
691 ret
= qemu_gluster_parse_uri(gconf
, filename
);
693 error_setg(errp
, "invalid URI %s", filename
);
694 error_append_hint(errp
, "Usage: file=gluster[+transport]://"
695 "[host[:port]]volume/path[?socket=...]"
697 "[,file.logfile=/path/filename.log]\n");
701 ret
= qemu_gluster_parse_json(gconf
, options
, errp
);
703 error_append_hint(errp
, "Usage: "
704 "-drive driver=qcow2,file.driver=gluster,"
705 "file.volume=testvol,file.path=/path/a.qcow2"
707 "[,file.logfile=/path/filename.log],"
708 "file.server.0.type=inet,"
709 "file.server.0.host=1.2.3.4,"
710 "file.server.0.port=24007,"
711 "file.server.1.transport=unix,"
712 "file.server.1.path=/var/run/glusterd.socket ..."
721 static struct glfs
*qemu_gluster_init(BlockdevOptionsGluster
*gconf
,
722 const char *filename
,
723 QDict
*options
, Error
**errp
)
727 ret
= qemu_gluster_parse(gconf
, filename
, options
, errp
);
733 return qemu_gluster_glfs_init(gconf
, errp
);
737 * AIO callback routine called from GlusterFS thread.
739 static void gluster_finish_aiocb(struct glfs_fd
*fd
, ssize_t ret
,
740 #ifdef CONFIG_GLUSTERFS_IOCB_HAS_STAT
741 struct glfs_stat
*pre
, struct glfs_stat
*post
,
745 GlusterAIOCB
*acb
= (GlusterAIOCB
*)arg
;
747 if (!ret
|| ret
== acb
->size
) {
748 acb
->ret
= 0; /* Success */
749 } else if (ret
< 0) {
750 acb
->ret
= -errno
; /* Read/Write failed */
752 acb
->ret
= -EIO
; /* Partial read/write - fail it */
755 aio_co_schedule(acb
->aio_context
, acb
->coroutine
);
758 static void qemu_gluster_parse_flags(int bdrv_flags
, int *open_flags
)
760 assert(open_flags
!= NULL
);
762 *open_flags
|= O_BINARY
;
764 if (bdrv_flags
& BDRV_O_RDWR
) {
765 *open_flags
|= O_RDWR
;
767 *open_flags
|= O_RDONLY
;
770 if ((bdrv_flags
& BDRV_O_NOCACHE
)) {
771 *open_flags
|= O_DIRECT
;
776 * Do SEEK_DATA/HOLE to detect if it is functional. Older broken versions of
777 * gfapi incorrectly return the current offset when SEEK_DATA/HOLE is used.
778 * - Corrected versions return -1 and set errno to EINVAL.
779 * - Versions that support SEEK_DATA/HOLE correctly, will return -1 and set
780 * errno to ENXIO when SEEK_DATA is called with a position of EOF.
782 static bool qemu_gluster_test_seek(struct glfs_fd
*fd
)
786 #if defined SEEK_HOLE && defined SEEK_DATA
789 eof
= glfs_lseek(fd
, 0, SEEK_END
);
791 /* this should never occur */
795 /* this should always fail with ENXIO if SEEK_DATA is supported */
796 ret
= glfs_lseek(fd
, eof
, SEEK_DATA
);
799 return (ret
< 0) && (errno
== ENXIO
);
802 static int qemu_gluster_open(BlockDriverState
*bs
, QDict
*options
,
803 int bdrv_flags
, Error
**errp
)
805 BDRVGlusterState
*s
= bs
->opaque
;
808 BlockdevOptionsGluster
*gconf
= NULL
;
810 Error
*local_err
= NULL
;
811 const char *filename
, *logfile
;
813 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
814 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
816 error_propagate(errp
, local_err
);
821 filename
= qemu_opt_get(opts
, GLUSTER_OPT_FILENAME
);
823 s
->debug
= qemu_opt_get_number(opts
, GLUSTER_OPT_DEBUG
,
824 GLUSTER_DEBUG_DEFAULT
);
827 } else if (s
->debug
> GLUSTER_DEBUG_MAX
) {
828 s
->debug
= GLUSTER_DEBUG_MAX
;
831 gconf
= g_new0(BlockdevOptionsGluster
, 1);
832 gconf
->debug
= s
->debug
;
833 gconf
->has_debug
= true;
835 logfile
= qemu_opt_get(opts
, GLUSTER_OPT_LOGFILE
);
836 s
->logfile
= g_strdup(logfile
? logfile
: GLUSTER_LOGFILE_DEFAULT
);
838 gconf
->logfile
= g_strdup(s
->logfile
);
839 gconf
->has_logfile
= true;
841 s
->glfs
= qemu_gluster_init(gconf
, filename
, options
, errp
);
847 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
848 /* Without this, if fsync fails for a recoverable reason (for instance,
849 * ENOSPC), gluster will dump its cache, preventing retries. This means
850 * almost certain data loss. Not all gluster versions support the
851 * 'resync-failed-syncs-after-fsync' key value, but there is no way to
852 * discover during runtime if it is supported (this api returns success for
853 * unknown key/value pairs) */
854 ret
= glfs_set_xlator_option(s
->glfs
, "*-write-behind",
855 "resync-failed-syncs-after-fsync",
858 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
864 qemu_gluster_parse_flags(bdrv_flags
, &open_flags
);
866 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
867 ret
= s
->fd
? 0 : -errno
;
869 if (ret
== -EACCES
|| ret
== -EROFS
) {
870 /* Try to degrade to read-only, but if it doesn't work, still use the
871 * normal error message. */
872 if (bdrv_apply_auto_read_only(bs
, NULL
, NULL
) == 0) {
873 open_flags
= (open_flags
& ~O_RDWR
) | O_RDONLY
;
874 s
->fd
= glfs_open(s
->glfs
, gconf
->path
, open_flags
);
875 ret
= s
->fd
? 0 : -errno
;
879 s
->supports_seek_data
= qemu_gluster_test_seek(s
->fd
);
883 qapi_free_BlockdevOptionsGluster(gconf
);
892 glfs_clear_preopened(s
->glfs
);
897 static void qemu_gluster_refresh_limits(BlockDriverState
*bs
, Error
**errp
)
899 bs
->bl
.max_transfer
= GLUSTER_MAX_TRANSFER
;
902 static int qemu_gluster_reopen_prepare(BDRVReopenState
*state
,
903 BlockReopenQueue
*queue
, Error
**errp
)
907 BDRVGlusterReopenState
*reop_s
;
908 BlockdevOptionsGluster
*gconf
;
911 assert(state
!= NULL
);
912 assert(state
->bs
!= NULL
);
914 s
= state
->bs
->opaque
;
916 state
->opaque
= g_new0(BDRVGlusterReopenState
, 1);
917 reop_s
= state
->opaque
;
919 qemu_gluster_parse_flags(state
->flags
, &open_flags
);
921 gconf
= g_new0(BlockdevOptionsGluster
, 1);
922 gconf
->debug
= s
->debug
;
923 gconf
->has_debug
= true;
924 gconf
->logfile
= g_strdup(s
->logfile
);
925 gconf
->has_logfile
= true;
926 reop_s
->glfs
= qemu_gluster_init(gconf
, state
->bs
->filename
, NULL
, errp
);
927 if (reop_s
->glfs
== NULL
) {
932 #ifdef CONFIG_GLUSTERFS_XLATOR_OPT
933 ret
= glfs_set_xlator_option(reop_s
->glfs
, "*-write-behind",
934 "resync-failed-syncs-after-fsync", "on");
936 error_setg_errno(errp
, errno
, "Unable to set xlator key/value pair");
942 reop_s
->fd
= glfs_open(reop_s
->glfs
, gconf
->path
, open_flags
);
943 if (reop_s
->fd
== NULL
) {
944 /* reops->glfs will be cleaned up in _abort */
950 /* state->opaque will be freed in either the _abort or _commit */
951 qapi_free_BlockdevOptionsGluster(gconf
);
955 static void qemu_gluster_reopen_commit(BDRVReopenState
*state
)
957 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
958 BDRVGlusterState
*s
= state
->bs
->opaque
;
966 glfs_clear_preopened(s
->glfs
);
968 /* use the newly opened image / connection */
970 s
->glfs
= reop_s
->glfs
;
972 g_free(state
->opaque
);
973 state
->opaque
= NULL
;
979 static void qemu_gluster_reopen_abort(BDRVReopenState
*state
)
981 BDRVGlusterReopenState
*reop_s
= state
->opaque
;
983 if (reop_s
== NULL
) {
988 glfs_close(reop_s
->fd
);
991 glfs_clear_preopened(reop_s
->glfs
);
993 g_free(state
->opaque
);
994 state
->opaque
= NULL
;
999 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1000 static coroutine_fn
int qemu_gluster_co_pwrite_zeroes(BlockDriverState
*bs
,
1003 BdrvRequestFlags flags
)
1007 BDRVGlusterState
*s
= bs
->opaque
;
1011 acb
.coroutine
= qemu_coroutine_self();
1012 acb
.aio_context
= bdrv_get_aio_context(bs
);
1014 ret
= glfs_zerofill_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1019 qemu_coroutine_yield();
1024 static int qemu_gluster_do_truncate(struct glfs_fd
*fd
, int64_t offset
,
1025 PreallocMode prealloc
, Error
**errp
)
1027 int64_t current_length
;
1029 current_length
= glfs_lseek(fd
, 0, SEEK_END
);
1030 if (current_length
< 0) {
1031 error_setg_errno(errp
, errno
, "Failed to determine current size");
1035 if (current_length
> offset
&& prealloc
!= PREALLOC_MODE_OFF
) {
1036 error_setg(errp
, "Cannot use preallocation for shrinking files");
1040 if (current_length
== offset
) {
1045 #ifdef CONFIG_GLUSTERFS_FALLOCATE
1046 case PREALLOC_MODE_FALLOC
:
1047 if (glfs_fallocate(fd
, 0, current_length
, offset
- current_length
)) {
1048 error_setg_errno(errp
, errno
, "Could not preallocate data");
1052 #endif /* CONFIG_GLUSTERFS_FALLOCATE */
1053 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1054 case PREALLOC_MODE_FULL
:
1055 if (glfs_ftruncate(fd
, offset
)) {
1056 error_setg_errno(errp
, errno
, "Could not resize file");
1059 if (glfs_zerofill(fd
, current_length
, offset
- current_length
)) {
1060 error_setg_errno(errp
, errno
, "Could not zerofill the new area");
1064 #endif /* CONFIG_GLUSTERFS_ZEROFILL */
1065 case PREALLOC_MODE_OFF
:
1066 if (glfs_ftruncate(fd
, offset
)) {
1067 error_setg_errno(errp
, errno
, "Could not resize file");
1072 error_setg(errp
, "Unsupported preallocation mode: %s",
1073 PreallocMode_str(prealloc
));
1080 static int qemu_gluster_co_create(BlockdevCreateOptions
*options
,
1083 BlockdevCreateOptionsGluster
*opts
= &options
->u
.gluster
;
1085 struct glfs_fd
*fd
= NULL
;
1088 assert(options
->driver
== BLOCKDEV_DRIVER_GLUSTER
);
1090 glfs
= qemu_gluster_glfs_init(opts
->location
, errp
);
1096 fd
= glfs_creat(glfs
, opts
->location
->path
,
1097 O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, S_IRUSR
| S_IWUSR
);
1103 ret
= qemu_gluster_do_truncate(fd
, opts
->size
, opts
->preallocation
, errp
);
1107 if (glfs_close(fd
) != 0 && ret
== 0) {
1111 glfs_clear_preopened(glfs
);
1115 static int coroutine_fn
qemu_gluster_co_create_opts(const char *filename
,
1119 BlockdevCreateOptions
*options
;
1120 BlockdevCreateOptionsGluster
*gopts
;
1121 BlockdevOptionsGluster
*gconf
;
1123 Error
*local_err
= NULL
;
1126 options
= g_new0(BlockdevCreateOptions
, 1);
1127 options
->driver
= BLOCKDEV_DRIVER_GLUSTER
;
1128 gopts
= &options
->u
.gluster
;
1130 gconf
= g_new0(BlockdevOptionsGluster
, 1);
1131 gopts
->location
= gconf
;
1133 gopts
->size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
1136 tmp
= qemu_opt_get_del(opts
, BLOCK_OPT_PREALLOC
);
1137 gopts
->preallocation
= qapi_enum_parse(&PreallocMode_lookup
, tmp
,
1138 PREALLOC_MODE_OFF
, &local_err
);
1141 error_propagate(errp
, local_err
);
1146 gconf
->debug
= qemu_opt_get_number_del(opts
, GLUSTER_OPT_DEBUG
,
1147 GLUSTER_DEBUG_DEFAULT
);
1148 if (gconf
->debug
< 0) {
1150 } else if (gconf
->debug
> GLUSTER_DEBUG_MAX
) {
1151 gconf
->debug
= GLUSTER_DEBUG_MAX
;
1153 gconf
->has_debug
= true;
1155 gconf
->logfile
= qemu_opt_get_del(opts
, GLUSTER_OPT_LOGFILE
);
1156 if (!gconf
->logfile
) {
1157 gconf
->logfile
= g_strdup(GLUSTER_LOGFILE_DEFAULT
);
1159 gconf
->has_logfile
= true;
1161 ret
= qemu_gluster_parse(gconf
, filename
, NULL
, errp
);
1166 ret
= qemu_gluster_co_create(options
, errp
);
1173 qapi_free_BlockdevCreateOptions(options
);
1177 static coroutine_fn
int qemu_gluster_co_rw(BlockDriverState
*bs
,
1178 int64_t sector_num
, int nb_sectors
,
1179 QEMUIOVector
*qiov
, int write
)
1183 BDRVGlusterState
*s
= bs
->opaque
;
1184 size_t size
= nb_sectors
* BDRV_SECTOR_SIZE
;
1185 off_t offset
= sector_num
* BDRV_SECTOR_SIZE
;
1189 acb
.coroutine
= qemu_coroutine_self();
1190 acb
.aio_context
= bdrv_get_aio_context(bs
);
1193 ret
= glfs_pwritev_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1194 gluster_finish_aiocb
, &acb
);
1196 ret
= glfs_preadv_async(s
->fd
, qiov
->iov
, qiov
->niov
, offset
, 0,
1197 gluster_finish_aiocb
, &acb
);
1204 qemu_coroutine_yield();
1208 static coroutine_fn
int qemu_gluster_co_truncate(BlockDriverState
*bs
,
1210 PreallocMode prealloc
,
1213 BDRVGlusterState
*s
= bs
->opaque
;
1214 return qemu_gluster_do_truncate(s
->fd
, offset
, prealloc
, errp
);
1217 static coroutine_fn
int qemu_gluster_co_readv(BlockDriverState
*bs
,
1222 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 0);
1225 static coroutine_fn
int qemu_gluster_co_writev(BlockDriverState
*bs
,
1232 return qemu_gluster_co_rw(bs
, sector_num
, nb_sectors
, qiov
, 1);
1235 static void qemu_gluster_close(BlockDriverState
*bs
)
1237 BDRVGlusterState
*s
= bs
->opaque
;
1244 glfs_clear_preopened(s
->glfs
);
1247 static coroutine_fn
int qemu_gluster_co_flush_to_disk(BlockDriverState
*bs
)
1251 BDRVGlusterState
*s
= bs
->opaque
;
1255 acb
.coroutine
= qemu_coroutine_self();
1256 acb
.aio_context
= bdrv_get_aio_context(bs
);
1258 ret
= glfs_fsync_async(s
->fd
, gluster_finish_aiocb
, &acb
);
1264 qemu_coroutine_yield();
1273 /* Some versions of Gluster (3.5.6 -> 3.5.8?) will not retain its cache
1274 * after a fsync failure, so we have no way of allowing the guest to safely
1275 * continue. Gluster versions prior to 3.5.6 don't retain the cache
1276 * either, but will invalidate the fd on error, so this is again our only
1279 * The 'resync-failed-syncs-after-fsync' xlator option for the
1280 * write-behind cache will cause later gluster versions to retain its
1281 * cache after error, so long as the fd remains open. However, we
1282 * currently have no way of knowing if this option is supported.
1284 * TODO: Once gluster provides a way for us to determine if the option
1285 * is supported, bypass the closure and setting drv to NULL. */
1286 qemu_gluster_close(bs
);
1291 #ifdef CONFIG_GLUSTERFS_DISCARD
1292 static coroutine_fn
int qemu_gluster_co_pdiscard(BlockDriverState
*bs
,
1293 int64_t offset
, int size
)
1297 BDRVGlusterState
*s
= bs
->opaque
;
1301 acb
.coroutine
= qemu_coroutine_self();
1302 acb
.aio_context
= bdrv_get_aio_context(bs
);
1304 ret
= glfs_discard_async(s
->fd
, offset
, size
, gluster_finish_aiocb
, &acb
);
1309 qemu_coroutine_yield();
1314 static int64_t qemu_gluster_getlength(BlockDriverState
*bs
)
1316 BDRVGlusterState
*s
= bs
->opaque
;
1319 ret
= glfs_lseek(s
->fd
, 0, SEEK_END
);
1327 static int64_t qemu_gluster_allocated_file_size(BlockDriverState
*bs
)
1329 BDRVGlusterState
*s
= bs
->opaque
;
1333 ret
= glfs_fstat(s
->fd
, &st
);
1337 return st
.st_blocks
* 512;
1341 static int qemu_gluster_has_zero_init(BlockDriverState
*bs
)
1343 /* GlusterFS volume could be backed by a block device */
1348 * Find allocation range in @bs around offset @start.
1349 * May change underlying file descriptor's file offset.
1350 * If @start is not in a hole, store @start in @data, and the
1351 * beginning of the next hole in @hole, and return 0.
1352 * If @start is in a non-trailing hole, store @start in @hole and the
1353 * beginning of the next non-hole in @data, and return 0.
1354 * If @start is in a trailing hole or beyond EOF, return -ENXIO.
1355 * If we can't find out, return a negative errno other than -ENXIO.
1357 * (Shamefully copied from file-posix.c, only minuscule adaptions.)
1359 static int find_allocation(BlockDriverState
*bs
, off_t start
,
1360 off_t
*data
, off_t
*hole
)
1362 BDRVGlusterState
*s
= bs
->opaque
;
1364 if (!s
->supports_seek_data
) {
1368 #if defined SEEK_HOLE && defined SEEK_DATA
1373 * D1. offs == start: start is in data
1374 * D2. offs > start: start is in a hole, next data at offs
1375 * D3. offs < 0, errno = ENXIO: either start is in a trailing hole
1376 * or start is beyond EOF
1377 * If the latter happens, the file has been truncated behind
1378 * our back since we opened it. All bets are off then.
1379 * Treating like a trailing hole is simplest.
1380 * D4. offs < 0, errno != ENXIO: we learned nothing
1382 offs
= glfs_lseek(s
->fd
, start
, SEEK_DATA
);
1384 return -errno
; /* D3 or D4 */
1388 /* This is not a valid return by lseek(). We are safe to just return
1389 * -EIO in this case, and we'll treat it like D4. Unfortunately some
1390 * versions of gluster server will return offs < start, so an assert
1391 * here will unnecessarily abort QEMU. */
1396 /* D2: in hole, next data at offs */
1402 /* D1: in data, end not yet known */
1406 * H1. offs == start: start is in a hole
1407 * If this happens here, a hole has been dug behind our back
1408 * since the previous lseek().
1409 * H2. offs > start: either start is in data, next hole at offs,
1410 * or start is in trailing hole, EOF at offs
1411 * Linux treats trailing holes like any other hole: offs ==
1412 * start. Solaris seeks to EOF instead: offs > start (blech).
1413 * If that happens here, a hole has been dug behind our back
1414 * since the previous lseek().
1415 * H3. offs < 0, errno = ENXIO: start is beyond EOF
1416 * If this happens, the file has been truncated behind our
1417 * back since we opened it. Treat it like a trailing hole.
1418 * H4. offs < 0, errno != ENXIO: we learned nothing
1419 * Pretend we know nothing at all, i.e. "forget" about D1.
1421 offs
= glfs_lseek(s
->fd
, start
, SEEK_HOLE
);
1423 return -errno
; /* D1 and (H3 or H4) */
1427 /* This is not a valid return by lseek(). We are safe to just return
1428 * -EIO in this case, and we'll treat it like H4. Unfortunately some
1429 * versions of gluster server will return offs < start, so an assert
1430 * here will unnecessarily abort QEMU. */
1436 * D1 and H2: either in data, next hole at offs, or it was in
1437 * data but is now in a trailing hole. In the latter case,
1438 * all bets are off. Treating it as if it there was data all
1439 * the way to EOF is safe, so simply do that.
1455 * Returns the allocation status of the specified offset.
1457 * The block layer guarantees 'offset' and 'bytes' are within bounds.
1459 * 'pnum' is set to the number of bytes (including and immediately following
1460 * the specified offset) that are known to be in the same
1461 * allocated/unallocated state.
1463 * 'bytes' is the max value 'pnum' should be set to.
1465 * (Based on raw_co_block_status() from file-posix.c.)
1467 static int coroutine_fn
qemu_gluster_co_block_status(BlockDriverState
*bs
,
1473 BlockDriverState
**file
)
1475 BDRVGlusterState
*s
= bs
->opaque
;
1476 off_t data
= 0, hole
= 0;
1487 return BDRV_BLOCK_DATA
| BDRV_BLOCK_OFFSET_VALID
;
1490 ret
= find_allocation(bs
, offset
, &data
, &hole
);
1491 if (ret
== -ENXIO
) {
1494 ret
= BDRV_BLOCK_ZERO
;
1495 } else if (ret
< 0) {
1496 /* No info available, so pretend there are no holes */
1498 ret
= BDRV_BLOCK_DATA
;
1499 } else if (data
== offset
) {
1500 /* On a data extent, compute bytes to the end of the extent,
1501 * possibly including a partial sector at EOF. */
1502 *pnum
= MIN(bytes
, hole
- offset
);
1503 ret
= BDRV_BLOCK_DATA
;
1505 /* On a hole, compute bytes to the beginning of the next extent. */
1506 assert(hole
== offset
);
1507 *pnum
= MIN(bytes
, data
- offset
);
1508 ret
= BDRV_BLOCK_ZERO
;
1514 return ret
| BDRV_BLOCK_OFFSET_VALID
;
1518 static const char *const gluster_strong_open_opts
[] = {
1522 GLUSTER_OPT_SERVER_PATTERN
,
1533 static BlockDriver bdrv_gluster
= {
1534 .format_name
= "gluster",
1535 .protocol_name
= "gluster",
1536 .instance_size
= sizeof(BDRVGlusterState
),
1537 .bdrv_needs_filename
= false,
1538 .bdrv_file_open
= qemu_gluster_open
,
1539 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1540 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1541 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1542 .bdrv_close
= qemu_gluster_close
,
1543 .bdrv_co_create
= qemu_gluster_co_create
,
1544 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1545 .bdrv_getlength
= qemu_gluster_getlength
,
1546 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1547 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1548 .bdrv_co_readv
= qemu_gluster_co_readv
,
1549 .bdrv_co_writev
= qemu_gluster_co_writev
,
1550 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1551 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1552 #ifdef CONFIG_GLUSTERFS_DISCARD
1553 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1555 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1556 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1558 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1559 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1560 .create_opts
= &qemu_gluster_create_opts
,
1561 .strong_runtime_opts
= gluster_strong_open_opts
,
1564 static BlockDriver bdrv_gluster_tcp
= {
1565 .format_name
= "gluster",
1566 .protocol_name
= "gluster+tcp",
1567 .instance_size
= sizeof(BDRVGlusterState
),
1568 .bdrv_needs_filename
= false,
1569 .bdrv_file_open
= qemu_gluster_open
,
1570 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1571 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1572 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1573 .bdrv_close
= qemu_gluster_close
,
1574 .bdrv_co_create
= qemu_gluster_co_create
,
1575 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1576 .bdrv_getlength
= qemu_gluster_getlength
,
1577 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1578 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1579 .bdrv_co_readv
= qemu_gluster_co_readv
,
1580 .bdrv_co_writev
= qemu_gluster_co_writev
,
1581 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1582 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1583 #ifdef CONFIG_GLUSTERFS_DISCARD
1584 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1586 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1587 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1589 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1590 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1591 .create_opts
= &qemu_gluster_create_opts
,
1592 .strong_runtime_opts
= gluster_strong_open_opts
,
1595 static BlockDriver bdrv_gluster_unix
= {
1596 .format_name
= "gluster",
1597 .protocol_name
= "gluster+unix",
1598 .instance_size
= sizeof(BDRVGlusterState
),
1599 .bdrv_needs_filename
= true,
1600 .bdrv_file_open
= qemu_gluster_open
,
1601 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1602 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1603 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1604 .bdrv_close
= qemu_gluster_close
,
1605 .bdrv_co_create
= qemu_gluster_co_create
,
1606 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1607 .bdrv_getlength
= qemu_gluster_getlength
,
1608 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1609 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1610 .bdrv_co_readv
= qemu_gluster_co_readv
,
1611 .bdrv_co_writev
= qemu_gluster_co_writev
,
1612 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1613 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1614 #ifdef CONFIG_GLUSTERFS_DISCARD
1615 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1617 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1618 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1620 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1621 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1622 .create_opts
= &qemu_gluster_create_opts
,
1623 .strong_runtime_opts
= gluster_strong_open_opts
,
1626 /* rdma is deprecated (actually never supported for volfile fetch).
1627 * Let's maintain it for the protocol compatibility, to make sure things
1628 * won't break immediately. For now, gluster+rdma will fall back to gluster+tcp
1629 * protocol with a warning.
1630 * TODO: remove gluster+rdma interface support
1632 static BlockDriver bdrv_gluster_rdma
= {
1633 .format_name
= "gluster",
1634 .protocol_name
= "gluster+rdma",
1635 .instance_size
= sizeof(BDRVGlusterState
),
1636 .bdrv_needs_filename
= true,
1637 .bdrv_file_open
= qemu_gluster_open
,
1638 .bdrv_reopen_prepare
= qemu_gluster_reopen_prepare
,
1639 .bdrv_reopen_commit
= qemu_gluster_reopen_commit
,
1640 .bdrv_reopen_abort
= qemu_gluster_reopen_abort
,
1641 .bdrv_close
= qemu_gluster_close
,
1642 .bdrv_co_create
= qemu_gluster_co_create
,
1643 .bdrv_co_create_opts
= qemu_gluster_co_create_opts
,
1644 .bdrv_getlength
= qemu_gluster_getlength
,
1645 .bdrv_get_allocated_file_size
= qemu_gluster_allocated_file_size
,
1646 .bdrv_co_truncate
= qemu_gluster_co_truncate
,
1647 .bdrv_co_readv
= qemu_gluster_co_readv
,
1648 .bdrv_co_writev
= qemu_gluster_co_writev
,
1649 .bdrv_co_flush_to_disk
= qemu_gluster_co_flush_to_disk
,
1650 .bdrv_has_zero_init
= qemu_gluster_has_zero_init
,
1651 #ifdef CONFIG_GLUSTERFS_DISCARD
1652 .bdrv_co_pdiscard
= qemu_gluster_co_pdiscard
,
1654 #ifdef CONFIG_GLUSTERFS_ZEROFILL
1655 .bdrv_co_pwrite_zeroes
= qemu_gluster_co_pwrite_zeroes
,
1657 .bdrv_co_block_status
= qemu_gluster_co_block_status
,
1658 .bdrv_refresh_limits
= qemu_gluster_refresh_limits
,
1659 .create_opts
= &qemu_gluster_create_opts
,
1660 .strong_runtime_opts
= gluster_strong_open_opts
,
1663 static void bdrv_gluster_init(void)
1665 bdrv_register(&bdrv_gluster_rdma
);
1666 bdrv_register(&bdrv_gluster_unix
);
1667 bdrv_register(&bdrv_gluster_tcp
);
1668 bdrv_register(&bdrv_gluster
);
1671 block_init(bdrv_gluster_init
);