Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Block driver for RADOS (Ceph) |
| 3 | * |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 4 | * Copyright (C) 2010-2011 Christian Brunner <chb@muc.de>, |
| 5 | * Josh Durgin <josh.durgin@dreamhost.com> |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 6 | * |
| 7 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 8 | * the COPYING file in the top-level directory. |
| 9 | * |
Paolo Bonzini | 6b620ca | 2012-01-13 17:44:23 +0100 | [diff] [blame] | 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. |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
Peter Maydell | 80c71a2 | 2016-01-18 18:01:42 +0000 | [diff] [blame] | 14 | #include "qemu/osdep.h" |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 15 | |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 16 | #include <rbd/librbd.h> |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 17 | #include "qapi/error.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 18 | #include "qemu/error-report.h" |
Paolo Bonzini | 737e150 | 2012-12-17 18:19:44 +0100 | [diff] [blame] | 19 | #include "block/block_int.h" |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 20 | #include "crypto/secret.h" |
Veronia Bahaa | f348b6d | 2016-03-20 19:16:19 +0200 | [diff] [blame] | 21 | #include "qemu/cutils.h" |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 22 | #include "qapi/qmp/qstring.h" |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 23 | #include "qapi/qmp/qjson.h" |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 24 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 25 | /* |
| 26 | * When specifying the image filename use: |
| 27 | * |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 28 | * rbd:poolname/devicename[@snapshotname][:option1=value1[:option2=value2...]] |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 29 | * |
Sage Weil | 9e1fbcd | 2011-09-15 14:11:10 -0700 | [diff] [blame] | 30 | * poolname must be the name of an existing rados pool. |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 31 | * |
Sage Weil | 9e1fbcd | 2011-09-15 14:11:10 -0700 | [diff] [blame] | 32 | * devicename is the name of the rbd image. |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 33 | * |
Sage Weil | 9e1fbcd | 2011-09-15 14:11:10 -0700 | [diff] [blame] | 34 | * Each option given is used to configure rados, and may be any valid |
| 35 | * Ceph option, "id", or "conf". |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 36 | * |
Sage Weil | 9e1fbcd | 2011-09-15 14:11:10 -0700 | [diff] [blame] | 37 | * The "id" option indicates what user we should authenticate as to |
| 38 | * the Ceph cluster. If it is excluded we will use the Ceph default |
| 39 | * (normally 'admin'). |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 40 | * |
Sage Weil | 9e1fbcd | 2011-09-15 14:11:10 -0700 | [diff] [blame] | 41 | * The "conf" option specifies a Ceph configuration file to read. If |
| 42 | * it is not specified, we will read from the default Ceph locations |
| 43 | * (e.g., /etc/ceph/ceph.conf). To avoid reading _any_ configuration |
| 44 | * file, specify conf=/dev/null. |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 45 | * |
Sage Weil | 9e1fbcd | 2011-09-15 14:11:10 -0700 | [diff] [blame] | 46 | * Configuration values containing :, @, or = can be escaped with a |
| 47 | * leading "\". |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 48 | */ |
| 49 | |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 50 | /* rbd_aio_discard added in 0.1.2 */ |
| 51 | #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 2) |
| 52 | #define LIBRBD_SUPPORTS_DISCARD |
| 53 | #else |
| 54 | #undef LIBRBD_SUPPORTS_DISCARD |
| 55 | #endif |
| 56 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 57 | #define OBJ_MAX_SIZE (1UL << OBJ_DEFAULT_OBJ_ORDER) |
| 58 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 59 | #define RBD_MAX_SNAPS 100 |
| 60 | |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 61 | /* The LIBRBD_SUPPORTS_IOVEC is defined in librbd.h */ |
| 62 | #ifdef LIBRBD_SUPPORTS_IOVEC |
| 63 | #define LIBRBD_USE_IOVEC 1 |
| 64 | #else |
| 65 | #define LIBRBD_USE_IOVEC 0 |
| 66 | #endif |
| 67 | |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 68 | typedef enum { |
| 69 | RBD_AIO_READ, |
| 70 | RBD_AIO_WRITE, |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 71 | RBD_AIO_DISCARD, |
| 72 | RBD_AIO_FLUSH |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 73 | } RBDAIOCmd; |
| 74 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 75 | typedef struct RBDAIOCB { |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 76 | BlockAIOCB common; |
Stefan Priebe | 08448d5 | 2012-11-20 13:44:55 +0100 | [diff] [blame] | 77 | int64_t ret; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 78 | QEMUIOVector *qiov; |
| 79 | char *bounce; |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 80 | RBDAIOCmd cmd; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 81 | int error; |
| 82 | struct BDRVRBDState *s; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 83 | } RBDAIOCB; |
| 84 | |
| 85 | typedef struct RADOSCB { |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 86 | RBDAIOCB *acb; |
| 87 | struct BDRVRBDState *s; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 88 | int64_t size; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 89 | char *buf; |
Stefan Priebe | 08448d5 | 2012-11-20 13:44:55 +0100 | [diff] [blame] | 90 | int64_t ret; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 91 | } RADOSCB; |
| 92 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 93 | typedef struct BDRVRBDState { |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 94 | rados_t cluster; |
| 95 | rados_ioctx_t io_ctx; |
| 96 | rbd_image_t image; |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 97 | char *image_name; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 98 | char *snap; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 99 | } BDRVRBDState; |
| 100 | |
Markus Armbruster | 730b00b | 2017-03-28 10:56:01 +0200 | [diff] [blame] | 101 | static char *qemu_rbd_next_tok(char *src, char delim, char **p) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 102 | { |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 103 | char *end; |
| 104 | |
| 105 | *p = NULL; |
| 106 | |
Markus Armbruster | 8efb339 | 2017-03-28 10:56:02 +0200 | [diff] [blame] | 107 | for (end = src; *end; ++end) { |
Sage Weil | 16a06b2 | 2011-09-19 13:35:26 -0700 | [diff] [blame] | 108 | if (*end == delim) { |
Markus Armbruster | 8efb339 | 2017-03-28 10:56:02 +0200 | [diff] [blame] | 109 | break; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 110 | } |
Markus Armbruster | 8efb339 | 2017-03-28 10:56:02 +0200 | [diff] [blame] | 111 | if (*end == '\\' && end[1] != '\0') { |
| 112 | end++; |
| 113 | } |
| 114 | } |
| 115 | if (*end == delim) { |
| 116 | *p = end + 1; |
| 117 | *end = '\0'; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 118 | } |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 119 | return src; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Sage Weil | 16a06b2 | 2011-09-19 13:35:26 -0700 | [diff] [blame] | 122 | static void qemu_rbd_unescape(char *src) |
| 123 | { |
| 124 | char *p; |
| 125 | |
| 126 | for (p = src; *src; ++src, ++p) { |
| 127 | if (*src == '\\' && src[1] != '\0') { |
| 128 | src++; |
| 129 | } |
| 130 | *p = *src; |
| 131 | } |
| 132 | *p = '\0'; |
| 133 | } |
| 134 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 135 | static void qemu_rbd_parse_filename(const char *filename, QDict *options, |
| 136 | Error **errp) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 137 | { |
| 138 | const char *start; |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 139 | char *p, *buf; |
| 140 | QList *keypairs = NULL; |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 141 | char *found_str; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 142 | |
| 143 | if (!strstart(filename, "rbd:", &start)) { |
Markus Armbruster | d61563b | 2014-05-16 11:00:11 +0200 | [diff] [blame] | 144 | error_setg(errp, "File name must start with 'rbd:'"); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 145 | return; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 148 | buf = g_strdup(start); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 149 | p = buf; |
| 150 | |
Markus Armbruster | 730b00b | 2017-03-28 10:56:01 +0200 | [diff] [blame] | 151 | found_str = qemu_rbd_next_tok(p, '/', &p); |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 152 | if (!p) { |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 153 | error_setg(errp, "Pool name is required"); |
| 154 | goto done; |
| 155 | } |
| 156 | qemu_rbd_unescape(found_str); |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 157 | qdict_put_str(options, "pool", found_str); |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 158 | |
| 159 | if (strchr(p, '@')) { |
Markus Armbruster | 730b00b | 2017-03-28 10:56:01 +0200 | [diff] [blame] | 160 | found_str = qemu_rbd_next_tok(p, '@', &p); |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 161 | qemu_rbd_unescape(found_str); |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 162 | qdict_put_str(options, "image", found_str); |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 163 | |
Markus Armbruster | 730b00b | 2017-03-28 10:56:01 +0200 | [diff] [blame] | 164 | found_str = qemu_rbd_next_tok(p, ':', &p); |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 165 | qemu_rbd_unescape(found_str); |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 166 | qdict_put_str(options, "snapshot", found_str); |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 167 | } else { |
Markus Armbruster | 730b00b | 2017-03-28 10:56:01 +0200 | [diff] [blame] | 168 | found_str = qemu_rbd_next_tok(p, ':', &p); |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 169 | qemu_rbd_unescape(found_str); |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 170 | qdict_put_str(options, "image", found_str); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 171 | } |
Jeff Cody | 7830f90 | 2017-02-24 10:30:33 -0500 | [diff] [blame] | 172 | if (!p) { |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 173 | goto done; |
| 174 | } |
| 175 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 176 | /* The following are essentially all key/value pairs, and we treat |
| 177 | * 'id' and 'conf' a bit special. Key/value pairs may be in any order. */ |
| 178 | while (p) { |
| 179 | char *name, *value; |
Markus Armbruster | 730b00b | 2017-03-28 10:56:01 +0200 | [diff] [blame] | 180 | name = qemu_rbd_next_tok(p, '=', &p); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 181 | if (!p) { |
| 182 | error_setg(errp, "conf option %s has no value", name); |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | qemu_rbd_unescape(name); |
| 187 | |
Markus Armbruster | 730b00b | 2017-03-28 10:56:01 +0200 | [diff] [blame] | 188 | value = qemu_rbd_next_tok(p, ':', &p); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 189 | qemu_rbd_unescape(value); |
| 190 | |
| 191 | if (!strcmp(name, "conf")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 192 | qdict_put_str(options, "conf", value); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 193 | } else if (!strcmp(name, "id")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 194 | qdict_put_str(options, "user", value); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 195 | } else { |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 196 | /* |
| 197 | * We pass these internally to qemu_rbd_set_keypairs(), so |
| 198 | * we can get away with the simpler list of [ "key1", |
| 199 | * "value1", "key2", "value2" ] rather than a raw dict |
| 200 | * { "key1": "value1", "key2": "value2" } where we can't |
| 201 | * guarantee order, or even a more correct but complex |
| 202 | * [ { "key1": "value1" }, { "key2": "value2" } ] |
| 203 | */ |
| 204 | if (!keypairs) { |
| 205 | keypairs = qlist_new(); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 206 | } |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 207 | qlist_append_str(keypairs, name); |
| 208 | qlist_append_str(keypairs, value); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 212 | if (keypairs) { |
| 213 | qdict_put(options, "=keyvalue-pairs", |
| 214 | qobject_to_json(QOBJECT(keypairs))); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 217 | done: |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 218 | g_free(buf); |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 219 | QDECREF(keypairs); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 220 | return; |
Sage Weil | 7c7e9df | 2011-09-07 09:28:04 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 223 | |
| 224 | static int qemu_rbd_set_auth(rados_t cluster, const char *secretid, |
| 225 | Error **errp) |
| 226 | { |
| 227 | if (secretid == 0) { |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | gchar *secret = qcrypto_secret_lookup_as_base64(secretid, |
| 232 | errp); |
| 233 | if (!secret) { |
| 234 | return -1; |
| 235 | } |
| 236 | |
| 237 | rados_conf_set(cluster, "key", secret); |
| 238 | g_free(secret); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 243 | static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs_json, |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 244 | Error **errp) |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 245 | { |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 246 | QList *keypairs; |
| 247 | QString *name; |
| 248 | QString *value; |
| 249 | const char *key; |
| 250 | size_t remaining; |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 251 | int ret = 0; |
| 252 | |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 253 | if (!keypairs_json) { |
| 254 | return ret; |
| 255 | } |
| 256 | keypairs = qobject_to_qlist(qobject_from_json(keypairs_json, |
| 257 | &error_abort)); |
| 258 | remaining = qlist_size(keypairs) / 2; |
| 259 | assert(remaining); |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 260 | |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 261 | while (remaining--) { |
| 262 | name = qobject_to_qstring(qlist_pop(keypairs)); |
| 263 | value = qobject_to_qstring(qlist_pop(keypairs)); |
| 264 | assert(name && value); |
| 265 | key = qstring_get_str(name); |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 266 | |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 267 | ret = rados_conf_set(cluster, key, qstring_get_str(value)); |
| 268 | QDECREF(name); |
| 269 | QDECREF(value); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 270 | if (ret < 0) { |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 271 | error_setg_errno(errp, -ret, "invalid conf option %s", key); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 272 | ret = -EINVAL; |
| 273 | break; |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Eric Blake | e98c696 | 2017-03-31 10:27:30 -0500 | [diff] [blame] | 277 | QDECREF(keypairs); |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 278 | return ret; |
| 279 | } |
| 280 | |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 281 | static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs) |
| 282 | { |
| 283 | if (LIBRBD_USE_IOVEC) { |
| 284 | RBDAIOCB *acb = rcb->acb; |
| 285 | iov_memset(acb->qiov->iov, acb->qiov->niov, offs, 0, |
| 286 | acb->qiov->size - offs); |
| 287 | } else { |
| 288 | memset(rcb->buf + offs, 0, rcb->size - offs); |
| 289 | } |
| 290 | } |
| 291 | |
Jeff Cody | 0f9d252 | 2017-02-27 01:03:53 -0500 | [diff] [blame] | 292 | static QemuOptsList runtime_opts = { |
| 293 | .name = "rbd", |
| 294 | .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), |
| 295 | .desc = { |
| 296 | { |
Jeff Cody | 0f9d252 | 2017-02-27 01:03:53 -0500 | [diff] [blame] | 297 | .name = "pool", |
| 298 | .type = QEMU_OPT_STRING, |
| 299 | .help = "Rados pool name", |
| 300 | }, |
| 301 | { |
| 302 | .name = "image", |
| 303 | .type = QEMU_OPT_STRING, |
| 304 | .help = "Image name in the pool", |
| 305 | }, |
| 306 | { |
Markus Armbruster | cbf036b | 2017-03-28 10:56:04 +0200 | [diff] [blame] | 307 | .name = "conf", |
| 308 | .type = QEMU_OPT_STRING, |
| 309 | .help = "Rados config file location", |
| 310 | }, |
| 311 | { |
Jeff Cody | 0f9d252 | 2017-02-27 01:03:53 -0500 | [diff] [blame] | 312 | .name = "snapshot", |
| 313 | .type = QEMU_OPT_STRING, |
| 314 | .help = "Ceph snapshot name", |
| 315 | }, |
| 316 | { |
| 317 | /* maps to 'id' in rados_create() */ |
| 318 | .name = "user", |
| 319 | .type = QEMU_OPT_STRING, |
| 320 | .help = "Rados id name", |
| 321 | }, |
Markus Armbruster | cbf036b | 2017-03-28 10:56:04 +0200 | [diff] [blame] | 322 | /* |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 323 | * server.* extracted manually, see qemu_rbd_mon_host() |
Markus Armbruster | cbf036b | 2017-03-28 10:56:04 +0200 | [diff] [blame] | 324 | */ |
| 325 | { |
| 326 | .name = "password-secret", |
| 327 | .type = QEMU_OPT_STRING, |
| 328 | .help = "ID of secret providing the password", |
| 329 | }, |
| 330 | |
| 331 | /* |
| 332 | * Keys for qemu_rbd_parse_filename(), not in the QAPI schema |
| 333 | */ |
Jeff Cody | 0f9d252 | 2017-02-27 01:03:53 -0500 | [diff] [blame] | 334 | { |
Markus Armbruster | 82f20e8 | 2017-03-28 10:56:03 +0200 | [diff] [blame] | 335 | /* |
| 336 | * HACK: name starts with '=' so that qemu_opts_parse() |
| 337 | * can't set it |
| 338 | */ |
| 339 | .name = "=keyvalue-pairs", |
Jeff Cody | 0f9d252 | 2017-02-27 01:03:53 -0500 | [diff] [blame] | 340 | .type = QEMU_OPT_STRING, |
| 341 | .help = "Legacy rados key/value option parameters", |
| 342 | }, |
Jeff Cody | 91589d9 | 2017-06-14 08:53:19 -0400 | [diff] [blame] | 343 | { |
| 344 | .name = "filename", |
| 345 | .type = QEMU_OPT_STRING, |
| 346 | }, |
Jeff Cody | 0f9d252 | 2017-02-27 01:03:53 -0500 | [diff] [blame] | 347 | { /* end of list */ } |
| 348 | }, |
| 349 | }; |
| 350 | |
Chunyan Liu | bd0cf59 | 2014-06-05 17:21:04 +0800 | [diff] [blame] | 351 | static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 352 | { |
Markus Armbruster | d61563b | 2014-05-16 11:00:11 +0200 | [diff] [blame] | 353 | Error *local_err = NULL; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 354 | int64_t bytes = 0; |
| 355 | int64_t objsize; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 356 | int obj_order = 0; |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 357 | const char *pool, *image_name, *conf, *user, *keypairs; |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 358 | const char *secretid; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 359 | rados_t cluster; |
| 360 | rados_ioctx_t io_ctx; |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 361 | QDict *options = NULL; |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 362 | int ret = 0; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 363 | |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 364 | secretid = qemu_opt_get(opts, "password-secret"); |
| 365 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 366 | /* Read out options */ |
Hu Tao | c2eb918 | 2014-09-10 17:05:45 +0800 | [diff] [blame] | 367 | bytes = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), |
| 368 | BDRV_SECTOR_SIZE); |
Chunyan Liu | bd0cf59 | 2014-06-05 17:21:04 +0800 | [diff] [blame] | 369 | objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0); |
| 370 | if (objsize) { |
| 371 | if ((objsize - 1) & objsize) { /* not a power of 2? */ |
| 372 | error_setg(errp, "obj size needs to be power of 2"); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 373 | ret = -EINVAL; |
| 374 | goto exit; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 375 | } |
Chunyan Liu | bd0cf59 | 2014-06-05 17:21:04 +0800 | [diff] [blame] | 376 | if (objsize < 4096) { |
| 377 | error_setg(errp, "obj size too small"); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 378 | ret = -EINVAL; |
| 379 | goto exit; |
Chunyan Liu | bd0cf59 | 2014-06-05 17:21:04 +0800 | [diff] [blame] | 380 | } |
Stefan Hajnoczi | 786a4ea | 2015-03-23 15:29:26 +0000 | [diff] [blame] | 381 | obj_order = ctz32(objsize); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 384 | options = qdict_new(); |
| 385 | qemu_rbd_parse_filename(filename, options, &local_err); |
| 386 | if (local_err) { |
| 387 | ret = -EINVAL; |
| 388 | error_propagate(errp, local_err); |
| 389 | goto exit; |
| 390 | } |
| 391 | |
Markus Armbruster | 129c7d1 | 2017-03-30 19:43:12 +0200 | [diff] [blame] | 392 | /* |
| 393 | * Caution: while qdict_get_try_str() is fine, getting non-string |
| 394 | * types would require more care. When @options come from -blockdev |
| 395 | * or blockdev_add, its members are typed according to the QAPI |
| 396 | * schema, but when they come from -drive, they're all QString. |
| 397 | */ |
Markus Armbruster | 0784639 | 2017-03-28 10:56:05 +0200 | [diff] [blame] | 398 | pool = qdict_get_try_str(options, "pool"); |
| 399 | conf = qdict_get_try_str(options, "conf"); |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 400 | user = qdict_get_try_str(options, "user"); |
| 401 | image_name = qdict_get_try_str(options, "image"); |
Markus Armbruster | 0784639 | 2017-03-28 10:56:05 +0200 | [diff] [blame] | 402 | keypairs = qdict_get_try_str(options, "=keyvalue-pairs"); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 403 | |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 404 | ret = rados_create(&cluster, user); |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 405 | if (ret < 0) { |
| 406 | error_setg_errno(errp, -ret, "error initializing"); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 407 | goto exit; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 410 | /* try default location when conf=NULL, but ignore failure */ |
| 411 | ret = rados_conf_read_file(cluster, conf); |
| 412 | if (conf && ret < 0) { |
| 413 | error_setg_errno(errp, -ret, "error reading conf file %s", conf); |
Xiubo Li | e38f643 | 2016-10-15 16:26:13 +0800 | [diff] [blame] | 414 | ret = -EIO; |
| 415 | goto shutdown; |
Josh Durgin | fab5cf5 | 2011-05-26 16:07:32 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 418 | ret = qemu_rbd_set_keypairs(cluster, keypairs, errp); |
| 419 | if (ret < 0) { |
Xiubo Li | e38f643 | 2016-10-15 16:26:13 +0800 | [diff] [blame] | 420 | ret = -EIO; |
| 421 | goto shutdown; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 424 | if (qemu_rbd_set_auth(cluster, secretid, errp) < 0) { |
Xiubo Li | e38f643 | 2016-10-15 16:26:13 +0800 | [diff] [blame] | 425 | ret = -EIO; |
| 426 | goto shutdown; |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 429 | ret = rados_connect(cluster); |
| 430 | if (ret < 0) { |
| 431 | error_setg_errno(errp, -ret, "error connecting"); |
Xiubo Li | e38f643 | 2016-10-15 16:26:13 +0800 | [diff] [blame] | 432 | goto shutdown; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 435 | ret = rados_ioctx_create(cluster, pool, &io_ctx); |
| 436 | if (ret < 0) { |
| 437 | error_setg_errno(errp, -ret, "error opening pool %s", pool); |
Xiubo Li | e38f643 | 2016-10-15 16:26:13 +0800 | [diff] [blame] | 438 | goto shutdown; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 441 | ret = rbd_create(io_ctx, image_name, bytes, &obj_order); |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 442 | if (ret < 0) { |
| 443 | error_setg_errno(errp, -ret, "error rbd create"); |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 444 | } |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 445 | |
Xiubo Li | e38f643 | 2016-10-15 16:26:13 +0800 | [diff] [blame] | 446 | rados_ioctx_destroy(io_ctx); |
| 447 | |
| 448 | shutdown: |
| 449 | rados_shutdown(cluster); |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 450 | |
| 451 | exit: |
| 452 | QDECREF(options); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 453 | return ret; |
| 454 | } |
| 455 | |
| 456 | /* |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 457 | * This aio completion is being called from rbd_finish_bh() and runs in qemu |
| 458 | * BH context. |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 459 | */ |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 460 | static void qemu_rbd_complete_aio(RADOSCB *rcb) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 461 | { |
| 462 | RBDAIOCB *acb = rcb->acb; |
| 463 | int64_t r; |
| 464 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 465 | r = rcb->ret; |
| 466 | |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 467 | if (acb->cmd != RBD_AIO_READ) { |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 468 | if (r < 0) { |
| 469 | acb->ret = r; |
| 470 | acb->error = 1; |
| 471 | } else if (!acb->error) { |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 472 | acb->ret = rcb->size; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 473 | } |
| 474 | } else { |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 475 | if (r < 0) { |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 476 | qemu_rbd_memset(rcb, 0); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 477 | acb->ret = r; |
| 478 | acb->error = 1; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 479 | } else if (r < rcb->size) { |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 480 | qemu_rbd_memset(rcb, r); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 481 | if (!acb->error) { |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 482 | acb->ret = rcb->size; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 483 | } |
| 484 | } else if (!acb->error) { |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 485 | acb->ret = r; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 486 | } |
| 487 | } |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 488 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 489 | g_free(rcb); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 490 | |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 491 | if (!LIBRBD_USE_IOVEC) { |
| 492 | if (acb->cmd == RBD_AIO_READ) { |
| 493 | qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size); |
| 494 | } |
| 495 | qemu_vfree(acb->bounce); |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 496 | } |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 497 | |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 498 | acb->common.cb(acb->common.opaque, (acb->ret > 0 ? 0 : acb->ret)); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 499 | |
Fam Zheng | 8007429 | 2014-09-11 13:41:28 +0800 | [diff] [blame] | 500 | qemu_aio_unref(acb); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 501 | } |
| 502 | |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 503 | static char *qemu_rbd_mon_host(QDict *options, Error **errp) |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 504 | { |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 505 | const char **vals = g_new(const char *, qdict_size(options) + 1); |
| 506 | char keybuf[32]; |
| 507 | const char *host, *port; |
| 508 | char *rados_str; |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 509 | int i; |
| 510 | |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 511 | for (i = 0;; i++) { |
| 512 | sprintf(keybuf, "server.%d.host", i); |
| 513 | host = qdict_get_try_str(options, keybuf); |
| 514 | qdict_del(options, keybuf); |
| 515 | sprintf(keybuf, "server.%d.port", i); |
| 516 | port = qdict_get_try_str(options, keybuf); |
| 517 | qdict_del(options, keybuf); |
| 518 | if (!host && !port) { |
| 519 | break; |
| 520 | } |
| 521 | if (!host) { |
| 522 | error_setg(errp, "Parameter server.%d.host is missing", i); |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 523 | rados_str = NULL; |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 524 | goto out; |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 525 | } |
| 526 | |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 527 | if (strchr(host, ':')) { |
| 528 | vals[i] = port ? g_strdup_printf("[%s]:%s", host, port) |
| 529 | : g_strdup_printf("[%s]", host); |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 530 | } else { |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 531 | vals[i] = port ? g_strdup_printf("%s:%s", host, port) |
| 532 | : g_strdup(host); |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 533 | } |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 534 | } |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 535 | vals[i] = NULL; |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 536 | |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 537 | rados_str = i ? g_strjoinv(";", (char **)vals) : NULL; |
| 538 | out: |
| 539 | g_strfreev((char **)vals); |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 540 | return rados_str; |
| 541 | } |
| 542 | |
Max Reitz | 015a103 | 2013-09-05 14:22:29 +0200 | [diff] [blame] | 543 | static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, |
| 544 | Error **errp) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 545 | { |
| 546 | BDRVRBDState *s = bs->opaque; |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 547 | const char *pool, *snap, *conf, *user, *image_name, *keypairs; |
Jeff Cody | 91589d9 | 2017-06-14 08:53:19 -0400 | [diff] [blame] | 548 | const char *secretid, *filename; |
Kevin Wolf | a9ccedc | 2013-04-12 18:05:35 +0200 | [diff] [blame] | 549 | QemuOpts *opts; |
| 550 | Error *local_err = NULL; |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 551 | char *mon_host = NULL; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 552 | int r; |
| 553 | |
Jeff Cody | 91589d9 | 2017-06-14 08:53:19 -0400 | [diff] [blame] | 554 | /* If we are given a filename, parse the filename, with precedence given to |
| 555 | * filename encoded options */ |
| 556 | filename = qdict_get_try_str(options, "filename"); |
| 557 | if (filename) { |
Alistair Francis | 3dc6f86 | 2017-07-12 06:57:41 -0700 | [diff] [blame] | 558 | warn_report("'filename' option specified. " |
| 559 | "This is an unsupported option, and may be deprecated " |
| 560 | "in the future"); |
Jeff Cody | 91589d9 | 2017-06-14 08:53:19 -0400 | [diff] [blame] | 561 | qemu_rbd_parse_filename(filename, options, &local_err); |
| 562 | if (local_err) { |
| 563 | r = -EINVAL; |
| 564 | error_propagate(errp, local_err); |
| 565 | goto exit; |
| 566 | } |
| 567 | } |
| 568 | |
Peter Crosthwaite | 87ea75d | 2014-01-01 18:49:17 -0800 | [diff] [blame] | 569 | opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); |
Kevin Wolf | a9ccedc | 2013-04-12 18:05:35 +0200 | [diff] [blame] | 570 | qemu_opts_absorb_qdict(opts, options, &local_err); |
Markus Armbruster | 84d18f0 | 2014-01-30 15:07:28 +0100 | [diff] [blame] | 571 | if (local_err) { |
Markus Armbruster | d61563b | 2014-05-16 11:00:11 +0200 | [diff] [blame] | 572 | error_propagate(errp, local_err); |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 573 | r = -EINVAL; |
| 574 | goto failed_opts; |
Kevin Wolf | a9ccedc | 2013-04-12 18:05:35 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Markus Armbruster | 2836284 | 2017-03-28 10:56:08 +0200 | [diff] [blame] | 577 | mon_host = qemu_rbd_mon_host(options, &local_err); |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 578 | if (local_err) { |
| 579 | error_propagate(errp, local_err); |
| 580 | r = -EINVAL; |
| 581 | goto failed_opts; |
| 582 | } |
| 583 | |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 584 | secretid = qemu_opt_get(opts, "password-secret"); |
Kevin Wolf | a9ccedc | 2013-04-12 18:05:35 +0200 | [diff] [blame] | 585 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 586 | pool = qemu_opt_get(opts, "pool"); |
| 587 | conf = qemu_opt_get(opts, "conf"); |
| 588 | snap = qemu_opt_get(opts, "snapshot"); |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 589 | user = qemu_opt_get(opts, "user"); |
| 590 | image_name = qemu_opt_get(opts, "image"); |
Markus Armbruster | 82f20e8 | 2017-03-28 10:56:03 +0200 | [diff] [blame] | 591 | keypairs = qemu_opt_get(opts, "=keyvalue-pairs"); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 592 | |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 593 | if (!pool || !image_name) { |
Markus Armbruster | f51c363 | 2017-03-28 10:56:00 +0200 | [diff] [blame] | 594 | error_setg(errp, "Parameters 'pool' and 'image' are required"); |
| 595 | r = -EINVAL; |
| 596 | goto failed_opts; |
| 597 | } |
| 598 | |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 599 | r = rados_create(&s->cluster, user); |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 600 | if (r < 0) { |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 601 | error_setg_errno(errp, -r, "error initializing"); |
Kevin Wolf | c3ca988 | 2013-04-25 15:59:27 +0200 | [diff] [blame] | 602 | goto failed_opts; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 605 | s->snap = g_strdup(snap); |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 606 | s->image_name = g_strdup(image_name); |
Sage Weil | eb93d5d | 2011-09-07 09:28:06 -0700 | [diff] [blame] | 607 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 608 | /* try default location when conf=NULL, but ignore failure */ |
| 609 | r = rados_conf_read_file(s->cluster, conf); |
| 610 | if (conf && r < 0) { |
| 611 | error_setg_errno(errp, -r, "error reading conf file %s", conf); |
| 612 | goto failed_shutdown; |
Josh Durgin | 99a3c89 | 2015-06-10 20:28:45 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 615 | r = qemu_rbd_set_keypairs(s->cluster, keypairs, errp); |
| 616 | if (r < 0) { |
| 617 | goto failed_shutdown; |
Josh Durgin | 99a3c89 | 2015-06-10 20:28:45 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 620 | if (mon_host) { |
| 621 | r = rados_conf_set(s->cluster, "mon_host", mon_host); |
| 622 | if (r < 0) { |
| 623 | goto failed_shutdown; |
| 624 | } |
| 625 | } |
| 626 | |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 627 | if (qemu_rbd_set_auth(s->cluster, secretid, errp) < 0) { |
| 628 | r = -EIO; |
| 629 | goto failed_shutdown; |
| 630 | } |
| 631 | |
Josh Durgin | b11f38f | 2012-05-17 13:42:29 -0700 | [diff] [blame] | 632 | /* |
| 633 | * Fallback to more conservative semantics if setting cache |
| 634 | * options fails. Ignore errors from setting rbd_cache because the |
| 635 | * only possible error is that the option does not exist, and |
| 636 | * librbd defaults to no caching. If write through caching cannot |
| 637 | * be set up, fall back to no caching. |
| 638 | */ |
| 639 | if (flags & BDRV_O_NOCACHE) { |
| 640 | rados_conf_set(s->cluster, "rbd_cache", "false"); |
| 641 | } else { |
| 642 | rados_conf_set(s->cluster, "rbd_cache", "true"); |
Josh Durgin | b11f38f | 2012-05-17 13:42:29 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 645 | r = rados_connect(s->cluster); |
| 646 | if (r < 0) { |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 647 | error_setg_errno(errp, -r, "error connecting"); |
Sage Weil | eb93d5d | 2011-09-07 09:28:06 -0700 | [diff] [blame] | 648 | goto failed_shutdown; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | r = rados_ioctx_create(s->cluster, pool, &s->io_ctx); |
| 652 | if (r < 0) { |
Vikhyat Umrao | 87cd3d2 | 2016-05-09 13:21:59 +0530 | [diff] [blame] | 653 | error_setg_errno(errp, -r, "error opening pool %s", pool); |
Sage Weil | eb93d5d | 2011-09-07 09:28:06 -0700 | [diff] [blame] | 654 | goto failed_shutdown; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Jeff Cody | e2b8247 | 2017-04-07 16:55:26 -0400 | [diff] [blame] | 657 | /* rbd_open is always r/w */ |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 658 | r = rbd_open(s->io_ctx, s->image_name, &s->image, s->snap); |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 659 | if (r < 0) { |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 660 | error_setg_errno(errp, -r, "error reading header from %s", |
| 661 | s->image_name); |
Sage Weil | eb93d5d | 2011-09-07 09:28:06 -0700 | [diff] [blame] | 662 | goto failed_open; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Jeff Cody | e2b8247 | 2017-04-07 16:55:26 -0400 | [diff] [blame] | 665 | /* If we are using an rbd snapshot, we must be r/o, otherwise |
| 666 | * leave as-is */ |
| 667 | if (s->snap != NULL) { |
| 668 | r = bdrv_set_read_only(bs, true, &local_err); |
| 669 | if (r < 0) { |
| 670 | error_propagate(errp, local_err); |
| 671 | goto failed_open; |
| 672 | } |
| 673 | } |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 674 | |
Kevin Wolf | c3ca988 | 2013-04-25 15:59:27 +0200 | [diff] [blame] | 675 | qemu_opts_del(opts); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 676 | return 0; |
| 677 | |
Sage Weil | eb93d5d | 2011-09-07 09:28:06 -0700 | [diff] [blame] | 678 | failed_open: |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 679 | rados_ioctx_destroy(s->io_ctx); |
Sage Weil | eb93d5d | 2011-09-07 09:28:06 -0700 | [diff] [blame] | 680 | failed_shutdown: |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 681 | rados_shutdown(s->cluster); |
Sage Weil | eb93d5d | 2011-09-07 09:28:06 -0700 | [diff] [blame] | 682 | g_free(s->snap); |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 683 | g_free(s->image_name); |
Kevin Wolf | c3ca988 | 2013-04-25 15:59:27 +0200 | [diff] [blame] | 684 | failed_opts: |
| 685 | qemu_opts_del(opts); |
Jeff Cody | 0a55679 | 2017-02-27 12:36:46 -0500 | [diff] [blame] | 686 | g_free(mon_host); |
Jeff Cody | 91589d9 | 2017-06-14 08:53:19 -0400 | [diff] [blame] | 687 | exit: |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 688 | return r; |
| 689 | } |
| 690 | |
Jeff Cody | 56e7cf8 | 2017-04-07 16:55:32 -0400 | [diff] [blame] | 691 | |
| 692 | /* Since RBD is currently always opened R/W via the API, |
| 693 | * we just need to check if we are using a snapshot or not, in |
| 694 | * order to determine if we will allow it to be R/W */ |
| 695 | static int qemu_rbd_reopen_prepare(BDRVReopenState *state, |
| 696 | BlockReopenQueue *queue, Error **errp) |
| 697 | { |
| 698 | BDRVRBDState *s = state->bs->opaque; |
| 699 | int ret = 0; |
| 700 | |
| 701 | if (s->snap && state->flags & BDRV_O_RDWR) { |
| 702 | error_setg(errp, |
| 703 | "Cannot change node '%s' to r/w when using RBD snapshot", |
| 704 | bdrv_get_device_or_node_name(state->bs)); |
| 705 | ret = -EINVAL; |
| 706 | } |
| 707 | |
| 708 | return ret; |
| 709 | } |
| 710 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 711 | static void qemu_rbd_close(BlockDriverState *bs) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 712 | { |
| 713 | BDRVRBDState *s = bs->opaque; |
| 714 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 715 | rbd_close(s->image); |
| 716 | rados_ioctx_destroy(s->io_ctx); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 717 | g_free(s->snap); |
Jeff Cody | 80b61a2 | 2017-04-07 16:55:31 -0400 | [diff] [blame] | 718 | g_free(s->image_name); |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 719 | rados_shutdown(s->cluster); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 720 | } |
| 721 | |
Stefan Hajnoczi | d7331be | 2012-10-31 16:34:37 +0100 | [diff] [blame] | 722 | static const AIOCBInfo rbd_aiocb_info = { |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 723 | .aiocb_size = sizeof(RBDAIOCB), |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 724 | }; |
| 725 | |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 726 | static void rbd_finish_bh(void *opaque) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 727 | { |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 728 | RADOSCB *rcb = opaque; |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 729 | qemu_rbd_complete_aio(rcb); |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* |
| 733 | * This is the callback function for rbd_aio_read and _write |
| 734 | * |
| 735 | * Note: this function is being called from a non qemu thread so |
| 736 | * we need to be careful about what we do here. Generally we only |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 737 | * schedule a BH, and do the rest of the io completion handling |
| 738 | * from rbd_finish_bh() which runs in a qemu context. |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 739 | */ |
| 740 | static void rbd_finish_aiocb(rbd_completion_t c, RADOSCB *rcb) |
| 741 | { |
Stefan Hajnoczi | e04fb07 | 2013-12-05 16:38:33 +0100 | [diff] [blame] | 742 | RBDAIOCB *acb = rcb->acb; |
| 743 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 744 | rcb->ret = rbd_aio_get_return_value(c); |
| 745 | rbd_aio_release(c); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 746 | |
Paolo Bonzini | fffb6e1 | 2016-10-03 18:14:16 +0200 | [diff] [blame] | 747 | aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), |
| 748 | rbd_finish_bh, rcb); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 749 | } |
| 750 | |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 751 | static int rbd_aio_discard_wrapper(rbd_image_t image, |
| 752 | uint64_t off, |
| 753 | uint64_t len, |
| 754 | rbd_completion_t comp) |
| 755 | { |
| 756 | #ifdef LIBRBD_SUPPORTS_DISCARD |
| 757 | return rbd_aio_discard(image, off, len, comp); |
| 758 | #else |
| 759 | return -ENOTSUP; |
| 760 | #endif |
| 761 | } |
| 762 | |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 763 | static int rbd_aio_flush_wrapper(rbd_image_t image, |
| 764 | rbd_completion_t comp) |
| 765 | { |
| 766 | #ifdef LIBRBD_SUPPORTS_AIO_FLUSH |
| 767 | return rbd_aio_flush(image, comp); |
| 768 | #else |
| 769 | return -ENOTSUP; |
| 770 | #endif |
| 771 | } |
| 772 | |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 773 | static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, |
Eric Blake | 7bbca9e | 2016-07-15 17:22:56 -0600 | [diff] [blame] | 774 | int64_t off, |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 775 | QEMUIOVector *qiov, |
Eric Blake | 7bbca9e | 2016-07-15 17:22:56 -0600 | [diff] [blame] | 776 | int64_t size, |
Markus Armbruster | 097310b | 2014-10-07 13:59:15 +0200 | [diff] [blame] | 777 | BlockCompletionFunc *cb, |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 778 | void *opaque, |
| 779 | RBDAIOCmd cmd) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 780 | { |
| 781 | RBDAIOCB *acb; |
Kevin Wolf | 0f7a023 | 2014-05-21 18:11:48 +0200 | [diff] [blame] | 782 | RADOSCB *rcb = NULL; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 783 | rbd_completion_t c; |
Josh Durgin | 51a1352 | 2011-05-26 16:07:33 -0700 | [diff] [blame] | 784 | int r; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 785 | |
| 786 | BDRVRBDState *s = bs->opaque; |
| 787 | |
Stefan Hajnoczi | d7331be | 2012-10-31 16:34:37 +0100 | [diff] [blame] | 788 | acb = qemu_aio_get(&rbd_aiocb_info, bs, cb, opaque); |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 789 | acb->cmd = cmd; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 790 | acb->qiov = qiov; |
Eric Blake | 7bbca9e | 2016-07-15 17:22:56 -0600 | [diff] [blame] | 791 | assert(!qiov || qiov->size == size); |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 792 | |
| 793 | rcb = g_new(RADOSCB, 1); |
| 794 | |
| 795 | if (!LIBRBD_USE_IOVEC) { |
| 796 | if (cmd == RBD_AIO_DISCARD || cmd == RBD_AIO_FLUSH) { |
| 797 | acb->bounce = NULL; |
| 798 | } else { |
| 799 | acb->bounce = qemu_try_blockalign(bs, qiov->size); |
| 800 | if (acb->bounce == NULL) { |
| 801 | goto failed; |
| 802 | } |
Kevin Wolf | 0f7a023 | 2014-05-21 18:11:48 +0200 | [diff] [blame] | 803 | } |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 804 | if (cmd == RBD_AIO_WRITE) { |
| 805 | qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size); |
| 806 | } |
| 807 | rcb->buf = acb->bounce; |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 808 | } |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 809 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 810 | acb->ret = 0; |
| 811 | acb->error = 0; |
| 812 | acb->s = s; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 813 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 814 | rcb->acb = acb; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 815 | rcb->s = acb->s; |
| 816 | rcb->size = size; |
Josh Durgin | 51a1352 | 2011-05-26 16:07:33 -0700 | [diff] [blame] | 817 | r = rbd_aio_create_completion(rcb, (rbd_callback_t) rbd_finish_aiocb, &c); |
| 818 | if (r < 0) { |
| 819 | goto failed; |
| 820 | } |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 821 | |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 822 | switch (cmd) { |
| 823 | case RBD_AIO_WRITE: |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 824 | #ifdef LIBRBD_SUPPORTS_IOVEC |
| 825 | r = rbd_aio_writev(s->image, qiov->iov, qiov->niov, off, c); |
| 826 | #else |
| 827 | r = rbd_aio_write(s->image, off, size, rcb->buf, c); |
| 828 | #endif |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 829 | break; |
| 830 | case RBD_AIO_READ: |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 831 | #ifdef LIBRBD_SUPPORTS_IOVEC |
| 832 | r = rbd_aio_readv(s->image, qiov->iov, qiov->niov, off, c); |
| 833 | #else |
| 834 | r = rbd_aio_read(s->image, off, size, rcb->buf, c); |
| 835 | #endif |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 836 | break; |
| 837 | case RBD_AIO_DISCARD: |
| 838 | r = rbd_aio_discard_wrapper(s->image, off, size, c); |
| 839 | break; |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 840 | case RBD_AIO_FLUSH: |
| 841 | r = rbd_aio_flush_wrapper(s->image, c); |
| 842 | break; |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 843 | default: |
| 844 | r = -EINVAL; |
Josh Durgin | 51a1352 | 2011-05-26 16:07:33 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | if (r < 0) { |
Kevin Wolf | 405a276 | 2014-06-05 16:19:26 +0200 | [diff] [blame] | 848 | goto failed_completion; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 849 | } |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 850 | return &acb->common; |
Josh Durgin | 51a1352 | 2011-05-26 16:07:33 -0700 | [diff] [blame] | 851 | |
Kevin Wolf | 405a276 | 2014-06-05 16:19:26 +0200 | [diff] [blame] | 852 | failed_completion: |
| 853 | rbd_aio_release(c); |
Josh Durgin | 51a1352 | 2011-05-26 16:07:33 -0700 | [diff] [blame] | 854 | failed: |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 855 | g_free(rcb); |
tianqing | 1d393bd | 2017-02-21 14:50:03 +0800 | [diff] [blame] | 856 | if (!LIBRBD_USE_IOVEC) { |
| 857 | qemu_vfree(acb->bounce); |
| 858 | } |
| 859 | |
Fam Zheng | 8007429 | 2014-09-11 13:41:28 +0800 | [diff] [blame] | 860 | qemu_aio_unref(acb); |
Josh Durgin | 51a1352 | 2011-05-26 16:07:33 -0700 | [diff] [blame] | 861 | return NULL; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 862 | } |
| 863 | |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 864 | static BlockAIOCB *qemu_rbd_aio_readv(BlockDriverState *bs, |
| 865 | int64_t sector_num, |
| 866 | QEMUIOVector *qiov, |
| 867 | int nb_sectors, |
Markus Armbruster | 097310b | 2014-10-07 13:59:15 +0200 | [diff] [blame] | 868 | BlockCompletionFunc *cb, |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 869 | void *opaque) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 870 | { |
Eric Blake | 7bbca9e | 2016-07-15 17:22:56 -0600 | [diff] [blame] | 871 | return rbd_start_aio(bs, sector_num << BDRV_SECTOR_BITS, qiov, |
Paolo Bonzini | e948f66 | 2016-10-10 21:58:58 +0200 | [diff] [blame] | 872 | (int64_t) nb_sectors << BDRV_SECTOR_BITS, cb, opaque, |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 873 | RBD_AIO_READ); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 874 | } |
| 875 | |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 876 | static BlockAIOCB *qemu_rbd_aio_writev(BlockDriverState *bs, |
| 877 | int64_t sector_num, |
| 878 | QEMUIOVector *qiov, |
| 879 | int nb_sectors, |
Markus Armbruster | 097310b | 2014-10-07 13:59:15 +0200 | [diff] [blame] | 880 | BlockCompletionFunc *cb, |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 881 | void *opaque) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 882 | { |
Eric Blake | 7bbca9e | 2016-07-15 17:22:56 -0600 | [diff] [blame] | 883 | return rbd_start_aio(bs, sector_num << BDRV_SECTOR_BITS, qiov, |
Paolo Bonzini | e948f66 | 2016-10-10 21:58:58 +0200 | [diff] [blame] | 884 | (int64_t) nb_sectors << BDRV_SECTOR_BITS, cb, opaque, |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 885 | RBD_AIO_WRITE); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 886 | } |
| 887 | |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 888 | #ifdef LIBRBD_SUPPORTS_AIO_FLUSH |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 889 | static BlockAIOCB *qemu_rbd_aio_flush(BlockDriverState *bs, |
Markus Armbruster | 097310b | 2014-10-07 13:59:15 +0200 | [diff] [blame] | 890 | BlockCompletionFunc *cb, |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 891 | void *opaque) |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 892 | { |
| 893 | return rbd_start_aio(bs, 0, NULL, 0, cb, opaque, RBD_AIO_FLUSH); |
| 894 | } |
| 895 | |
| 896 | #else |
| 897 | |
Paolo Bonzini | 8b94ff8 | 2011-10-20 13:16:24 +0200 | [diff] [blame] | 898 | static int qemu_rbd_co_flush(BlockDriverState *bs) |
Sage Weil | 7a3f5fe | 2011-09-15 14:11:11 -0700 | [diff] [blame] | 899 | { |
| 900 | #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 1) |
| 901 | /* rbd_flush added in 0.1.1 */ |
| 902 | BDRVRBDState *s = bs->opaque; |
| 903 | return rbd_flush(s->image); |
| 904 | #else |
| 905 | return 0; |
| 906 | #endif |
| 907 | } |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 908 | #endif |
Sage Weil | 7a3f5fe | 2011-09-15 14:11:11 -0700 | [diff] [blame] | 909 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 910 | static int qemu_rbd_getinfo(BlockDriverState *bs, BlockDriverInfo *bdi) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 911 | { |
| 912 | BDRVRBDState *s = bs->opaque; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 913 | rbd_image_info_t info; |
| 914 | int r; |
| 915 | |
| 916 | r = rbd_stat(s->image, &info, sizeof(info)); |
| 917 | if (r < 0) { |
| 918 | return r; |
| 919 | } |
| 920 | |
| 921 | bdi->cluster_size = info.obj_size; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 922 | return 0; |
| 923 | } |
| 924 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 925 | static int64_t qemu_rbd_getlength(BlockDriverState *bs) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 926 | { |
| 927 | BDRVRBDState *s = bs->opaque; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 928 | rbd_image_info_t info; |
| 929 | int r; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 930 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 931 | r = rbd_stat(s->image, &info, sizeof(info)); |
| 932 | if (r < 0) { |
| 933 | return r; |
| 934 | } |
| 935 | |
| 936 | return info.size; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Max Reitz | 8243ccb | 2017-06-13 22:20:52 +0200 | [diff] [blame] | 939 | static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset, |
| 940 | PreallocMode prealloc, Error **errp) |
Josh Durgin | 30cdc48 | 2011-05-26 16:07:34 -0700 | [diff] [blame] | 941 | { |
| 942 | BDRVRBDState *s = bs->opaque; |
| 943 | int r; |
| 944 | |
Max Reitz | 8243ccb | 2017-06-13 22:20:52 +0200 | [diff] [blame] | 945 | if (prealloc != PREALLOC_MODE_OFF) { |
| 946 | error_setg(errp, "Unsupported preallocation mode '%s'", |
| 947 | PreallocMode_lookup[prealloc]); |
| 948 | return -ENOTSUP; |
| 949 | } |
| 950 | |
Josh Durgin | 30cdc48 | 2011-05-26 16:07:34 -0700 | [diff] [blame] | 951 | r = rbd_resize(s->image, offset); |
| 952 | if (r < 0) { |
Max Reitz | f59adb3 | 2017-03-28 22:51:29 +0200 | [diff] [blame] | 953 | error_setg_errno(errp, -r, "Failed to resize file"); |
Josh Durgin | 30cdc48 | 2011-05-26 16:07:34 -0700 | [diff] [blame] | 954 | return r; |
| 955 | } |
| 956 | |
| 957 | return 0; |
| 958 | } |
| 959 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 960 | static int qemu_rbd_snap_create(BlockDriverState *bs, |
| 961 | QEMUSnapshotInfo *sn_info) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 962 | { |
| 963 | BDRVRBDState *s = bs->opaque; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 964 | int r; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 965 | |
| 966 | if (sn_info->name[0] == '\0') { |
| 967 | return -EINVAL; /* we need a name for rbd snapshots */ |
| 968 | } |
| 969 | |
| 970 | /* |
| 971 | * rbd snapshots are using the name as the user controlled unique identifier |
| 972 | * we can't use the rbd snapid for that purpose, as it can't be set |
| 973 | */ |
| 974 | if (sn_info->id_str[0] != '\0' && |
| 975 | strcmp(sn_info->id_str, sn_info->name) != 0) { |
| 976 | return -EINVAL; |
| 977 | } |
| 978 | |
| 979 | if (strlen(sn_info->name) >= sizeof(sn_info->id_str)) { |
| 980 | return -ERANGE; |
| 981 | } |
| 982 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 983 | r = rbd_snap_create(s->image, sn_info->name); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 984 | if (r < 0) { |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 985 | error_report("failed to create snap: %s", strerror(-r)); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 986 | return r; |
| 987 | } |
| 988 | |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 989 | return 0; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 990 | } |
| 991 | |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 992 | static int qemu_rbd_snap_remove(BlockDriverState *bs, |
Wenchao Xia | a89d89d | 2013-09-11 14:04:33 +0800 | [diff] [blame] | 993 | const char *snapshot_id, |
| 994 | const char *snapshot_name, |
| 995 | Error **errp) |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 996 | { |
| 997 | BDRVRBDState *s = bs->opaque; |
| 998 | int r; |
| 999 | |
Wenchao Xia | a89d89d | 2013-09-11 14:04:33 +0800 | [diff] [blame] | 1000 | if (!snapshot_name) { |
| 1001 | error_setg(errp, "rbd need a valid snapshot name"); |
| 1002 | return -EINVAL; |
| 1003 | } |
| 1004 | |
| 1005 | /* If snapshot_id is specified, it must be equal to name, see |
| 1006 | qemu_rbd_snap_list() */ |
| 1007 | if (snapshot_id && strcmp(snapshot_id, snapshot_name)) { |
| 1008 | error_setg(errp, |
| 1009 | "rbd do not support snapshot id, it should be NULL or " |
| 1010 | "equal to snapshot name"); |
| 1011 | return -EINVAL; |
| 1012 | } |
| 1013 | |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 1014 | r = rbd_snap_remove(s->image, snapshot_name); |
Wenchao Xia | a89d89d | 2013-09-11 14:04:33 +0800 | [diff] [blame] | 1015 | if (r < 0) { |
| 1016 | error_setg_errno(errp, -r, "Failed to remove the snapshot"); |
| 1017 | } |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 1018 | return r; |
| 1019 | } |
| 1020 | |
| 1021 | static int qemu_rbd_snap_rollback(BlockDriverState *bs, |
| 1022 | const char *snapshot_name) |
| 1023 | { |
| 1024 | BDRVRBDState *s = bs->opaque; |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 1025 | |
Eduardo Habkost | 9be3859 | 2016-06-13 18:57:58 -0300 | [diff] [blame] | 1026 | return rbd_snap_rollback(s->image, snapshot_name); |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1029 | static int qemu_rbd_snap_list(BlockDriverState *bs, |
| 1030 | QEMUSnapshotInfo **psn_tab) |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1031 | { |
| 1032 | BDRVRBDState *s = bs->opaque; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1033 | QEMUSnapshotInfo *sn_info, *sn_tab = NULL; |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1034 | int i, snap_count; |
| 1035 | rbd_snap_info_t *snaps; |
| 1036 | int max_snaps = RBD_MAX_SNAPS; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1037 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1038 | do { |
Markus Armbruster | 02c4f26 | 2014-08-19 10:31:09 +0200 | [diff] [blame] | 1039 | snaps = g_new(rbd_snap_info_t, max_snaps); |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1040 | snap_count = rbd_snap_list(s->image, snaps, &max_snaps); |
Stefan Hajnoczi | 9e6337d | 2013-09-25 16:00:48 +0200 | [diff] [blame] | 1041 | if (snap_count <= 0) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1042 | g_free(snaps); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1043 | } |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1044 | } while (snap_count == -ERANGE); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1045 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1046 | if (snap_count <= 0) { |
Josh Durgin | b9c5329 | 2011-12-06 17:05:10 -0800 | [diff] [blame] | 1047 | goto done; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
Markus Armbruster | 5839e53 | 2014-08-19 10:31:08 +0200 | [diff] [blame] | 1050 | sn_tab = g_new0(QEMUSnapshotInfo, snap_count); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1051 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1052 | for (i = 0; i < snap_count; i++) { |
| 1053 | const char *snap_name = snaps[i].name; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1054 | |
| 1055 | sn_info = sn_tab + i; |
| 1056 | pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), snap_name); |
| 1057 | pstrcpy(sn_info->name, sizeof(sn_info->name), snap_name); |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1058 | |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1059 | sn_info->vm_state_size = snaps[i].size; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1060 | sn_info->date_sec = 0; |
| 1061 | sn_info->date_nsec = 0; |
| 1062 | sn_info->vm_clock_nsec = 0; |
| 1063 | } |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1064 | rbd_snap_list_end(snaps); |
Stefan Hajnoczi | 9e6337d | 2013-09-25 16:00:48 +0200 | [diff] [blame] | 1065 | g_free(snaps); |
Josh Durgin | ad32e9c | 2011-05-26 16:07:31 -0700 | [diff] [blame] | 1066 | |
Josh Durgin | b9c5329 | 2011-12-06 17:05:10 -0800 | [diff] [blame] | 1067 | done: |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1068 | *psn_tab = sn_tab; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1069 | return snap_count; |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1070 | } |
| 1071 | |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 1072 | #ifdef LIBRBD_SUPPORTS_DISCARD |
Eric Blake | 4da444a | 2016-07-15 17:22:57 -0600 | [diff] [blame] | 1073 | static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverState *bs, |
| 1074 | int64_t offset, |
Manos Pitsidianakis | f5a5ca7 | 2017-06-09 13:18:08 +0300 | [diff] [blame] | 1075 | int bytes, |
Eric Blake | 4da444a | 2016-07-15 17:22:57 -0600 | [diff] [blame] | 1076 | BlockCompletionFunc *cb, |
| 1077 | void *opaque) |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 1078 | { |
Manos Pitsidianakis | f5a5ca7 | 2017-06-09 13:18:08 +0300 | [diff] [blame] | 1079 | return rbd_start_aio(bs, offset, NULL, bytes, cb, opaque, |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 1080 | RBD_AIO_DISCARD); |
| 1081 | } |
| 1082 | #endif |
| 1083 | |
Adam Crume | be21788 | 2014-10-09 11:44:32 -0700 | [diff] [blame] | 1084 | #ifdef LIBRBD_SUPPORTS_INVALIDATE |
| 1085 | static void qemu_rbd_invalidate_cache(BlockDriverState *bs, |
| 1086 | Error **errp) |
| 1087 | { |
| 1088 | BDRVRBDState *s = bs->opaque; |
| 1089 | int r = rbd_invalidate_cache(s->image); |
| 1090 | if (r < 0) { |
| 1091 | error_setg_errno(errp, -r, "Failed to invalidate the cache"); |
| 1092 | } |
| 1093 | } |
| 1094 | #endif |
| 1095 | |
Chunyan Liu | bd0cf59 | 2014-06-05 17:21:04 +0800 | [diff] [blame] | 1096 | static QemuOptsList qemu_rbd_create_opts = { |
| 1097 | .name = "rbd-create-opts", |
| 1098 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head), |
| 1099 | .desc = { |
| 1100 | { |
| 1101 | .name = BLOCK_OPT_SIZE, |
| 1102 | .type = QEMU_OPT_SIZE, |
| 1103 | .help = "Virtual disk size" |
| 1104 | }, |
| 1105 | { |
| 1106 | .name = BLOCK_OPT_CLUSTER_SIZE, |
| 1107 | .type = QEMU_OPT_SIZE, |
| 1108 | .help = "RBD object size" |
| 1109 | }, |
Daniel P. Berrange | 60390a2 | 2016-01-21 14:19:19 +0000 | [diff] [blame] | 1110 | { |
| 1111 | .name = "password-secret", |
| 1112 | .type = QEMU_OPT_STRING, |
| 1113 | .help = "ID of secret providing the password", |
| 1114 | }, |
Chunyan Liu | bd0cf59 | 2014-06-05 17:21:04 +0800 | [diff] [blame] | 1115 | { /* end of list */ } |
| 1116 | } |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1117 | }; |
| 1118 | |
| 1119 | static BlockDriver bdrv_rbd = { |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 1120 | .format_name = "rbd", |
| 1121 | .instance_size = sizeof(BDRVRBDState), |
| 1122 | .bdrv_parse_filename = qemu_rbd_parse_filename, |
| 1123 | .bdrv_file_open = qemu_rbd_open, |
| 1124 | .bdrv_close = qemu_rbd_close, |
Jeff Cody | 56e7cf8 | 2017-04-07 16:55:32 -0400 | [diff] [blame] | 1125 | .bdrv_reopen_prepare = qemu_rbd_reopen_prepare, |
Jeff Cody | c7cacb3 | 2017-02-26 17:50:42 -0500 | [diff] [blame] | 1126 | .bdrv_create = qemu_rbd_create, |
| 1127 | .bdrv_has_zero_init = bdrv_has_zero_init_1, |
| 1128 | .bdrv_get_info = qemu_rbd_getinfo, |
| 1129 | .create_opts = &qemu_rbd_create_opts, |
| 1130 | .bdrv_getlength = qemu_rbd_getlength, |
| 1131 | .bdrv_truncate = qemu_rbd_truncate, |
| 1132 | .protocol_name = "rbd", |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1133 | |
Kevin Wolf | c68b89a | 2011-11-10 17:25:44 +0100 | [diff] [blame] | 1134 | .bdrv_aio_readv = qemu_rbd_aio_readv, |
| 1135 | .bdrv_aio_writev = qemu_rbd_aio_writev, |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 1136 | |
| 1137 | #ifdef LIBRBD_SUPPORTS_AIO_FLUSH |
| 1138 | .bdrv_aio_flush = qemu_rbd_aio_flush, |
| 1139 | #else |
Kevin Wolf | c68b89a | 2011-11-10 17:25:44 +0100 | [diff] [blame] | 1140 | .bdrv_co_flush_to_disk = qemu_rbd_co_flush, |
Josh Durgin | dc7588c | 2013-03-29 13:03:23 -0700 | [diff] [blame] | 1141 | #endif |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1142 | |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 1143 | #ifdef LIBRBD_SUPPORTS_DISCARD |
Eric Blake | 4da444a | 2016-07-15 17:22:57 -0600 | [diff] [blame] | 1144 | .bdrv_aio_pdiscard = qemu_rbd_aio_pdiscard, |
Josh Durgin | 787f313 | 2012-04-30 23:16:45 -0700 | [diff] [blame] | 1145 | #endif |
| 1146 | |
Kevin Wolf | c68b89a | 2011-11-10 17:25:44 +0100 | [diff] [blame] | 1147 | .bdrv_snapshot_create = qemu_rbd_snap_create, |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 1148 | .bdrv_snapshot_delete = qemu_rbd_snap_remove, |
Kevin Wolf | c68b89a | 2011-11-10 17:25:44 +0100 | [diff] [blame] | 1149 | .bdrv_snapshot_list = qemu_rbd_snap_list, |
Gregory Farnum | bd60324 | 2012-01-11 11:53:52 -0800 | [diff] [blame] | 1150 | .bdrv_snapshot_goto = qemu_rbd_snap_rollback, |
Adam Crume | be21788 | 2014-10-09 11:44:32 -0700 | [diff] [blame] | 1151 | #ifdef LIBRBD_SUPPORTS_INVALIDATE |
| 1152 | .bdrv_invalidate_cache = qemu_rbd_invalidate_cache, |
| 1153 | #endif |
Christian Brunner | f27aaf4 | 2010-12-06 20:53:01 +0100 | [diff] [blame] | 1154 | }; |
| 1155 | |
| 1156 | static void bdrv_rbd_init(void) |
| 1157 | { |
| 1158 | bdrv_register(&bdrv_rbd); |
| 1159 | } |
| 1160 | |
| 1161 | block_init(bdrv_rbd_init); |