2 * QEMU Block driver for RADOS (Ceph)
4 * Copyright (C) 2010-2011 Christian Brunner <chb@muc.de>,
5 * Josh Durgin <josh.durgin@dreamhost.com>
7 * This work is licensed under the terms of the GNU GPL, version 2. See
8 * the COPYING file in the top-level directory.
10 * Contributions after 2012-01-13 are licensed under the terms of the
11 * GNU GPL, version 2 or (at your option) any later version.
14 #include "qemu/osdep.h"
16 #include <rbd/librbd.h>
17 #include "qapi/error.h"
18 #include "qemu/error-report.h"
19 #include "block/block_int.h"
20 #include "crypto/secret.h"
21 #include "qemu/cutils.h"
22 #include "qapi/qmp/qstring.h"
25 * When specifying the image filename use:
27 * rbd:poolname/devicename[@snapshotname][:option1=value1[:option2=value2...]]
29 * poolname must be the name of an existing rados pool.
31 * devicename is the name of the rbd image.
33 * Each option given is used to configure rados, and may be any valid
34 * Ceph option, "id", or "conf".
36 * The "id" option indicates what user we should authenticate as to
37 * the Ceph cluster. If it is excluded we will use the Ceph default
40 * The "conf" option specifies a Ceph configuration file to read. If
41 * it is not specified, we will read from the default Ceph locations
42 * (e.g., /etc/ceph/ceph.conf). To avoid reading _any_ configuration
43 * file, specify conf=/dev/null.
45 * Configuration values containing :, @, or = can be escaped with a
49 /* rbd_aio_discard added in 0.1.2 */
50 #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 2)
51 #define LIBRBD_SUPPORTS_DISCARD
53 #undef LIBRBD_SUPPORTS_DISCARD
56 #define OBJ_MAX_SIZE (1UL << OBJ_DEFAULT_OBJ_ORDER)
58 #define RBD_MAX_SNAPS 100
60 /* The LIBRBD_SUPPORTS_IOVEC is defined in librbd.h */
61 #ifdef LIBRBD_SUPPORTS_IOVEC
62 #define LIBRBD_USE_IOVEC 1
64 #define LIBRBD_USE_IOVEC 0
74 typedef struct RBDAIOCB
{
81 struct BDRVRBDState
*s
;
84 typedef struct RADOSCB
{
86 struct BDRVRBDState
*s
;
92 typedef struct BDRVRBDState
{
100 static char *qemu_rbd_next_tok(char *src
, char delim
, char **p
)
106 for (end
= src
; *end
; ++end
) {
110 if (*end
== '\\' && end
[1] != '\0') {
121 static void qemu_rbd_unescape(char *src
)
125 for (p
= src
; *src
; ++src
, ++p
) {
126 if (*src
== '\\' && src
[1] != '\0') {
134 static void qemu_rbd_parse_filename(const char *filename
, QDict
*options
,
138 char *p
, *buf
, *keypairs
;
140 size_t max_keypair_size
;
142 if (!strstart(filename
, "rbd:", &start
)) {
143 error_setg(errp
, "File name must start with 'rbd:'");
147 max_keypair_size
= strlen(start
) + 1;
148 buf
= g_strdup(start
);
149 keypairs
= g_malloc0(max_keypair_size
);
152 found_str
= qemu_rbd_next_tok(p
, '/', &p
);
154 error_setg(errp
, "Pool name is required");
157 qemu_rbd_unescape(found_str
);
158 qdict_put(options
, "pool", qstring_from_str(found_str
));
160 if (strchr(p
, '@')) {
161 found_str
= qemu_rbd_next_tok(p
, '@', &p
);
162 qemu_rbd_unescape(found_str
);
163 qdict_put(options
, "image", qstring_from_str(found_str
));
165 found_str
= qemu_rbd_next_tok(p
, ':', &p
);
166 qemu_rbd_unescape(found_str
);
167 qdict_put(options
, "snapshot", qstring_from_str(found_str
));
169 found_str
= qemu_rbd_next_tok(p
, ':', &p
);
170 qemu_rbd_unescape(found_str
);
171 qdict_put(options
, "image", qstring_from_str(found_str
));
177 /* The following are essentially all key/value pairs, and we treat
178 * 'id' and 'conf' a bit special. Key/value pairs may be in any order. */
181 name
= qemu_rbd_next_tok(p
, '=', &p
);
183 error_setg(errp
, "conf option %s has no value", name
);
187 qemu_rbd_unescape(name
);
189 value
= qemu_rbd_next_tok(p
, ':', &p
);
190 qemu_rbd_unescape(value
);
192 if (!strcmp(name
, "conf")) {
193 qdict_put(options
, "conf", qstring_from_str(value
));
194 } else if (!strcmp(name
, "id")) {
195 qdict_put(options
, "user" , qstring_from_str(value
));
197 /* FIXME: This is pretty ugly, and not the right way to do this.
198 * These should be contained in a structure, and then
199 * passed explicitly as individual key/value pairs to
200 * rados. Consider this legacy code that needs to be
202 char *tmp
= g_malloc0(max_keypair_size
);
203 /* only use a delimiter if it is not the first keypair found */
204 /* These are sets of unknown key/value pairs we'll pass along
207 snprintf(tmp
, max_keypair_size
, ":%s=%s", name
, value
);
208 pstrcat(keypairs
, max_keypair_size
, tmp
);
210 snprintf(keypairs
, max_keypair_size
, "%s=%s", name
, value
);
217 qdict_put(options
, "=keyvalue-pairs", qstring_from_str(keypairs
));
228 static int qemu_rbd_set_auth(rados_t cluster
, const char *secretid
,
235 gchar
*secret
= qcrypto_secret_lookup_as_base64(secretid
,
241 rados_conf_set(cluster
, "key", secret
);
247 static int qemu_rbd_set_keypairs(rados_t cluster
, const char *keypairs
,
255 buf
= g_strdup(keypairs
);
259 name
= qemu_rbd_next_tok(p
, '=', &p
);
261 error_setg(errp
, "conf option %s has no value", name
);
266 value
= qemu_rbd_next_tok(p
, ':', &p
);
268 ret
= rados_conf_set(cluster
, name
, value
);
270 error_setg_errno(errp
, -ret
, "invalid conf option %s", name
);
280 static void qemu_rbd_memset(RADOSCB
*rcb
, int64_t offs
)
282 if (LIBRBD_USE_IOVEC
) {
283 RBDAIOCB
*acb
= rcb
->acb
;
284 iov_memset(acb
->qiov
->iov
, acb
->qiov
->niov
, offs
, 0,
285 acb
->qiov
->size
- offs
);
287 memset(rcb
->buf
+ offs
, 0, rcb
->size
- offs
);
291 static QemuOptsList runtime_opts
= {
293 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
297 .type
= QEMU_OPT_STRING
,
298 .help
= "Rados pool name",
302 .type
= QEMU_OPT_STRING
,
303 .help
= "Image name in the pool",
307 .type
= QEMU_OPT_STRING
,
308 .help
= "Rados config file location",
312 .type
= QEMU_OPT_STRING
,
313 .help
= "Ceph snapshot name",
316 /* maps to 'id' in rados_create() */
318 .type
= QEMU_OPT_STRING
,
319 .help
= "Rados id name",
322 * server.* extracted manually, see qemu_rbd_mon_host()
325 .name
= "password-secret",
326 .type
= QEMU_OPT_STRING
,
327 .help
= "ID of secret providing the password",
331 * Keys for qemu_rbd_parse_filename(), not in the QAPI schema
335 * HACK: name starts with '=' so that qemu_opts_parse()
338 .name
= "=keyvalue-pairs",
339 .type
= QEMU_OPT_STRING
,
340 .help
= "Legacy rados key/value option parameters",
342 { /* end of list */ }
346 static int qemu_rbd_create(const char *filename
, QemuOpts
*opts
, Error
**errp
)
348 Error
*local_err
= NULL
;
352 const char *pool
, *name
, *conf
, *clientname
, *keypairs
;
353 const char *secretid
;
355 rados_ioctx_t io_ctx
;
356 QDict
*options
= NULL
;
359 secretid
= qemu_opt_get(opts
, "password-secret");
361 /* Read out options */
362 bytes
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
364 objsize
= qemu_opt_get_size_del(opts
, BLOCK_OPT_CLUSTER_SIZE
, 0);
366 if ((objsize
- 1) & objsize
) { /* not a power of 2? */
367 error_setg(errp
, "obj size needs to be power of 2");
371 if (objsize
< 4096) {
372 error_setg(errp
, "obj size too small");
376 obj_order
= ctz32(objsize
);
379 options
= qdict_new();
380 qemu_rbd_parse_filename(filename
, options
, &local_err
);
383 error_propagate(errp
, local_err
);
387 pool
= qdict_get_try_str(options
, "pool");
388 conf
= qdict_get_try_str(options
, "conf");
389 clientname
= qdict_get_try_str(options
, "user");
390 name
= qdict_get_try_str(options
, "image");
391 keypairs
= qdict_get_try_str(options
, "=keyvalue-pairs");
393 ret
= rados_create(&cluster
, clientname
);
395 error_setg_errno(errp
, -ret
, "error initializing");
399 /* try default location when conf=NULL, but ignore failure */
400 ret
= rados_conf_read_file(cluster
, conf
);
401 if (conf
&& ret
< 0) {
402 error_setg_errno(errp
, -ret
, "error reading conf file %s", conf
);
407 ret
= qemu_rbd_set_keypairs(cluster
, keypairs
, errp
);
413 if (qemu_rbd_set_auth(cluster
, secretid
, errp
) < 0) {
418 ret
= rados_connect(cluster
);
420 error_setg_errno(errp
, -ret
, "error connecting");
424 ret
= rados_ioctx_create(cluster
, pool
, &io_ctx
);
426 error_setg_errno(errp
, -ret
, "error opening pool %s", pool
);
430 ret
= rbd_create(io_ctx
, name
, bytes
, &obj_order
);
432 error_setg_errno(errp
, -ret
, "error rbd create");
435 rados_ioctx_destroy(io_ctx
);
438 rados_shutdown(cluster
);
446 * This aio completion is being called from rbd_finish_bh() and runs in qemu
449 static void qemu_rbd_complete_aio(RADOSCB
*rcb
)
451 RBDAIOCB
*acb
= rcb
->acb
;
456 if (acb
->cmd
!= RBD_AIO_READ
) {
460 } else if (!acb
->error
) {
461 acb
->ret
= rcb
->size
;
465 qemu_rbd_memset(rcb
, 0);
468 } else if (r
< rcb
->size
) {
469 qemu_rbd_memset(rcb
, r
);
471 acb
->ret
= rcb
->size
;
473 } else if (!acb
->error
) {
480 if (!LIBRBD_USE_IOVEC
) {
481 if (acb
->cmd
== RBD_AIO_READ
) {
482 qemu_iovec_from_buf(acb
->qiov
, 0, acb
->bounce
, acb
->qiov
->size
);
484 qemu_vfree(acb
->bounce
);
487 acb
->common
.cb(acb
->common
.opaque
, (acb
->ret
> 0 ? 0 : acb
->ret
));
492 static char *qemu_rbd_mon_host(QDict
*options
, Error
**errp
)
494 const char **vals
= g_new(const char *, qdict_size(options
) + 1);
496 const char *host
, *port
;
501 sprintf(keybuf
, "server.%d.host", i
);
502 host
= qdict_get_try_str(options
, keybuf
);
503 qdict_del(options
, keybuf
);
504 sprintf(keybuf
, "server.%d.port", i
);
505 port
= qdict_get_try_str(options
, keybuf
);
506 qdict_del(options
, keybuf
);
507 if (!host
&& !port
) {
511 error_setg(errp
, "Parameter server.%d.host is missing", i
);
516 if (strchr(host
, ':')) {
517 vals
[i
] = port
? g_strdup_printf("[%s]:%s", host
, port
)
518 : g_strdup_printf("[%s]", host
);
520 vals
[i
] = port
? g_strdup_printf("%s:%s", host
, port
)
526 rados_str
= i
? g_strjoinv(";", (char **)vals
) : NULL
;
528 g_strfreev((char **)vals
);
532 static int qemu_rbd_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
535 BDRVRBDState
*s
= bs
->opaque
;
536 const char *pool
, *snap
, *conf
, *clientname
, *name
, *keypairs
;
537 const char *secretid
;
539 Error
*local_err
= NULL
;
540 char *mon_host
= NULL
;
543 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
544 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
546 error_propagate(errp
, local_err
);
551 mon_host
= qemu_rbd_mon_host(options
, &local_err
);
553 error_propagate(errp
, local_err
);
558 secretid
= qemu_opt_get(opts
, "password-secret");
560 pool
= qemu_opt_get(opts
, "pool");
561 conf
= qemu_opt_get(opts
, "conf");
562 snap
= qemu_opt_get(opts
, "snapshot");
563 clientname
= qemu_opt_get(opts
, "user");
564 name
= qemu_opt_get(opts
, "image");
565 keypairs
= qemu_opt_get(opts
, "=keyvalue-pairs");
567 if (!pool
|| !name
) {
568 error_setg(errp
, "Parameters 'pool' and 'image' are required");
573 r
= rados_create(&s
->cluster
, clientname
);
575 error_setg_errno(errp
, -r
, "error initializing");
579 s
->snap
= g_strdup(snap
);
580 s
->name
= g_strdup(name
);
582 /* try default location when conf=NULL, but ignore failure */
583 r
= rados_conf_read_file(s
->cluster
, conf
);
585 error_setg_errno(errp
, -r
, "error reading conf file %s", conf
);
586 goto failed_shutdown
;
589 r
= qemu_rbd_set_keypairs(s
->cluster
, keypairs
, errp
);
591 goto failed_shutdown
;
595 r
= rados_conf_set(s
->cluster
, "mon_host", mon_host
);
597 goto failed_shutdown
;
601 if (qemu_rbd_set_auth(s
->cluster
, secretid
, errp
) < 0) {
603 goto failed_shutdown
;
607 * Fallback to more conservative semantics if setting cache
608 * options fails. Ignore errors from setting rbd_cache because the
609 * only possible error is that the option does not exist, and
610 * librbd defaults to no caching. If write through caching cannot
611 * be set up, fall back to no caching.
613 if (flags
& BDRV_O_NOCACHE
) {
614 rados_conf_set(s
->cluster
, "rbd_cache", "false");
616 rados_conf_set(s
->cluster
, "rbd_cache", "true");
619 r
= rados_connect(s
->cluster
);
621 error_setg_errno(errp
, -r
, "error connecting");
622 goto failed_shutdown
;
625 r
= rados_ioctx_create(s
->cluster
, pool
, &s
->io_ctx
);
627 error_setg_errno(errp
, -r
, "error opening pool %s", pool
);
628 goto failed_shutdown
;
631 r
= rbd_open(s
->io_ctx
, s
->name
, &s
->image
, s
->snap
);
633 error_setg_errno(errp
, -r
, "error reading header from %s", s
->name
);
637 bs
->read_only
= (s
->snap
!= NULL
);
643 rados_ioctx_destroy(s
->io_ctx
);
645 rados_shutdown(s
->cluster
);
654 static void qemu_rbd_close(BlockDriverState
*bs
)
656 BDRVRBDState
*s
= bs
->opaque
;
659 rados_ioctx_destroy(s
->io_ctx
);
662 rados_shutdown(s
->cluster
);
665 static const AIOCBInfo rbd_aiocb_info
= {
666 .aiocb_size
= sizeof(RBDAIOCB
),
669 static void rbd_finish_bh(void *opaque
)
671 RADOSCB
*rcb
= opaque
;
672 qemu_rbd_complete_aio(rcb
);
676 * This is the callback function for rbd_aio_read and _write
678 * Note: this function is being called from a non qemu thread so
679 * we need to be careful about what we do here. Generally we only
680 * schedule a BH, and do the rest of the io completion handling
681 * from rbd_finish_bh() which runs in a qemu context.
683 static void rbd_finish_aiocb(rbd_completion_t c
, RADOSCB
*rcb
)
685 RBDAIOCB
*acb
= rcb
->acb
;
687 rcb
->ret
= rbd_aio_get_return_value(c
);
690 aio_bh_schedule_oneshot(bdrv_get_aio_context(acb
->common
.bs
),
694 static int rbd_aio_discard_wrapper(rbd_image_t image
,
697 rbd_completion_t comp
)
699 #ifdef LIBRBD_SUPPORTS_DISCARD
700 return rbd_aio_discard(image
, off
, len
, comp
);
706 static int rbd_aio_flush_wrapper(rbd_image_t image
,
707 rbd_completion_t comp
)
709 #ifdef LIBRBD_SUPPORTS_AIO_FLUSH
710 return rbd_aio_flush(image
, comp
);
716 static BlockAIOCB
*rbd_start_aio(BlockDriverState
*bs
,
720 BlockCompletionFunc
*cb
,
729 BDRVRBDState
*s
= bs
->opaque
;
731 acb
= qemu_aio_get(&rbd_aiocb_info
, bs
, cb
, opaque
);
734 assert(!qiov
|| qiov
->size
== size
);
736 rcb
= g_new(RADOSCB
, 1);
738 if (!LIBRBD_USE_IOVEC
) {
739 if (cmd
== RBD_AIO_DISCARD
|| cmd
== RBD_AIO_FLUSH
) {
742 acb
->bounce
= qemu_try_blockalign(bs
, qiov
->size
);
743 if (acb
->bounce
== NULL
) {
747 if (cmd
== RBD_AIO_WRITE
) {
748 qemu_iovec_to_buf(acb
->qiov
, 0, acb
->bounce
, qiov
->size
);
750 rcb
->buf
= acb
->bounce
;
760 r
= rbd_aio_create_completion(rcb
, (rbd_callback_t
) rbd_finish_aiocb
, &c
);
767 #ifdef LIBRBD_SUPPORTS_IOVEC
768 r
= rbd_aio_writev(s
->image
, qiov
->iov
, qiov
->niov
, off
, c
);
770 r
= rbd_aio_write(s
->image
, off
, size
, rcb
->buf
, c
);
774 #ifdef LIBRBD_SUPPORTS_IOVEC
775 r
= rbd_aio_readv(s
->image
, qiov
->iov
, qiov
->niov
, off
, c
);
777 r
= rbd_aio_read(s
->image
, off
, size
, rcb
->buf
, c
);
780 case RBD_AIO_DISCARD
:
781 r
= rbd_aio_discard_wrapper(s
->image
, off
, size
, c
);
784 r
= rbd_aio_flush_wrapper(s
->image
, c
);
791 goto failed_completion
;
799 if (!LIBRBD_USE_IOVEC
) {
800 qemu_vfree(acb
->bounce
);
807 static BlockAIOCB
*qemu_rbd_aio_readv(BlockDriverState
*bs
,
811 BlockCompletionFunc
*cb
,
814 return rbd_start_aio(bs
, sector_num
<< BDRV_SECTOR_BITS
, qiov
,
815 (int64_t) nb_sectors
<< BDRV_SECTOR_BITS
, cb
, opaque
,
819 static BlockAIOCB
*qemu_rbd_aio_writev(BlockDriverState
*bs
,
823 BlockCompletionFunc
*cb
,
826 return rbd_start_aio(bs
, sector_num
<< BDRV_SECTOR_BITS
, qiov
,
827 (int64_t) nb_sectors
<< BDRV_SECTOR_BITS
, cb
, opaque
,
831 #ifdef LIBRBD_SUPPORTS_AIO_FLUSH
832 static BlockAIOCB
*qemu_rbd_aio_flush(BlockDriverState
*bs
,
833 BlockCompletionFunc
*cb
,
836 return rbd_start_aio(bs
, 0, NULL
, 0, cb
, opaque
, RBD_AIO_FLUSH
);
841 static int qemu_rbd_co_flush(BlockDriverState
*bs
)
843 #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 1)
844 /* rbd_flush added in 0.1.1 */
845 BDRVRBDState
*s
= bs
->opaque
;
846 return rbd_flush(s
->image
);
853 static int qemu_rbd_getinfo(BlockDriverState
*bs
, BlockDriverInfo
*bdi
)
855 BDRVRBDState
*s
= bs
->opaque
;
856 rbd_image_info_t info
;
859 r
= rbd_stat(s
->image
, &info
, sizeof(info
));
864 bdi
->cluster_size
= info
.obj_size
;
868 static int64_t qemu_rbd_getlength(BlockDriverState
*bs
)
870 BDRVRBDState
*s
= bs
->opaque
;
871 rbd_image_info_t info
;
874 r
= rbd_stat(s
->image
, &info
, sizeof(info
));
882 static int qemu_rbd_truncate(BlockDriverState
*bs
, int64_t offset
)
884 BDRVRBDState
*s
= bs
->opaque
;
887 r
= rbd_resize(s
->image
, offset
);
895 static int qemu_rbd_snap_create(BlockDriverState
*bs
,
896 QEMUSnapshotInfo
*sn_info
)
898 BDRVRBDState
*s
= bs
->opaque
;
901 if (sn_info
->name
[0] == '\0') {
902 return -EINVAL
; /* we need a name for rbd snapshots */
906 * rbd snapshots are using the name as the user controlled unique identifier
907 * we can't use the rbd snapid for that purpose, as it can't be set
909 if (sn_info
->id_str
[0] != '\0' &&
910 strcmp(sn_info
->id_str
, sn_info
->name
) != 0) {
914 if (strlen(sn_info
->name
) >= sizeof(sn_info
->id_str
)) {
918 r
= rbd_snap_create(s
->image
, sn_info
->name
);
920 error_report("failed to create snap: %s", strerror(-r
));
927 static int qemu_rbd_snap_remove(BlockDriverState
*bs
,
928 const char *snapshot_id
,
929 const char *snapshot_name
,
932 BDRVRBDState
*s
= bs
->opaque
;
935 if (!snapshot_name
) {
936 error_setg(errp
, "rbd need a valid snapshot name");
940 /* If snapshot_id is specified, it must be equal to name, see
941 qemu_rbd_snap_list() */
942 if (snapshot_id
&& strcmp(snapshot_id
, snapshot_name
)) {
944 "rbd do not support snapshot id, it should be NULL or "
945 "equal to snapshot name");
949 r
= rbd_snap_remove(s
->image
, snapshot_name
);
951 error_setg_errno(errp
, -r
, "Failed to remove the snapshot");
956 static int qemu_rbd_snap_rollback(BlockDriverState
*bs
,
957 const char *snapshot_name
)
959 BDRVRBDState
*s
= bs
->opaque
;
961 return rbd_snap_rollback(s
->image
, snapshot_name
);
964 static int qemu_rbd_snap_list(BlockDriverState
*bs
,
965 QEMUSnapshotInfo
**psn_tab
)
967 BDRVRBDState
*s
= bs
->opaque
;
968 QEMUSnapshotInfo
*sn_info
, *sn_tab
= NULL
;
970 rbd_snap_info_t
*snaps
;
971 int max_snaps
= RBD_MAX_SNAPS
;
974 snaps
= g_new(rbd_snap_info_t
, max_snaps
);
975 snap_count
= rbd_snap_list(s
->image
, snaps
, &max_snaps
);
976 if (snap_count
<= 0) {
979 } while (snap_count
== -ERANGE
);
981 if (snap_count
<= 0) {
985 sn_tab
= g_new0(QEMUSnapshotInfo
, snap_count
);
987 for (i
= 0; i
< snap_count
; i
++) {
988 const char *snap_name
= snaps
[i
].name
;
990 sn_info
= sn_tab
+ i
;
991 pstrcpy(sn_info
->id_str
, sizeof(sn_info
->id_str
), snap_name
);
992 pstrcpy(sn_info
->name
, sizeof(sn_info
->name
), snap_name
);
994 sn_info
->vm_state_size
= snaps
[i
].size
;
995 sn_info
->date_sec
= 0;
996 sn_info
->date_nsec
= 0;
997 sn_info
->vm_clock_nsec
= 0;
999 rbd_snap_list_end(snaps
);
1007 #ifdef LIBRBD_SUPPORTS_DISCARD
1008 static BlockAIOCB
*qemu_rbd_aio_pdiscard(BlockDriverState
*bs
,
1011 BlockCompletionFunc
*cb
,
1014 return rbd_start_aio(bs
, offset
, NULL
, count
, cb
, opaque
,
1019 #ifdef LIBRBD_SUPPORTS_INVALIDATE
1020 static void qemu_rbd_invalidate_cache(BlockDriverState
*bs
,
1023 BDRVRBDState
*s
= bs
->opaque
;
1024 int r
= rbd_invalidate_cache(s
->image
);
1026 error_setg_errno(errp
, -r
, "Failed to invalidate the cache");
1031 static QemuOptsList qemu_rbd_create_opts
= {
1032 .name
= "rbd-create-opts",
1033 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts
.head
),
1036 .name
= BLOCK_OPT_SIZE
,
1037 .type
= QEMU_OPT_SIZE
,
1038 .help
= "Virtual disk size"
1041 .name
= BLOCK_OPT_CLUSTER_SIZE
,
1042 .type
= QEMU_OPT_SIZE
,
1043 .help
= "RBD object size"
1046 .name
= "password-secret",
1047 .type
= QEMU_OPT_STRING
,
1048 .help
= "ID of secret providing the password",
1050 { /* end of list */ }
1054 static BlockDriver bdrv_rbd
= {
1055 .format_name
= "rbd",
1056 .instance_size
= sizeof(BDRVRBDState
),
1057 .bdrv_parse_filename
= qemu_rbd_parse_filename
,
1058 .bdrv_file_open
= qemu_rbd_open
,
1059 .bdrv_close
= qemu_rbd_close
,
1060 .bdrv_create
= qemu_rbd_create
,
1061 .bdrv_has_zero_init
= bdrv_has_zero_init_1
,
1062 .bdrv_get_info
= qemu_rbd_getinfo
,
1063 .create_opts
= &qemu_rbd_create_opts
,
1064 .bdrv_getlength
= qemu_rbd_getlength
,
1065 .bdrv_truncate
= qemu_rbd_truncate
,
1066 .protocol_name
= "rbd",
1068 .bdrv_aio_readv
= qemu_rbd_aio_readv
,
1069 .bdrv_aio_writev
= qemu_rbd_aio_writev
,
1071 #ifdef LIBRBD_SUPPORTS_AIO_FLUSH
1072 .bdrv_aio_flush
= qemu_rbd_aio_flush
,
1074 .bdrv_co_flush_to_disk
= qemu_rbd_co_flush
,
1077 #ifdef LIBRBD_SUPPORTS_DISCARD
1078 .bdrv_aio_pdiscard
= qemu_rbd_aio_pdiscard
,
1081 .bdrv_snapshot_create
= qemu_rbd_snap_create
,
1082 .bdrv_snapshot_delete
= qemu_rbd_snap_remove
,
1083 .bdrv_snapshot_list
= qemu_rbd_snap_list
,
1084 .bdrv_snapshot_goto
= qemu_rbd_snap_rollback
,
1085 #ifdef LIBRBD_SUPPORTS_INVALIDATE
1086 .bdrv_invalidate_cache
= qemu_rbd_invalidate_cache
,
1090 static void bdrv_rbd_init(void)
1092 bdrv_register(&bdrv_rbd
);
1095 block_init(bdrv_rbd_init
);