1f27aaf4bSChristian Brunner /* 2f27aaf4bSChristian Brunner * QEMU Block driver for RADOS (Ceph) 3f27aaf4bSChristian Brunner * 4ad32e9c0SJosh Durgin * Copyright (C) 2010-2011 Christian Brunner <chb@muc.de>, 5ad32e9c0SJosh Durgin * Josh Durgin <josh.durgin@dreamhost.com> 6f27aaf4bSChristian Brunner * 7f27aaf4bSChristian Brunner * This work is licensed under the terms of the GNU GPL, version 2. See 8f27aaf4bSChristian Brunner * the COPYING file in the top-level directory. 9f27aaf4bSChristian Brunner * 106b620ca3SPaolo Bonzini * Contributions after 2012-01-13 are licensed under the terms of the 116b620ca3SPaolo Bonzini * GNU GPL, version 2 or (at your option) any later version. 12f27aaf4bSChristian Brunner */ 13f27aaf4bSChristian Brunner 1480c71a24SPeter Maydell #include "qemu/osdep.h" 15ad32e9c0SJosh Durgin 162836284dSMarkus Armbruster #include <rbd/librbd.h> 17da34e65cSMarkus Armbruster #include "qapi/error.h" 181de7afc9SPaolo Bonzini #include "qemu/error-report.h" 19737e150eSPaolo Bonzini #include "block/block_int.h" 2060390a21SDaniel P. Berrange #include "crypto/secret.h" 21f348b6d1SVeronia Bahaa #include "qemu/cutils.h" 22c7cacb3eSJeff Cody #include "qapi/qmp/qstring.h" 23e98c6961SEric Blake #include "qapi/qmp/qjson.h" 24f27aaf4bSChristian Brunner 25f27aaf4bSChristian Brunner /* 26f27aaf4bSChristian Brunner * When specifying the image filename use: 27f27aaf4bSChristian Brunner * 28fab5cf59SJosh Durgin * rbd:poolname/devicename[@snapshotname][:option1=value1[:option2=value2...]] 29f27aaf4bSChristian Brunner * 309e1fbcdeSSage Weil * poolname must be the name of an existing rados pool. 31f27aaf4bSChristian Brunner * 329e1fbcdeSSage Weil * devicename is the name of the rbd image. 33f27aaf4bSChristian Brunner * 349e1fbcdeSSage Weil * Each option given is used to configure rados, and may be any valid 359e1fbcdeSSage Weil * Ceph option, "id", or "conf". 36fab5cf59SJosh Durgin * 379e1fbcdeSSage Weil * The "id" option indicates what user we should authenticate as to 389e1fbcdeSSage Weil * the Ceph cluster. If it is excluded we will use the Ceph default 399e1fbcdeSSage Weil * (normally 'admin'). 40f27aaf4bSChristian Brunner * 419e1fbcdeSSage Weil * The "conf" option specifies a Ceph configuration file to read. If 429e1fbcdeSSage Weil * it is not specified, we will read from the default Ceph locations 439e1fbcdeSSage Weil * (e.g., /etc/ceph/ceph.conf). To avoid reading _any_ configuration 449e1fbcdeSSage Weil * file, specify conf=/dev/null. 45f27aaf4bSChristian Brunner * 469e1fbcdeSSage Weil * Configuration values containing :, @, or = can be escaped with a 479e1fbcdeSSage Weil * leading "\". 48f27aaf4bSChristian Brunner */ 49f27aaf4bSChristian Brunner 50787f3133SJosh Durgin /* rbd_aio_discard added in 0.1.2 */ 51787f3133SJosh Durgin #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 2) 52787f3133SJosh Durgin #define LIBRBD_SUPPORTS_DISCARD 53787f3133SJosh Durgin #else 54787f3133SJosh Durgin #undef LIBRBD_SUPPORTS_DISCARD 55787f3133SJosh Durgin #endif 56787f3133SJosh Durgin 57f27aaf4bSChristian Brunner #define OBJ_MAX_SIZE (1UL << OBJ_DEFAULT_OBJ_ORDER) 58f27aaf4bSChristian Brunner 59ad32e9c0SJosh Durgin #define RBD_MAX_SNAPS 100 60ad32e9c0SJosh Durgin 611d393bdeStianqing /* The LIBRBD_SUPPORTS_IOVEC is defined in librbd.h */ 621d393bdeStianqing #ifdef LIBRBD_SUPPORTS_IOVEC 631d393bdeStianqing #define LIBRBD_USE_IOVEC 1 641d393bdeStianqing #else 651d393bdeStianqing #define LIBRBD_USE_IOVEC 0 661d393bdeStianqing #endif 671d393bdeStianqing 68787f3133SJosh Durgin typedef enum { 69787f3133SJosh Durgin RBD_AIO_READ, 70787f3133SJosh Durgin RBD_AIO_WRITE, 71dc7588c1SJosh Durgin RBD_AIO_DISCARD, 72dc7588c1SJosh Durgin RBD_AIO_FLUSH 73787f3133SJosh Durgin } RBDAIOCmd; 74787f3133SJosh Durgin 75f27aaf4bSChristian Brunner typedef struct RBDAIOCB { 767c84b1b8SMarkus Armbruster BlockAIOCB common; 7708448d51SStefan Priebe int64_t ret; 78f27aaf4bSChristian Brunner QEMUIOVector *qiov; 79f27aaf4bSChristian Brunner char *bounce; 80787f3133SJosh Durgin RBDAIOCmd cmd; 81f27aaf4bSChristian Brunner int error; 82f27aaf4bSChristian Brunner struct BDRVRBDState *s; 83f27aaf4bSChristian Brunner } RBDAIOCB; 84f27aaf4bSChristian Brunner 85f27aaf4bSChristian Brunner typedef struct RADOSCB { 86f27aaf4bSChristian Brunner RBDAIOCB *acb; 87f27aaf4bSChristian Brunner struct BDRVRBDState *s; 88ad32e9c0SJosh Durgin int64_t size; 89f27aaf4bSChristian Brunner char *buf; 9008448d51SStefan Priebe int64_t ret; 91f27aaf4bSChristian Brunner } RADOSCB; 92f27aaf4bSChristian Brunner 93f27aaf4bSChristian Brunner typedef struct BDRVRBDState { 94ad32e9c0SJosh Durgin rados_t cluster; 95ad32e9c0SJosh Durgin rados_ioctx_t io_ctx; 96ad32e9c0SJosh Durgin rbd_image_t image; 9780b61a27SJeff Cody char *image_name; 98ad32e9c0SJosh Durgin char *snap; 99f27aaf4bSChristian Brunner } BDRVRBDState; 100f27aaf4bSChristian Brunner 101730b00bbSMarkus Armbruster static char *qemu_rbd_next_tok(char *src, char delim, char **p) 102f27aaf4bSChristian Brunner { 103f27aaf4bSChristian Brunner char *end; 104f27aaf4bSChristian Brunner 105f27aaf4bSChristian Brunner *p = NULL; 106f27aaf4bSChristian Brunner 10716a06b24SSage Weil for (end = src; *end; ++end) { 10816a06b24SSage Weil if (*end == delim) { 10916a06b24SSage Weil break; 11016a06b24SSage Weil } 11116a06b24SSage Weil if (*end == '\\' && end[1] != '\0') { 11216a06b24SSage Weil end++; 11316a06b24SSage Weil } 11416a06b24SSage Weil } 11516a06b24SSage Weil if (*end == delim) { 116f27aaf4bSChristian Brunner *p = end + 1; 117f27aaf4bSChristian Brunner *end = '\0'; 118f27aaf4bSChristian Brunner } 1197830f909SJeff Cody return src; 120f27aaf4bSChristian Brunner } 121f27aaf4bSChristian Brunner 12216a06b24SSage Weil static void qemu_rbd_unescape(char *src) 12316a06b24SSage Weil { 12416a06b24SSage Weil char *p; 12516a06b24SSage Weil 12616a06b24SSage Weil for (p = src; *src; ++src, ++p) { 12716a06b24SSage Weil if (*src == '\\' && src[1] != '\0') { 12816a06b24SSage Weil src++; 12916a06b24SSage Weil } 13016a06b24SSage Weil *p = *src; 13116a06b24SSage Weil } 13216a06b24SSage Weil *p = '\0'; 13316a06b24SSage Weil } 13416a06b24SSage Weil 135c7cacb3eSJeff Cody static void qemu_rbd_parse_filename(const char *filename, QDict *options, 136d61563b2SMarkus Armbruster Error **errp) 137f27aaf4bSChristian Brunner { 138f27aaf4bSChristian Brunner const char *start; 139e98c6961SEric Blake char *p, *buf; 140e98c6961SEric Blake QList *keypairs = NULL; 1417830f909SJeff Cody char *found_str; 142f27aaf4bSChristian Brunner 143f27aaf4bSChristian Brunner if (!strstart(filename, "rbd:", &start)) { 144d61563b2SMarkus Armbruster error_setg(errp, "File name must start with 'rbd:'"); 145c7cacb3eSJeff Cody return; 146f27aaf4bSChristian Brunner } 147f27aaf4bSChristian Brunner 1487267c094SAnthony Liguori buf = g_strdup(start); 149f27aaf4bSChristian Brunner p = buf; 150f27aaf4bSChristian Brunner 151730b00bbSMarkus Armbruster found_str = qemu_rbd_next_tok(p, '/', &p); 1527830f909SJeff Cody if (!p) { 1537830f909SJeff Cody error_setg(errp, "Pool name is required"); 1547830f909SJeff Cody goto done; 1557830f909SJeff Cody } 1567830f909SJeff Cody qemu_rbd_unescape(found_str); 15746f5ac20SEric Blake qdict_put_str(options, "pool", found_str); 158fab5cf59SJosh Durgin 159fab5cf59SJosh Durgin if (strchr(p, '@')) { 160730b00bbSMarkus Armbruster found_str = qemu_rbd_next_tok(p, '@', &p); 1617830f909SJeff Cody qemu_rbd_unescape(found_str); 16246f5ac20SEric Blake qdict_put_str(options, "image", found_str); 1637830f909SJeff Cody 164730b00bbSMarkus Armbruster found_str = qemu_rbd_next_tok(p, ':', &p); 1657830f909SJeff Cody qemu_rbd_unescape(found_str); 16646f5ac20SEric Blake qdict_put_str(options, "snapshot", found_str); 1677830f909SJeff Cody } else { 168730b00bbSMarkus Armbruster found_str = qemu_rbd_next_tok(p, ':', &p); 1697830f909SJeff Cody qemu_rbd_unescape(found_str); 17046f5ac20SEric Blake qdict_put_str(options, "image", found_str); 1717830f909SJeff Cody } 1727830f909SJeff Cody if (!p) { 173f27aaf4bSChristian Brunner goto done; 174f27aaf4bSChristian Brunner } 175f27aaf4bSChristian Brunner 176c7cacb3eSJeff Cody /* The following are essentially all key/value pairs, and we treat 177c7cacb3eSJeff Cody * 'id' and 'conf' a bit special. Key/value pairs may be in any order. */ 178c7cacb3eSJeff Cody while (p) { 179c7cacb3eSJeff Cody char *name, *value; 180730b00bbSMarkus Armbruster name = qemu_rbd_next_tok(p, '=', &p); 181c7cacb3eSJeff Cody if (!p) { 182c7cacb3eSJeff Cody error_setg(errp, "conf option %s has no value", name); 183c7cacb3eSJeff Cody break; 184c7cacb3eSJeff Cody } 185c7cacb3eSJeff Cody 186c7cacb3eSJeff Cody qemu_rbd_unescape(name); 187c7cacb3eSJeff Cody 188730b00bbSMarkus Armbruster value = qemu_rbd_next_tok(p, ':', &p); 189c7cacb3eSJeff Cody qemu_rbd_unescape(value); 190c7cacb3eSJeff Cody 191c7cacb3eSJeff Cody if (!strcmp(name, "conf")) { 19246f5ac20SEric Blake qdict_put_str(options, "conf", value); 193c7cacb3eSJeff Cody } else if (!strcmp(name, "id")) { 19446f5ac20SEric Blake qdict_put_str(options, "user", value); 195c7cacb3eSJeff Cody } else { 196e98c6961SEric Blake /* 197e98c6961SEric Blake * We pass these internally to qemu_rbd_set_keypairs(), so 198e98c6961SEric Blake * we can get away with the simpler list of [ "key1", 199e98c6961SEric Blake * "value1", "key2", "value2" ] rather than a raw dict 200e98c6961SEric Blake * { "key1": "value1", "key2": "value2" } where we can't 201e98c6961SEric Blake * guarantee order, or even a more correct but complex 202e98c6961SEric Blake * [ { "key1": "value1" }, { "key2": "value2" } ] 203e98c6961SEric Blake */ 204e98c6961SEric Blake if (!keypairs) { 205e98c6961SEric Blake keypairs = qlist_new(); 206c7cacb3eSJeff Cody } 20746f5ac20SEric Blake qlist_append_str(keypairs, name); 20846f5ac20SEric Blake qlist_append_str(keypairs, value); 209c7cacb3eSJeff Cody } 210c7cacb3eSJeff Cody } 211c7cacb3eSJeff Cody 212e98c6961SEric Blake if (keypairs) { 213e98c6961SEric Blake qdict_put(options, "=keyvalue-pairs", 214e98c6961SEric Blake qobject_to_json(QOBJECT(keypairs))); 215c7cacb3eSJeff Cody } 216c7cacb3eSJeff Cody 217f27aaf4bSChristian Brunner done: 2187267c094SAnthony Liguori g_free(buf); 219e98c6961SEric Blake QDECREF(keypairs); 220c7cacb3eSJeff Cody return; 2217c7e9df0SSage Weil } 2227c7e9df0SSage Weil 22360390a21SDaniel P. Berrange 22460390a21SDaniel P. Berrange static int qemu_rbd_set_auth(rados_t cluster, const char *secretid, 22560390a21SDaniel P. Berrange Error **errp) 22660390a21SDaniel P. Berrange { 22760390a21SDaniel P. Berrange if (secretid == 0) { 22860390a21SDaniel P. Berrange return 0; 22960390a21SDaniel P. Berrange } 23060390a21SDaniel P. Berrange 23160390a21SDaniel P. Berrange gchar *secret = qcrypto_secret_lookup_as_base64(secretid, 23260390a21SDaniel P. Berrange errp); 23360390a21SDaniel P. Berrange if (!secret) { 23460390a21SDaniel P. Berrange return -1; 23560390a21SDaniel P. Berrange } 23660390a21SDaniel P. Berrange 23760390a21SDaniel P. Berrange rados_conf_set(cluster, "key", secret); 23860390a21SDaniel P. Berrange g_free(secret); 23960390a21SDaniel P. Berrange 24060390a21SDaniel P. Berrange return 0; 24160390a21SDaniel P. Berrange } 24260390a21SDaniel P. Berrange 243e98c6961SEric Blake static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs_json, 244e34d8f29SJosh Durgin Error **errp) 245fab5cf59SJosh Durgin { 246e98c6961SEric Blake QList *keypairs; 247e98c6961SEric Blake QString *name; 248e98c6961SEric Blake QString *value; 249e98c6961SEric Blake const char *key; 250e98c6961SEric Blake size_t remaining; 251fab5cf59SJosh Durgin int ret = 0; 252fab5cf59SJosh Durgin 253e98c6961SEric Blake if (!keypairs_json) { 254e98c6961SEric Blake return ret; 255fab5cf59SJosh Durgin } 256e98c6961SEric Blake keypairs = qobject_to_qlist(qobject_from_json(keypairs_json, 257e98c6961SEric Blake &error_abort)); 258e98c6961SEric Blake remaining = qlist_size(keypairs) / 2; 259e98c6961SEric Blake assert(remaining); 260fab5cf59SJosh Durgin 261e98c6961SEric Blake while (remaining--) { 262e98c6961SEric Blake name = qobject_to_qstring(qlist_pop(keypairs)); 263e98c6961SEric Blake value = qobject_to_qstring(qlist_pop(keypairs)); 264e98c6961SEric Blake assert(name && value); 265e98c6961SEric Blake key = qstring_get_str(name); 266fab5cf59SJosh Durgin 267e98c6961SEric Blake ret = rados_conf_set(cluster, key, qstring_get_str(value)); 268e98c6961SEric Blake QDECREF(name); 269e98c6961SEric Blake QDECREF(value); 270fab5cf59SJosh Durgin if (ret < 0) { 271e98c6961SEric Blake error_setg_errno(errp, -ret, "invalid conf option %s", key); 272fab5cf59SJosh Durgin ret = -EINVAL; 273fab5cf59SJosh Durgin break; 274fab5cf59SJosh Durgin } 275fab5cf59SJosh Durgin } 276fab5cf59SJosh Durgin 277e98c6961SEric Blake QDECREF(keypairs); 278fab5cf59SJosh Durgin return ret; 279fab5cf59SJosh Durgin } 280fab5cf59SJosh Durgin 2811d393bdeStianqing static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs) 2821d393bdeStianqing { 2831d393bdeStianqing if (LIBRBD_USE_IOVEC) { 2841d393bdeStianqing RBDAIOCB *acb = rcb->acb; 2851d393bdeStianqing iov_memset(acb->qiov->iov, acb->qiov->niov, offs, 0, 2861d393bdeStianqing acb->qiov->size - offs); 2871d393bdeStianqing } else { 2881d393bdeStianqing memset(rcb->buf + offs, 0, rcb->size - offs); 2891d393bdeStianqing } 2901d393bdeStianqing } 2911d393bdeStianqing 2920f9d252dSJeff Cody static QemuOptsList runtime_opts = { 2930f9d252dSJeff Cody .name = "rbd", 2940f9d252dSJeff Cody .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), 2950f9d252dSJeff Cody .desc = { 2960f9d252dSJeff Cody { 2970f9d252dSJeff Cody .name = "pool", 2980f9d252dSJeff Cody .type = QEMU_OPT_STRING, 2990f9d252dSJeff Cody .help = "Rados pool name", 3000f9d252dSJeff Cody }, 3010f9d252dSJeff Cody { 3020f9d252dSJeff Cody .name = "image", 3030f9d252dSJeff Cody .type = QEMU_OPT_STRING, 3040f9d252dSJeff Cody .help = "Image name in the pool", 3050f9d252dSJeff Cody }, 3060f9d252dSJeff Cody { 307cbf036b4SMarkus Armbruster .name = "conf", 308cbf036b4SMarkus Armbruster .type = QEMU_OPT_STRING, 309cbf036b4SMarkus Armbruster .help = "Rados config file location", 310cbf036b4SMarkus Armbruster }, 311cbf036b4SMarkus Armbruster { 3120f9d252dSJeff Cody .name = "snapshot", 3130f9d252dSJeff Cody .type = QEMU_OPT_STRING, 3140f9d252dSJeff Cody .help = "Ceph snapshot name", 3150f9d252dSJeff Cody }, 3160f9d252dSJeff Cody { 3170f9d252dSJeff Cody /* maps to 'id' in rados_create() */ 3180f9d252dSJeff Cody .name = "user", 3190f9d252dSJeff Cody .type = QEMU_OPT_STRING, 3200f9d252dSJeff Cody .help = "Rados id name", 3210f9d252dSJeff Cody }, 322cbf036b4SMarkus Armbruster /* 3232836284dSMarkus Armbruster * server.* extracted manually, see qemu_rbd_mon_host() 324cbf036b4SMarkus Armbruster */ 325cbf036b4SMarkus Armbruster { 326cbf036b4SMarkus Armbruster .name = "password-secret", 327cbf036b4SMarkus Armbruster .type = QEMU_OPT_STRING, 328cbf036b4SMarkus Armbruster .help = "ID of secret providing the password", 329cbf036b4SMarkus Armbruster }, 330cbf036b4SMarkus Armbruster 331cbf036b4SMarkus Armbruster /* 332cbf036b4SMarkus Armbruster * Keys for qemu_rbd_parse_filename(), not in the QAPI schema 333cbf036b4SMarkus Armbruster */ 3340f9d252dSJeff Cody { 33582f20e85SMarkus Armbruster /* 33682f20e85SMarkus Armbruster * HACK: name starts with '=' so that qemu_opts_parse() 33782f20e85SMarkus Armbruster * can't set it 33882f20e85SMarkus Armbruster */ 33982f20e85SMarkus Armbruster .name = "=keyvalue-pairs", 3400f9d252dSJeff Cody .type = QEMU_OPT_STRING, 3410f9d252dSJeff Cody .help = "Legacy rados key/value option parameters", 3420f9d252dSJeff Cody }, 34391589d9eSJeff Cody { 34491589d9eSJeff Cody .name = "filename", 34591589d9eSJeff Cody .type = QEMU_OPT_STRING, 34691589d9eSJeff Cody }, 3470f9d252dSJeff Cody { /* end of list */ } 3480f9d252dSJeff Cody }, 3490f9d252dSJeff Cody }; 3500f9d252dSJeff Cody 351bd0cf596SChunyan Liu static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) 352f27aaf4bSChristian Brunner { 353d61563b2SMarkus Armbruster Error *local_err = NULL; 354f27aaf4bSChristian Brunner int64_t bytes = 0; 355f27aaf4bSChristian Brunner int64_t objsize; 356ad32e9c0SJosh Durgin int obj_order = 0; 35780b61a27SJeff Cody const char *pool, *image_name, *conf, *user, *keypairs; 35860390a21SDaniel P. Berrange const char *secretid; 359ad32e9c0SJosh Durgin rados_t cluster; 360ad32e9c0SJosh Durgin rados_ioctx_t io_ctx; 361c7cacb3eSJeff Cody QDict *options = NULL; 362c7cacb3eSJeff Cody int ret = 0; 363f27aaf4bSChristian Brunner 36460390a21SDaniel P. Berrange secretid = qemu_opt_get(opts, "password-secret"); 36560390a21SDaniel P. Berrange 366f27aaf4bSChristian Brunner /* Read out options */ 367c2eb918eSHu Tao bytes = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), 368c2eb918eSHu Tao BDRV_SECTOR_SIZE); 369bd0cf596SChunyan Liu objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0); 370bd0cf596SChunyan Liu if (objsize) { 371f27aaf4bSChristian Brunner if ((objsize - 1) & objsize) { /* not a power of 2? */ 372d61563b2SMarkus Armbruster error_setg(errp, "obj size needs to be power of 2"); 373c7cacb3eSJeff Cody ret = -EINVAL; 374c7cacb3eSJeff Cody goto exit; 375f27aaf4bSChristian Brunner } 376f27aaf4bSChristian Brunner if (objsize < 4096) { 377d61563b2SMarkus Armbruster error_setg(errp, "obj size too small"); 378c7cacb3eSJeff Cody ret = -EINVAL; 379c7cacb3eSJeff Cody goto exit; 380f27aaf4bSChristian Brunner } 381786a4ea8SStefan Hajnoczi obj_order = ctz32(objsize); 382f27aaf4bSChristian Brunner } 383f27aaf4bSChristian Brunner 384c7cacb3eSJeff Cody options = qdict_new(); 385c7cacb3eSJeff Cody qemu_rbd_parse_filename(filename, options, &local_err); 386c7cacb3eSJeff Cody if (local_err) { 387c7cacb3eSJeff Cody ret = -EINVAL; 388c7cacb3eSJeff Cody error_propagate(errp, local_err); 389c7cacb3eSJeff Cody goto exit; 390c7cacb3eSJeff Cody } 391c7cacb3eSJeff Cody 392129c7d1cSMarkus Armbruster /* 393129c7d1cSMarkus Armbruster * Caution: while qdict_get_try_str() is fine, getting non-string 394129c7d1cSMarkus Armbruster * types would require more care. When @options come from -blockdev 395129c7d1cSMarkus Armbruster * or blockdev_add, its members are typed according to the QAPI 396129c7d1cSMarkus Armbruster * schema, but when they come from -drive, they're all QString. 397129c7d1cSMarkus Armbruster */ 39807846397SMarkus Armbruster pool = qdict_get_try_str(options, "pool"); 39907846397SMarkus Armbruster conf = qdict_get_try_str(options, "conf"); 40080b61a27SJeff Cody user = qdict_get_try_str(options, "user"); 40180b61a27SJeff Cody image_name = qdict_get_try_str(options, "image"); 40207846397SMarkus Armbruster keypairs = qdict_get_try_str(options, "=keyvalue-pairs"); 403c7cacb3eSJeff Cody 40480b61a27SJeff Cody ret = rados_create(&cluster, user); 40587cd3d20SVikhyat Umrao if (ret < 0) { 40687cd3d20SVikhyat Umrao error_setg_errno(errp, -ret, "error initializing"); 407c7cacb3eSJeff Cody goto exit; 408f27aaf4bSChristian Brunner } 409f27aaf4bSChristian Brunner 410c7cacb3eSJeff Cody /* try default location when conf=NULL, but ignore failure */ 411c7cacb3eSJeff Cody ret = rados_conf_read_file(cluster, conf); 412c7cacb3eSJeff Cody if (conf && ret < 0) { 413c7cacb3eSJeff Cody error_setg_errno(errp, -ret, "error reading conf file %s", conf); 414e38f643aSXiubo Li ret = -EIO; 415e38f643aSXiubo Li goto shutdown; 416fab5cf59SJosh Durgin } 417fab5cf59SJosh Durgin 418c7cacb3eSJeff Cody ret = qemu_rbd_set_keypairs(cluster, keypairs, errp); 419c7cacb3eSJeff Cody if (ret < 0) { 420e38f643aSXiubo Li ret = -EIO; 421e38f643aSXiubo Li goto shutdown; 422fab5cf59SJosh Durgin } 423ad32e9c0SJosh Durgin 42460390a21SDaniel P. Berrange if (qemu_rbd_set_auth(cluster, secretid, errp) < 0) { 425e38f643aSXiubo Li ret = -EIO; 426e38f643aSXiubo Li goto shutdown; 42760390a21SDaniel P. Berrange } 42860390a21SDaniel P. Berrange 42987cd3d20SVikhyat Umrao ret = rados_connect(cluster); 43087cd3d20SVikhyat Umrao if (ret < 0) { 43187cd3d20SVikhyat Umrao error_setg_errno(errp, -ret, "error connecting"); 432e38f643aSXiubo Li goto shutdown; 433ad32e9c0SJosh Durgin } 434ad32e9c0SJosh Durgin 43587cd3d20SVikhyat Umrao ret = rados_ioctx_create(cluster, pool, &io_ctx); 43687cd3d20SVikhyat Umrao if (ret < 0) { 43787cd3d20SVikhyat Umrao error_setg_errno(errp, -ret, "error opening pool %s", pool); 438e38f643aSXiubo Li goto shutdown; 439f27aaf4bSChristian Brunner } 440f27aaf4bSChristian Brunner 44180b61a27SJeff Cody ret = rbd_create(io_ctx, image_name, bytes, &obj_order); 44287cd3d20SVikhyat Umrao if (ret < 0) { 44387cd3d20SVikhyat Umrao error_setg_errno(errp, -ret, "error rbd create"); 44487cd3d20SVikhyat Umrao } 445f27aaf4bSChristian Brunner 446e38f643aSXiubo Li rados_ioctx_destroy(io_ctx); 447e38f643aSXiubo Li 448e38f643aSXiubo Li shutdown: 449e38f643aSXiubo Li rados_shutdown(cluster); 450c7cacb3eSJeff Cody 451c7cacb3eSJeff Cody exit: 452c7cacb3eSJeff Cody QDECREF(options); 453f27aaf4bSChristian Brunner return ret; 454f27aaf4bSChristian Brunner } 455f27aaf4bSChristian Brunner 456f27aaf4bSChristian Brunner /* 457e04fb07fSStefan Hajnoczi * This aio completion is being called from rbd_finish_bh() and runs in qemu 458e04fb07fSStefan Hajnoczi * BH context. 459f27aaf4bSChristian Brunner */ 460ad32e9c0SJosh Durgin static void qemu_rbd_complete_aio(RADOSCB *rcb) 461f27aaf4bSChristian Brunner { 462f27aaf4bSChristian Brunner RBDAIOCB *acb = rcb->acb; 463f27aaf4bSChristian Brunner int64_t r; 464f27aaf4bSChristian Brunner 465f27aaf4bSChristian Brunner r = rcb->ret; 466f27aaf4bSChristian Brunner 467dc7588c1SJosh Durgin if (acb->cmd != RBD_AIO_READ) { 468f27aaf4bSChristian Brunner if (r < 0) { 469f27aaf4bSChristian Brunner acb->ret = r; 470f27aaf4bSChristian Brunner acb->error = 1; 471f27aaf4bSChristian Brunner } else if (!acb->error) { 472ad32e9c0SJosh Durgin acb->ret = rcb->size; 473f27aaf4bSChristian Brunner } 474f27aaf4bSChristian Brunner } else { 475ad32e9c0SJosh Durgin if (r < 0) { 4761d393bdeStianqing qemu_rbd_memset(rcb, 0); 477f27aaf4bSChristian Brunner acb->ret = r; 478f27aaf4bSChristian Brunner acb->error = 1; 479ad32e9c0SJosh Durgin } else if (r < rcb->size) { 4801d393bdeStianqing qemu_rbd_memset(rcb, r); 481f27aaf4bSChristian Brunner if (!acb->error) { 482ad32e9c0SJosh Durgin acb->ret = rcb->size; 483f27aaf4bSChristian Brunner } 484f27aaf4bSChristian Brunner } else if (!acb->error) { 485ad32e9c0SJosh Durgin acb->ret = r; 486f27aaf4bSChristian Brunner } 487f27aaf4bSChristian Brunner } 488e04fb07fSStefan Hajnoczi 4897267c094SAnthony Liguori g_free(rcb); 490e04fb07fSStefan Hajnoczi 4911d393bdeStianqing if (!LIBRBD_USE_IOVEC) { 492e04fb07fSStefan Hajnoczi if (acb->cmd == RBD_AIO_READ) { 493e04fb07fSStefan Hajnoczi qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size); 494f27aaf4bSChristian Brunner } 495e04fb07fSStefan Hajnoczi qemu_vfree(acb->bounce); 4961d393bdeStianqing } 4971d393bdeStianqing 498e04fb07fSStefan Hajnoczi acb->common.cb(acb->common.opaque, (acb->ret > 0 ? 0 : acb->ret)); 499f27aaf4bSChristian Brunner 5008007429aSFam Zheng qemu_aio_unref(acb); 501f27aaf4bSChristian Brunner } 502f27aaf4bSChristian Brunner 5032836284dSMarkus Armbruster static char *qemu_rbd_mon_host(QDict *options, Error **errp) 5040a55679bSJeff Cody { 5052836284dSMarkus Armbruster const char **vals = g_new(const char *, qdict_size(options) + 1); 5062836284dSMarkus Armbruster char keybuf[32]; 5072836284dSMarkus Armbruster const char *host, *port; 5082836284dSMarkus Armbruster char *rados_str; 5090a55679bSJeff Cody int i; 5100a55679bSJeff Cody 5112836284dSMarkus Armbruster for (i = 0;; i++) { 5122836284dSMarkus Armbruster sprintf(keybuf, "server.%d.host", i); 5132836284dSMarkus Armbruster host = qdict_get_try_str(options, keybuf); 5142836284dSMarkus Armbruster qdict_del(options, keybuf); 5152836284dSMarkus Armbruster sprintf(keybuf, "server.%d.port", i); 5162836284dSMarkus Armbruster port = qdict_get_try_str(options, keybuf); 5172836284dSMarkus Armbruster qdict_del(options, keybuf); 5182836284dSMarkus Armbruster if (!host && !port) { 5192836284dSMarkus Armbruster break; 5200a55679bSJeff Cody } 5212836284dSMarkus Armbruster if (!host) { 5222836284dSMarkus Armbruster error_setg(errp, "Parameter server.%d.host is missing", i); 5230a55679bSJeff Cody rados_str = NULL; 5242836284dSMarkus Armbruster goto out; 5250a55679bSJeff Cody } 5260a55679bSJeff Cody 5270a55679bSJeff Cody if (strchr(host, ':')) { 5282836284dSMarkus Armbruster vals[i] = port ? g_strdup_printf("[%s]:%s", host, port) 5292836284dSMarkus Armbruster : g_strdup_printf("[%s]", host); 5300a55679bSJeff Cody } else { 5312836284dSMarkus Armbruster vals[i] = port ? g_strdup_printf("%s:%s", host, port) 5322836284dSMarkus Armbruster : g_strdup(host); 5330a55679bSJeff Cody } 5340a55679bSJeff Cody } 5352836284dSMarkus Armbruster vals[i] = NULL; 5360a55679bSJeff Cody 5372836284dSMarkus Armbruster rados_str = i ? g_strjoinv(";", (char **)vals) : NULL; 5382836284dSMarkus Armbruster out: 5392836284dSMarkus Armbruster g_strfreev((char **)vals); 5400a55679bSJeff Cody return rados_str; 5410a55679bSJeff Cody } 5420a55679bSJeff Cody 543015a1036SMax Reitz static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, 544015a1036SMax Reitz Error **errp) 545f27aaf4bSChristian Brunner { 546f27aaf4bSChristian Brunner BDRVRBDState *s = bs->opaque; 54780b61a27SJeff Cody const char *pool, *snap, *conf, *user, *image_name, *keypairs; 54891589d9eSJeff Cody const char *secretid, *filename; 549a9ccedc3SKevin Wolf QemuOpts *opts; 550a9ccedc3SKevin Wolf Error *local_err = NULL; 5510a55679bSJeff Cody char *mon_host = NULL; 552f27aaf4bSChristian Brunner int r; 553f27aaf4bSChristian Brunner 55491589d9eSJeff Cody /* If we are given a filename, parse the filename, with precedence given to 55591589d9eSJeff Cody * filename encoded options */ 55691589d9eSJeff Cody filename = qdict_get_try_str(options, "filename"); 55791589d9eSJeff Cody if (filename) { 5583dc6f869SAlistair Francis warn_report("'filename' option specified. " 55991589d9eSJeff Cody "This is an unsupported option, and may be deprecated " 56091589d9eSJeff Cody "in the future"); 56191589d9eSJeff Cody qemu_rbd_parse_filename(filename, options, &local_err); 56291589d9eSJeff Cody if (local_err) { 56391589d9eSJeff Cody r = -EINVAL; 56491589d9eSJeff Cody error_propagate(errp, local_err); 56591589d9eSJeff Cody goto exit; 56691589d9eSJeff Cody } 56791589d9eSJeff Cody } 56891589d9eSJeff Cody 56987ea75d5SPeter Crosthwaite opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); 570a9ccedc3SKevin Wolf qemu_opts_absorb_qdict(opts, options, &local_err); 57184d18f06SMarkus Armbruster if (local_err) { 572d61563b2SMarkus Armbruster error_propagate(errp, local_err); 5732836284dSMarkus Armbruster r = -EINVAL; 5742836284dSMarkus Armbruster goto failed_opts; 575a9ccedc3SKevin Wolf } 576a9ccedc3SKevin Wolf 5772836284dSMarkus Armbruster mon_host = qemu_rbd_mon_host(options, &local_err); 5780a55679bSJeff Cody if (local_err) { 5790a55679bSJeff Cody error_propagate(errp, local_err); 5800a55679bSJeff Cody r = -EINVAL; 5810a55679bSJeff Cody goto failed_opts; 5820a55679bSJeff Cody } 5830a55679bSJeff Cody 58460390a21SDaniel P. Berrange secretid = qemu_opt_get(opts, "password-secret"); 585a9ccedc3SKevin Wolf 586c7cacb3eSJeff Cody pool = qemu_opt_get(opts, "pool"); 587c7cacb3eSJeff Cody conf = qemu_opt_get(opts, "conf"); 588c7cacb3eSJeff Cody snap = qemu_opt_get(opts, "snapshot"); 58980b61a27SJeff Cody user = qemu_opt_get(opts, "user"); 59080b61a27SJeff Cody image_name = qemu_opt_get(opts, "image"); 59182f20e85SMarkus Armbruster keypairs = qemu_opt_get(opts, "=keyvalue-pairs"); 592f27aaf4bSChristian Brunner 59380b61a27SJeff Cody if (!pool || !image_name) { 594f51c363cSMarkus Armbruster error_setg(errp, "Parameters 'pool' and 'image' are required"); 595f51c363cSMarkus Armbruster r = -EINVAL; 596f51c363cSMarkus Armbruster goto failed_opts; 597f51c363cSMarkus Armbruster } 598f51c363cSMarkus Armbruster 59980b61a27SJeff Cody r = rados_create(&s->cluster, user); 600ad32e9c0SJosh Durgin if (r < 0) { 60187cd3d20SVikhyat Umrao error_setg_errno(errp, -r, "error initializing"); 602c3ca988dSKevin Wolf goto failed_opts; 603f27aaf4bSChristian Brunner } 604f27aaf4bSChristian Brunner 605c7cacb3eSJeff Cody s->snap = g_strdup(snap); 60680b61a27SJeff Cody s->image_name = g_strdup(image_name); 607eb93d5d9SSage Weil 608c7cacb3eSJeff Cody /* try default location when conf=NULL, but ignore failure */ 609c7cacb3eSJeff Cody r = rados_conf_read_file(s->cluster, conf); 610c7cacb3eSJeff Cody if (conf && r < 0) { 611c7cacb3eSJeff Cody error_setg_errno(errp, -r, "error reading conf file %s", conf); 612e34d8f29SJosh Durgin goto failed_shutdown; 613e34d8f29SJosh Durgin } 61499a3c89dSJosh Durgin 615c7cacb3eSJeff Cody r = qemu_rbd_set_keypairs(s->cluster, keypairs, errp); 61699a3c89dSJosh Durgin if (r < 0) { 61799a3c89dSJosh Durgin goto failed_shutdown; 61899a3c89dSJosh Durgin } 61999a3c89dSJosh Durgin 6200a55679bSJeff Cody if (mon_host) { 6210a55679bSJeff Cody r = rados_conf_set(s->cluster, "mon_host", mon_host); 6220a55679bSJeff Cody if (r < 0) { 6230a55679bSJeff Cody goto failed_shutdown; 6240a55679bSJeff Cody } 6250a55679bSJeff Cody } 6260a55679bSJeff Cody 62760390a21SDaniel P. Berrange if (qemu_rbd_set_auth(s->cluster, secretid, errp) < 0) { 62860390a21SDaniel P. Berrange r = -EIO; 62960390a21SDaniel P. Berrange goto failed_shutdown; 63060390a21SDaniel P. Berrange } 63160390a21SDaniel P. Berrange 632b11f38fcSJosh Durgin /* 633b11f38fcSJosh Durgin * Fallback to more conservative semantics if setting cache 634b11f38fcSJosh Durgin * options fails. Ignore errors from setting rbd_cache because the 635b11f38fcSJosh Durgin * only possible error is that the option does not exist, and 636b11f38fcSJosh Durgin * librbd defaults to no caching. If write through caching cannot 637b11f38fcSJosh Durgin * be set up, fall back to no caching. 638b11f38fcSJosh Durgin */ 639b11f38fcSJosh Durgin if (flags & BDRV_O_NOCACHE) { 640b11f38fcSJosh Durgin rados_conf_set(s->cluster, "rbd_cache", "false"); 641b11f38fcSJosh Durgin } else { 642b11f38fcSJosh Durgin rados_conf_set(s->cluster, "rbd_cache", "true"); 643b11f38fcSJosh Durgin } 644b11f38fcSJosh Durgin 645ad32e9c0SJosh Durgin r = rados_connect(s->cluster); 646ad32e9c0SJosh Durgin if (r < 0) { 64787cd3d20SVikhyat Umrao error_setg_errno(errp, -r, "error connecting"); 648eb93d5d9SSage Weil goto failed_shutdown; 649ad32e9c0SJosh Durgin } 650ad32e9c0SJosh Durgin 651ad32e9c0SJosh Durgin r = rados_ioctx_create(s->cluster, pool, &s->io_ctx); 652ad32e9c0SJosh Durgin if (r < 0) { 65387cd3d20SVikhyat Umrao error_setg_errno(errp, -r, "error opening pool %s", pool); 654eb93d5d9SSage Weil goto failed_shutdown; 655ad32e9c0SJosh Durgin } 656ad32e9c0SJosh Durgin 657e2b8247aSJeff Cody /* rbd_open is always r/w */ 65880b61a27SJeff Cody r = rbd_open(s->io_ctx, s->image_name, &s->image, s->snap); 659ad32e9c0SJosh Durgin if (r < 0) { 66080b61a27SJeff Cody error_setg_errno(errp, -r, "error reading header from %s", 66180b61a27SJeff Cody s->image_name); 662eb93d5d9SSage Weil goto failed_open; 663ad32e9c0SJosh Durgin } 664ad32e9c0SJosh Durgin 665e2b8247aSJeff Cody /* If we are using an rbd snapshot, we must be r/o, otherwise 666e2b8247aSJeff Cody * leave as-is */ 667e2b8247aSJeff Cody if (s->snap != NULL) { 668*398e6ad0SKevin Wolf if (!bdrv_is_read_only(bs)) { 669*398e6ad0SKevin Wolf error_report("Opening rbd snapshots without an explicit " 670*398e6ad0SKevin Wolf "read-only=on option is deprecated. Future versions " 671*398e6ad0SKevin Wolf "will refuse to open the image instead of " 672*398e6ad0SKevin Wolf "automatically marking the image read-only."); 673e2b8247aSJeff Cody r = bdrv_set_read_only(bs, true, &local_err); 674e2b8247aSJeff Cody if (r < 0) { 675e2b8247aSJeff Cody error_propagate(errp, local_err); 676e2b8247aSJeff Cody goto failed_open; 677e2b8247aSJeff Cody } 678e2b8247aSJeff Cody } 679*398e6ad0SKevin Wolf } 680f27aaf4bSChristian Brunner 681c3ca988dSKevin Wolf qemu_opts_del(opts); 682f27aaf4bSChristian Brunner return 0; 683f27aaf4bSChristian Brunner 684eb93d5d9SSage Weil failed_open: 685ad32e9c0SJosh Durgin rados_ioctx_destroy(s->io_ctx); 686eb93d5d9SSage Weil failed_shutdown: 687ad32e9c0SJosh Durgin rados_shutdown(s->cluster); 688eb93d5d9SSage Weil g_free(s->snap); 68980b61a27SJeff Cody g_free(s->image_name); 690c3ca988dSKevin Wolf failed_opts: 691c3ca988dSKevin Wolf qemu_opts_del(opts); 6920a55679bSJeff Cody g_free(mon_host); 69391589d9eSJeff Cody exit: 694f27aaf4bSChristian Brunner return r; 695f27aaf4bSChristian Brunner } 696f27aaf4bSChristian Brunner 69756e7cf8dSJeff Cody 69856e7cf8dSJeff Cody /* Since RBD is currently always opened R/W via the API, 69956e7cf8dSJeff Cody * we just need to check if we are using a snapshot or not, in 70056e7cf8dSJeff Cody * order to determine if we will allow it to be R/W */ 70156e7cf8dSJeff Cody static int qemu_rbd_reopen_prepare(BDRVReopenState *state, 70256e7cf8dSJeff Cody BlockReopenQueue *queue, Error **errp) 70356e7cf8dSJeff Cody { 70456e7cf8dSJeff Cody BDRVRBDState *s = state->bs->opaque; 70556e7cf8dSJeff Cody int ret = 0; 70656e7cf8dSJeff Cody 70756e7cf8dSJeff Cody if (s->snap && state->flags & BDRV_O_RDWR) { 70856e7cf8dSJeff Cody error_setg(errp, 70956e7cf8dSJeff Cody "Cannot change node '%s' to r/w when using RBD snapshot", 71056e7cf8dSJeff Cody bdrv_get_device_or_node_name(state->bs)); 71156e7cf8dSJeff Cody ret = -EINVAL; 71256e7cf8dSJeff Cody } 71356e7cf8dSJeff Cody 71456e7cf8dSJeff Cody return ret; 71556e7cf8dSJeff Cody } 71656e7cf8dSJeff Cody 717ad32e9c0SJosh Durgin static void qemu_rbd_close(BlockDriverState *bs) 718f27aaf4bSChristian Brunner { 719f27aaf4bSChristian Brunner BDRVRBDState *s = bs->opaque; 720f27aaf4bSChristian Brunner 721ad32e9c0SJosh Durgin rbd_close(s->image); 722ad32e9c0SJosh Durgin rados_ioctx_destroy(s->io_ctx); 7237267c094SAnthony Liguori g_free(s->snap); 72480b61a27SJeff Cody g_free(s->image_name); 725ad32e9c0SJosh Durgin rados_shutdown(s->cluster); 726f27aaf4bSChristian Brunner } 727f27aaf4bSChristian Brunner 728d7331bedSStefan Hajnoczi static const AIOCBInfo rbd_aiocb_info = { 729f27aaf4bSChristian Brunner .aiocb_size = sizeof(RBDAIOCB), 730f27aaf4bSChristian Brunner }; 731f27aaf4bSChristian Brunner 732e04fb07fSStefan Hajnoczi static void rbd_finish_bh(void *opaque) 733f27aaf4bSChristian Brunner { 734e04fb07fSStefan Hajnoczi RADOSCB *rcb = opaque; 735e04fb07fSStefan Hajnoczi qemu_rbd_complete_aio(rcb); 736ad32e9c0SJosh Durgin } 737ad32e9c0SJosh Durgin 738ad32e9c0SJosh Durgin /* 739ad32e9c0SJosh Durgin * This is the callback function for rbd_aio_read and _write 740ad32e9c0SJosh Durgin * 741ad32e9c0SJosh Durgin * Note: this function is being called from a non qemu thread so 742ad32e9c0SJosh Durgin * we need to be careful about what we do here. Generally we only 743e04fb07fSStefan Hajnoczi * schedule a BH, and do the rest of the io completion handling 744e04fb07fSStefan Hajnoczi * from rbd_finish_bh() which runs in a qemu context. 745ad32e9c0SJosh Durgin */ 746ad32e9c0SJosh Durgin static void rbd_finish_aiocb(rbd_completion_t c, RADOSCB *rcb) 747ad32e9c0SJosh Durgin { 748e04fb07fSStefan Hajnoczi RBDAIOCB *acb = rcb->acb; 749e04fb07fSStefan Hajnoczi 750ad32e9c0SJosh Durgin rcb->ret = rbd_aio_get_return_value(c); 751ad32e9c0SJosh Durgin rbd_aio_release(c); 752f27aaf4bSChristian Brunner 753fffb6e12SPaolo Bonzini aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), 754ea800191SStefan Hajnoczi rbd_finish_bh, rcb); 755473c7f02SStefan Priebe } 756f27aaf4bSChristian Brunner 757787f3133SJosh Durgin static int rbd_aio_discard_wrapper(rbd_image_t image, 758787f3133SJosh Durgin uint64_t off, 759787f3133SJosh Durgin uint64_t len, 760787f3133SJosh Durgin rbd_completion_t comp) 761787f3133SJosh Durgin { 762787f3133SJosh Durgin #ifdef LIBRBD_SUPPORTS_DISCARD 763787f3133SJosh Durgin return rbd_aio_discard(image, off, len, comp); 764787f3133SJosh Durgin #else 765787f3133SJosh Durgin return -ENOTSUP; 766787f3133SJosh Durgin #endif 767787f3133SJosh Durgin } 768787f3133SJosh Durgin 769dc7588c1SJosh Durgin static int rbd_aio_flush_wrapper(rbd_image_t image, 770dc7588c1SJosh Durgin rbd_completion_t comp) 771dc7588c1SJosh Durgin { 772dc7588c1SJosh Durgin #ifdef LIBRBD_SUPPORTS_AIO_FLUSH 773dc7588c1SJosh Durgin return rbd_aio_flush(image, comp); 774dc7588c1SJosh Durgin #else 775dc7588c1SJosh Durgin return -ENOTSUP; 776dc7588c1SJosh Durgin #endif 777dc7588c1SJosh Durgin } 778dc7588c1SJosh Durgin 7797c84b1b8SMarkus Armbruster static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, 7807bbca9e2SEric Blake int64_t off, 781f27aaf4bSChristian Brunner QEMUIOVector *qiov, 7827bbca9e2SEric Blake int64_t size, 783097310b5SMarkus Armbruster BlockCompletionFunc *cb, 784787f3133SJosh Durgin void *opaque, 785787f3133SJosh Durgin RBDAIOCmd cmd) 786f27aaf4bSChristian Brunner { 787f27aaf4bSChristian Brunner RBDAIOCB *acb; 7880f7a0237SKevin Wolf RADOSCB *rcb = NULL; 789ad32e9c0SJosh Durgin rbd_completion_t c; 79051a13528SJosh Durgin int r; 791f27aaf4bSChristian Brunner 792f27aaf4bSChristian Brunner BDRVRBDState *s = bs->opaque; 793f27aaf4bSChristian Brunner 794d7331bedSStefan Hajnoczi acb = qemu_aio_get(&rbd_aiocb_info, bs, cb, opaque); 795787f3133SJosh Durgin acb->cmd = cmd; 796f27aaf4bSChristian Brunner acb->qiov = qiov; 7977bbca9e2SEric Blake assert(!qiov || qiov->size == size); 7981d393bdeStianqing 7991d393bdeStianqing rcb = g_new(RADOSCB, 1); 8001d393bdeStianqing 8011d393bdeStianqing if (!LIBRBD_USE_IOVEC) { 802dc7588c1SJosh Durgin if (cmd == RBD_AIO_DISCARD || cmd == RBD_AIO_FLUSH) { 803787f3133SJosh Durgin acb->bounce = NULL; 804787f3133SJosh Durgin } else { 8050f7a0237SKevin Wolf acb->bounce = qemu_try_blockalign(bs, qiov->size); 8060f7a0237SKevin Wolf if (acb->bounce == NULL) { 8070f7a0237SKevin Wolf goto failed; 8080f7a0237SKevin Wolf } 809787f3133SJosh Durgin } 8101d393bdeStianqing if (cmd == RBD_AIO_WRITE) { 8111d393bdeStianqing qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size); 8121d393bdeStianqing } 8131d393bdeStianqing rcb->buf = acb->bounce; 8141d393bdeStianqing } 8151d393bdeStianqing 816f27aaf4bSChristian Brunner acb->ret = 0; 817f27aaf4bSChristian Brunner acb->error = 0; 818f27aaf4bSChristian Brunner acb->s = s; 819f27aaf4bSChristian Brunner 820f27aaf4bSChristian Brunner rcb->acb = acb; 821f27aaf4bSChristian Brunner rcb->s = acb->s; 822ad32e9c0SJosh Durgin rcb->size = size; 82351a13528SJosh Durgin r = rbd_aio_create_completion(rcb, (rbd_callback_t) rbd_finish_aiocb, &c); 82451a13528SJosh Durgin if (r < 0) { 82551a13528SJosh Durgin goto failed; 82651a13528SJosh Durgin } 827f27aaf4bSChristian Brunner 828787f3133SJosh Durgin switch (cmd) { 829787f3133SJosh Durgin case RBD_AIO_WRITE: 8301d393bdeStianqing #ifdef LIBRBD_SUPPORTS_IOVEC 8311d393bdeStianqing r = rbd_aio_writev(s->image, qiov->iov, qiov->niov, off, c); 8321d393bdeStianqing #else 8331d393bdeStianqing r = rbd_aio_write(s->image, off, size, rcb->buf, c); 8341d393bdeStianqing #endif 835787f3133SJosh Durgin break; 836787f3133SJosh Durgin case RBD_AIO_READ: 8371d393bdeStianqing #ifdef LIBRBD_SUPPORTS_IOVEC 8381d393bdeStianqing r = rbd_aio_readv(s->image, qiov->iov, qiov->niov, off, c); 8391d393bdeStianqing #else 8401d393bdeStianqing r = rbd_aio_read(s->image, off, size, rcb->buf, c); 8411d393bdeStianqing #endif 842787f3133SJosh Durgin break; 843787f3133SJosh Durgin case RBD_AIO_DISCARD: 844787f3133SJosh Durgin r = rbd_aio_discard_wrapper(s->image, off, size, c); 845787f3133SJosh Durgin break; 846dc7588c1SJosh Durgin case RBD_AIO_FLUSH: 847dc7588c1SJosh Durgin r = rbd_aio_flush_wrapper(s->image, c); 848dc7588c1SJosh Durgin break; 849787f3133SJosh Durgin default: 850787f3133SJosh Durgin r = -EINVAL; 85151a13528SJosh Durgin } 85251a13528SJosh Durgin 85351a13528SJosh Durgin if (r < 0) { 854405a2764SKevin Wolf goto failed_completion; 855f27aaf4bSChristian Brunner } 856f27aaf4bSChristian Brunner return &acb->common; 85751a13528SJosh Durgin 858405a2764SKevin Wolf failed_completion: 859405a2764SKevin Wolf rbd_aio_release(c); 86051a13528SJosh Durgin failed: 8617267c094SAnthony Liguori g_free(rcb); 8621d393bdeStianqing if (!LIBRBD_USE_IOVEC) { 863405a2764SKevin Wolf qemu_vfree(acb->bounce); 8641d393bdeStianqing } 8651d393bdeStianqing 8668007429aSFam Zheng qemu_aio_unref(acb); 86751a13528SJosh Durgin return NULL; 868f27aaf4bSChristian Brunner } 869f27aaf4bSChristian Brunner 8707c84b1b8SMarkus Armbruster static BlockAIOCB *qemu_rbd_aio_readv(BlockDriverState *bs, 871ad32e9c0SJosh Durgin int64_t sector_num, 872ad32e9c0SJosh Durgin QEMUIOVector *qiov, 873f27aaf4bSChristian Brunner int nb_sectors, 874097310b5SMarkus Armbruster BlockCompletionFunc *cb, 875f27aaf4bSChristian Brunner void *opaque) 876f27aaf4bSChristian Brunner { 8777bbca9e2SEric Blake return rbd_start_aio(bs, sector_num << BDRV_SECTOR_BITS, qiov, 878e948f663SPaolo Bonzini (int64_t) nb_sectors << BDRV_SECTOR_BITS, cb, opaque, 879787f3133SJosh Durgin RBD_AIO_READ); 880f27aaf4bSChristian Brunner } 881f27aaf4bSChristian Brunner 8827c84b1b8SMarkus Armbruster static BlockAIOCB *qemu_rbd_aio_writev(BlockDriverState *bs, 883ad32e9c0SJosh Durgin int64_t sector_num, 884ad32e9c0SJosh Durgin QEMUIOVector *qiov, 885f27aaf4bSChristian Brunner int nb_sectors, 886097310b5SMarkus Armbruster BlockCompletionFunc *cb, 887f27aaf4bSChristian Brunner void *opaque) 888f27aaf4bSChristian Brunner { 8897bbca9e2SEric Blake return rbd_start_aio(bs, sector_num << BDRV_SECTOR_BITS, qiov, 890e948f663SPaolo Bonzini (int64_t) nb_sectors << BDRV_SECTOR_BITS, cb, opaque, 891787f3133SJosh Durgin RBD_AIO_WRITE); 892f27aaf4bSChristian Brunner } 893f27aaf4bSChristian Brunner 894dc7588c1SJosh Durgin #ifdef LIBRBD_SUPPORTS_AIO_FLUSH 8957c84b1b8SMarkus Armbruster static BlockAIOCB *qemu_rbd_aio_flush(BlockDriverState *bs, 896097310b5SMarkus Armbruster BlockCompletionFunc *cb, 897dc7588c1SJosh Durgin void *opaque) 898dc7588c1SJosh Durgin { 899dc7588c1SJosh Durgin return rbd_start_aio(bs, 0, NULL, 0, cb, opaque, RBD_AIO_FLUSH); 900dc7588c1SJosh Durgin } 901dc7588c1SJosh Durgin 902dc7588c1SJosh Durgin #else 903dc7588c1SJosh Durgin 9048b94ff85SPaolo Bonzini static int qemu_rbd_co_flush(BlockDriverState *bs) 9057a3f5fe9SSage Weil { 9067a3f5fe9SSage Weil #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 1) 9077a3f5fe9SSage Weil /* rbd_flush added in 0.1.1 */ 9087a3f5fe9SSage Weil BDRVRBDState *s = bs->opaque; 9097a3f5fe9SSage Weil return rbd_flush(s->image); 9107a3f5fe9SSage Weil #else 9117a3f5fe9SSage Weil return 0; 9127a3f5fe9SSage Weil #endif 9137a3f5fe9SSage Weil } 914dc7588c1SJosh Durgin #endif 9157a3f5fe9SSage Weil 916ad32e9c0SJosh Durgin static int qemu_rbd_getinfo(BlockDriverState *bs, BlockDriverInfo *bdi) 917f27aaf4bSChristian Brunner { 918f27aaf4bSChristian Brunner BDRVRBDState *s = bs->opaque; 919ad32e9c0SJosh Durgin rbd_image_info_t info; 920ad32e9c0SJosh Durgin int r; 921ad32e9c0SJosh Durgin 922ad32e9c0SJosh Durgin r = rbd_stat(s->image, &info, sizeof(info)); 923ad32e9c0SJosh Durgin if (r < 0) { 924ad32e9c0SJosh Durgin return r; 925ad32e9c0SJosh Durgin } 926ad32e9c0SJosh Durgin 927ad32e9c0SJosh Durgin bdi->cluster_size = info.obj_size; 928f27aaf4bSChristian Brunner return 0; 929f27aaf4bSChristian Brunner } 930f27aaf4bSChristian Brunner 931ad32e9c0SJosh Durgin static int64_t qemu_rbd_getlength(BlockDriverState *bs) 932f27aaf4bSChristian Brunner { 933f27aaf4bSChristian Brunner BDRVRBDState *s = bs->opaque; 934ad32e9c0SJosh Durgin rbd_image_info_t info; 935ad32e9c0SJosh Durgin int r; 936f27aaf4bSChristian Brunner 937ad32e9c0SJosh Durgin r = rbd_stat(s->image, &info, sizeof(info)); 938ad32e9c0SJosh Durgin if (r < 0) { 939ad32e9c0SJosh Durgin return r; 940f27aaf4bSChristian Brunner } 941f27aaf4bSChristian Brunner 942ad32e9c0SJosh Durgin return info.size; 943ad32e9c0SJosh Durgin } 944ad32e9c0SJosh Durgin 9458243ccb7SMax Reitz static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset, 9468243ccb7SMax Reitz PreallocMode prealloc, Error **errp) 94730cdc48cSJosh Durgin { 94830cdc48cSJosh Durgin BDRVRBDState *s = bs->opaque; 94930cdc48cSJosh Durgin int r; 95030cdc48cSJosh Durgin 9518243ccb7SMax Reitz if (prealloc != PREALLOC_MODE_OFF) { 9528243ccb7SMax Reitz error_setg(errp, "Unsupported preallocation mode '%s'", 953977c736fSMarkus Armbruster PreallocMode_str(prealloc)); 9548243ccb7SMax Reitz return -ENOTSUP; 9558243ccb7SMax Reitz } 9568243ccb7SMax Reitz 95730cdc48cSJosh Durgin r = rbd_resize(s->image, offset); 95830cdc48cSJosh Durgin if (r < 0) { 959f59adb32SMax Reitz error_setg_errno(errp, -r, "Failed to resize file"); 96030cdc48cSJosh Durgin return r; 96130cdc48cSJosh Durgin } 96230cdc48cSJosh Durgin 96330cdc48cSJosh Durgin return 0; 96430cdc48cSJosh Durgin } 96530cdc48cSJosh Durgin 966ad32e9c0SJosh Durgin static int qemu_rbd_snap_create(BlockDriverState *bs, 967ad32e9c0SJosh Durgin QEMUSnapshotInfo *sn_info) 968f27aaf4bSChristian Brunner { 969f27aaf4bSChristian Brunner BDRVRBDState *s = bs->opaque; 970f27aaf4bSChristian Brunner int r; 971f27aaf4bSChristian Brunner 972f27aaf4bSChristian Brunner if (sn_info->name[0] == '\0') { 973f27aaf4bSChristian Brunner return -EINVAL; /* we need a name for rbd snapshots */ 974f27aaf4bSChristian Brunner } 975f27aaf4bSChristian Brunner 976f27aaf4bSChristian Brunner /* 977f27aaf4bSChristian Brunner * rbd snapshots are using the name as the user controlled unique identifier 978f27aaf4bSChristian Brunner * we can't use the rbd snapid for that purpose, as it can't be set 979f27aaf4bSChristian Brunner */ 980f27aaf4bSChristian Brunner if (sn_info->id_str[0] != '\0' && 981f27aaf4bSChristian Brunner strcmp(sn_info->id_str, sn_info->name) != 0) { 982f27aaf4bSChristian Brunner return -EINVAL; 983f27aaf4bSChristian Brunner } 984f27aaf4bSChristian Brunner 985f27aaf4bSChristian Brunner if (strlen(sn_info->name) >= sizeof(sn_info->id_str)) { 986f27aaf4bSChristian Brunner return -ERANGE; 987f27aaf4bSChristian Brunner } 988f27aaf4bSChristian Brunner 989ad32e9c0SJosh Durgin r = rbd_snap_create(s->image, sn_info->name); 990f27aaf4bSChristian Brunner if (r < 0) { 991ad32e9c0SJosh Durgin error_report("failed to create snap: %s", strerror(-r)); 992f27aaf4bSChristian Brunner return r; 993f27aaf4bSChristian Brunner } 994f27aaf4bSChristian Brunner 995f27aaf4bSChristian Brunner return 0; 996f27aaf4bSChristian Brunner } 997f27aaf4bSChristian Brunner 998bd603247SGregory Farnum static int qemu_rbd_snap_remove(BlockDriverState *bs, 999a89d89d3SWenchao Xia const char *snapshot_id, 1000a89d89d3SWenchao Xia const char *snapshot_name, 1001a89d89d3SWenchao Xia Error **errp) 1002bd603247SGregory Farnum { 1003bd603247SGregory Farnum BDRVRBDState *s = bs->opaque; 1004bd603247SGregory Farnum int r; 1005bd603247SGregory Farnum 1006a89d89d3SWenchao Xia if (!snapshot_name) { 1007a89d89d3SWenchao Xia error_setg(errp, "rbd need a valid snapshot name"); 1008a89d89d3SWenchao Xia return -EINVAL; 1009a89d89d3SWenchao Xia } 1010a89d89d3SWenchao Xia 1011a89d89d3SWenchao Xia /* If snapshot_id is specified, it must be equal to name, see 1012a89d89d3SWenchao Xia qemu_rbd_snap_list() */ 1013a89d89d3SWenchao Xia if (snapshot_id && strcmp(snapshot_id, snapshot_name)) { 1014a89d89d3SWenchao Xia error_setg(errp, 1015a89d89d3SWenchao Xia "rbd do not support snapshot id, it should be NULL or " 1016a89d89d3SWenchao Xia "equal to snapshot name"); 1017a89d89d3SWenchao Xia return -EINVAL; 1018a89d89d3SWenchao Xia } 1019a89d89d3SWenchao Xia 1020bd603247SGregory Farnum r = rbd_snap_remove(s->image, snapshot_name); 1021a89d89d3SWenchao Xia if (r < 0) { 1022a89d89d3SWenchao Xia error_setg_errno(errp, -r, "Failed to remove the snapshot"); 1023a89d89d3SWenchao Xia } 1024bd603247SGregory Farnum return r; 1025bd603247SGregory Farnum } 1026bd603247SGregory Farnum 1027bd603247SGregory Farnum static int qemu_rbd_snap_rollback(BlockDriverState *bs, 1028bd603247SGregory Farnum const char *snapshot_name) 1029bd603247SGregory Farnum { 1030bd603247SGregory Farnum BDRVRBDState *s = bs->opaque; 1031bd603247SGregory Farnum 10329be38598SEduardo Habkost return rbd_snap_rollback(s->image, snapshot_name); 1033bd603247SGregory Farnum } 1034bd603247SGregory Farnum 1035ad32e9c0SJosh Durgin static int qemu_rbd_snap_list(BlockDriverState *bs, 1036ad32e9c0SJosh Durgin QEMUSnapshotInfo **psn_tab) 1037f27aaf4bSChristian Brunner { 1038f27aaf4bSChristian Brunner BDRVRBDState *s = bs->opaque; 1039f27aaf4bSChristian Brunner QEMUSnapshotInfo *sn_info, *sn_tab = NULL; 1040ad32e9c0SJosh Durgin int i, snap_count; 1041ad32e9c0SJosh Durgin rbd_snap_info_t *snaps; 1042ad32e9c0SJosh Durgin int max_snaps = RBD_MAX_SNAPS; 1043f27aaf4bSChristian Brunner 1044ad32e9c0SJosh Durgin do { 104502c4f26bSMarkus Armbruster snaps = g_new(rbd_snap_info_t, max_snaps); 1046ad32e9c0SJosh Durgin snap_count = rbd_snap_list(s->image, snaps, &max_snaps); 10479e6337d0SStefan Hajnoczi if (snap_count <= 0) { 10487267c094SAnthony Liguori g_free(snaps); 1049f27aaf4bSChristian Brunner } 1050ad32e9c0SJosh Durgin } while (snap_count == -ERANGE); 1051f27aaf4bSChristian Brunner 1052ad32e9c0SJosh Durgin if (snap_count <= 0) { 1053b9c53290SJosh Durgin goto done; 1054f27aaf4bSChristian Brunner } 1055f27aaf4bSChristian Brunner 10565839e53bSMarkus Armbruster sn_tab = g_new0(QEMUSnapshotInfo, snap_count); 1057f27aaf4bSChristian Brunner 1058ad32e9c0SJosh Durgin for (i = 0; i < snap_count; i++) { 1059ad32e9c0SJosh Durgin const char *snap_name = snaps[i].name; 1060f27aaf4bSChristian Brunner 1061f27aaf4bSChristian Brunner sn_info = sn_tab + i; 1062f27aaf4bSChristian Brunner pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), snap_name); 1063f27aaf4bSChristian Brunner pstrcpy(sn_info->name, sizeof(sn_info->name), snap_name); 1064f27aaf4bSChristian Brunner 1065ad32e9c0SJosh Durgin sn_info->vm_state_size = snaps[i].size; 1066f27aaf4bSChristian Brunner sn_info->date_sec = 0; 1067f27aaf4bSChristian Brunner sn_info->date_nsec = 0; 1068f27aaf4bSChristian Brunner sn_info->vm_clock_nsec = 0; 1069f27aaf4bSChristian Brunner } 1070ad32e9c0SJosh Durgin rbd_snap_list_end(snaps); 10719e6337d0SStefan Hajnoczi g_free(snaps); 1072ad32e9c0SJosh Durgin 1073b9c53290SJosh Durgin done: 1074f27aaf4bSChristian Brunner *psn_tab = sn_tab; 1075f27aaf4bSChristian Brunner return snap_count; 1076f27aaf4bSChristian Brunner } 1077f27aaf4bSChristian Brunner 1078787f3133SJosh Durgin #ifdef LIBRBD_SUPPORTS_DISCARD 10794da444a0SEric Blake static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverState *bs, 10804da444a0SEric Blake int64_t offset, 1081f5a5ca79SManos Pitsidianakis int bytes, 1082097310b5SMarkus Armbruster BlockCompletionFunc *cb, 1083787f3133SJosh Durgin void *opaque) 1084787f3133SJosh Durgin { 1085f5a5ca79SManos Pitsidianakis return rbd_start_aio(bs, offset, NULL, bytes, cb, opaque, 1086787f3133SJosh Durgin RBD_AIO_DISCARD); 1087787f3133SJosh Durgin } 1088787f3133SJosh Durgin #endif 1089787f3133SJosh Durgin 1090be217884SAdam Crume #ifdef LIBRBD_SUPPORTS_INVALIDATE 1091be217884SAdam Crume static void qemu_rbd_invalidate_cache(BlockDriverState *bs, 1092be217884SAdam Crume Error **errp) 1093be217884SAdam Crume { 1094be217884SAdam Crume BDRVRBDState *s = bs->opaque; 1095be217884SAdam Crume int r = rbd_invalidate_cache(s->image); 1096be217884SAdam Crume if (r < 0) { 1097be217884SAdam Crume error_setg_errno(errp, -r, "Failed to invalidate the cache"); 1098be217884SAdam Crume } 1099be217884SAdam Crume } 1100be217884SAdam Crume #endif 1101be217884SAdam Crume 1102bd0cf596SChunyan Liu static QemuOptsList qemu_rbd_create_opts = { 1103bd0cf596SChunyan Liu .name = "rbd-create-opts", 1104bd0cf596SChunyan Liu .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head), 1105bd0cf596SChunyan Liu .desc = { 1106f27aaf4bSChristian Brunner { 1107f27aaf4bSChristian Brunner .name = BLOCK_OPT_SIZE, 1108bd0cf596SChunyan Liu .type = QEMU_OPT_SIZE, 1109f27aaf4bSChristian Brunner .help = "Virtual disk size" 1110f27aaf4bSChristian Brunner }, 1111f27aaf4bSChristian Brunner { 1112f27aaf4bSChristian Brunner .name = BLOCK_OPT_CLUSTER_SIZE, 1113bd0cf596SChunyan Liu .type = QEMU_OPT_SIZE, 1114f27aaf4bSChristian Brunner .help = "RBD object size" 1115f27aaf4bSChristian Brunner }, 111660390a21SDaniel P. Berrange { 111760390a21SDaniel P. Berrange .name = "password-secret", 111860390a21SDaniel P. Berrange .type = QEMU_OPT_STRING, 111960390a21SDaniel P. Berrange .help = "ID of secret providing the password", 112060390a21SDaniel P. Berrange }, 1121bd0cf596SChunyan Liu { /* end of list */ } 1122bd0cf596SChunyan Liu } 1123f27aaf4bSChristian Brunner }; 1124f27aaf4bSChristian Brunner 1125f27aaf4bSChristian Brunner static BlockDriver bdrv_rbd = { 1126f27aaf4bSChristian Brunner .format_name = "rbd", 1127f27aaf4bSChristian Brunner .instance_size = sizeof(BDRVRBDState), 1128c7cacb3eSJeff Cody .bdrv_parse_filename = qemu_rbd_parse_filename, 1129ad32e9c0SJosh Durgin .bdrv_file_open = qemu_rbd_open, 1130ad32e9c0SJosh Durgin .bdrv_close = qemu_rbd_close, 113156e7cf8dSJeff Cody .bdrv_reopen_prepare = qemu_rbd_reopen_prepare, 1132c282e1fdSChunyan Liu .bdrv_create = qemu_rbd_create, 11333ac21627SPeter Lieven .bdrv_has_zero_init = bdrv_has_zero_init_1, 1134ad32e9c0SJosh Durgin .bdrv_get_info = qemu_rbd_getinfo, 1135bd0cf596SChunyan Liu .create_opts = &qemu_rbd_create_opts, 1136ad32e9c0SJosh Durgin .bdrv_getlength = qemu_rbd_getlength, 113730cdc48cSJosh Durgin .bdrv_truncate = qemu_rbd_truncate, 1138f27aaf4bSChristian Brunner .protocol_name = "rbd", 1139f27aaf4bSChristian Brunner 1140ad32e9c0SJosh Durgin .bdrv_aio_readv = qemu_rbd_aio_readv, 1141ad32e9c0SJosh Durgin .bdrv_aio_writev = qemu_rbd_aio_writev, 1142dc7588c1SJosh Durgin 1143dc7588c1SJosh Durgin #ifdef LIBRBD_SUPPORTS_AIO_FLUSH 1144dc7588c1SJosh Durgin .bdrv_aio_flush = qemu_rbd_aio_flush, 1145dc7588c1SJosh Durgin #else 1146c68b89acSKevin Wolf .bdrv_co_flush_to_disk = qemu_rbd_co_flush, 1147dc7588c1SJosh Durgin #endif 1148f27aaf4bSChristian Brunner 1149787f3133SJosh Durgin #ifdef LIBRBD_SUPPORTS_DISCARD 11504da444a0SEric Blake .bdrv_aio_pdiscard = qemu_rbd_aio_pdiscard, 1151787f3133SJosh Durgin #endif 1152787f3133SJosh Durgin 1153ad32e9c0SJosh Durgin .bdrv_snapshot_create = qemu_rbd_snap_create, 1154bd603247SGregory Farnum .bdrv_snapshot_delete = qemu_rbd_snap_remove, 1155ad32e9c0SJosh Durgin .bdrv_snapshot_list = qemu_rbd_snap_list, 1156bd603247SGregory Farnum .bdrv_snapshot_goto = qemu_rbd_snap_rollback, 1157be217884SAdam Crume #ifdef LIBRBD_SUPPORTS_INVALIDATE 1158be217884SAdam Crume .bdrv_invalidate_cache = qemu_rbd_invalidate_cache, 1159be217884SAdam Crume #endif 1160f27aaf4bSChristian Brunner }; 1161f27aaf4bSChristian Brunner 1162f27aaf4bSChristian Brunner static void bdrv_rbd_init(void) 1163f27aaf4bSChristian Brunner { 1164f27aaf4bSChristian Brunner bdrv_register(&bdrv_rbd); 1165f27aaf4bSChristian Brunner } 1166f27aaf4bSChristian Brunner 1167f27aaf4bSChristian Brunner block_init(bdrv_rbd_init); 1168