]>
Commit | Line | Data |
---|---|---|
f27aaf4b CB |
1 | /* |
2 | * QEMU Block driver for RADOS (Ceph) | |
3 | * | |
ad32e9c0 JD |
4 | * Copyright (C) 2010-2011 Christian Brunner <[email protected]>, |
5 | * Josh Durgin <[email protected]> | |
f27aaf4b CB |
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 | * | |
6b620ca3 PB |
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. | |
f27aaf4b CB |
12 | */ |
13 | ||
80c71a24 | 14 | #include "qemu/osdep.h" |
ad32e9c0 | 15 | |
2836284d | 16 | #include <rbd/librbd.h> |
da34e65c | 17 | #include "qapi/error.h" |
1de7afc9 | 18 | #include "qemu/error-report.h" |
0b8fa32f | 19 | #include "qemu/module.h" |
922a01a0 | 20 | #include "qemu/option.h" |
737e150e | 21 | #include "block/block_int.h" |
609f45ea | 22 | #include "block/qdict.h" |
60390a21 | 23 | #include "crypto/secret.h" |
f348b6d1 | 24 | #include "qemu/cutils.h" |
e4ec5ad4 | 25 | #include "sysemu/replay.h" |
c7cacb3e | 26 | #include "qapi/qmp/qstring.h" |
452fcdbc | 27 | #include "qapi/qmp/qdict.h" |
e98c6961 | 28 | #include "qapi/qmp/qjson.h" |
47e6b297 | 29 | #include "qapi/qmp/qlist.h" |
4bfb2741 KW |
30 | #include "qapi/qobject-input-visitor.h" |
31 | #include "qapi/qapi-visit-block-core.h" | |
f27aaf4b | 32 | |
f27aaf4b CB |
33 | /* |
34 | * When specifying the image filename use: | |
35 | * | |
fab5cf59 | 36 | * rbd:poolname/devicename[@snapshotname][:option1=value1[:option2=value2...]] |
f27aaf4b | 37 | * |
9e1fbcde | 38 | * poolname must be the name of an existing rados pool. |
f27aaf4b | 39 | * |
9e1fbcde | 40 | * devicename is the name of the rbd image. |
f27aaf4b | 41 | * |
9e1fbcde SW |
42 | * Each option given is used to configure rados, and may be any valid |
43 | * Ceph option, "id", or "conf". | |
fab5cf59 | 44 | * |
9e1fbcde SW |
45 | * The "id" option indicates what user we should authenticate as to |
46 | * the Ceph cluster. If it is excluded we will use the Ceph default | |
47 | * (normally 'admin'). | |
f27aaf4b | 48 | * |
9e1fbcde SW |
49 | * The "conf" option specifies a Ceph configuration file to read. If |
50 | * it is not specified, we will read from the default Ceph locations | |
51 | * (e.g., /etc/ceph/ceph.conf). To avoid reading _any_ configuration | |
52 | * file, specify conf=/dev/null. | |
f27aaf4b | 53 | * |
9e1fbcde SW |
54 | * Configuration values containing :, @, or = can be escaped with a |
55 | * leading "\". | |
f27aaf4b CB |
56 | */ |
57 | ||
58 | #define OBJ_MAX_SIZE (1UL << OBJ_DEFAULT_OBJ_ORDER) | |
59 | ||
ad32e9c0 JD |
60 | #define RBD_MAX_SNAPS 100 |
61 | ||
42e4ac9e OO |
62 | #define RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN 8 |
63 | ||
64 | static const char rbd_luks_header_verification[ | |
65 | RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN] = { | |
66 | 'L', 'U', 'K', 'S', 0xBA, 0xBE, 0, 1 | |
67 | }; | |
68 | ||
69 | static const char rbd_luks2_header_verification[ | |
70 | RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN] = { | |
71 | 'L', 'U', 'K', 'S', 0xBA, 0xBE, 0, 2 | |
72 | }; | |
73 | ||
787f3133 JD |
74 | typedef enum { |
75 | RBD_AIO_READ, | |
76 | RBD_AIO_WRITE, | |
dc7588c1 JD |
77 | RBD_AIO_DISCARD, |
78 | RBD_AIO_FLUSH | |
787f3133 JD |
79 | } RBDAIOCmd; |
80 | ||
f27aaf4b | 81 | typedef struct RBDAIOCB { |
7c84b1b8 | 82 | BlockAIOCB common; |
08448d51 | 83 | int64_t ret; |
f27aaf4b | 84 | QEMUIOVector *qiov; |
787f3133 | 85 | RBDAIOCmd cmd; |
f27aaf4b CB |
86 | int error; |
87 | struct BDRVRBDState *s; | |
f27aaf4b CB |
88 | } RBDAIOCB; |
89 | ||
90 | typedef struct RADOSCB { | |
f27aaf4b CB |
91 | RBDAIOCB *acb; |
92 | struct BDRVRBDState *s; | |
ad32e9c0 | 93 | int64_t size; |
08448d51 | 94 | int64_t ret; |
f27aaf4b CB |
95 | } RADOSCB; |
96 | ||
f27aaf4b | 97 | typedef struct BDRVRBDState { |
ad32e9c0 JD |
98 | rados_t cluster; |
99 | rados_ioctx_t io_ctx; | |
100 | rbd_image_t image; | |
80b61a27 | 101 | char *image_name; |
ad32e9c0 | 102 | char *snap; |
19ae9ae0 | 103 | char *namespace; |
d24f8023 | 104 | uint64_t image_size; |
832a93dc | 105 | uint64_t object_size; |
f27aaf4b CB |
106 | } BDRVRBDState; |
107 | ||
aa045c2d KW |
108 | static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, |
109 | BlockdevOptionsRbd *opts, bool cache, | |
110 | const char *keypairs, const char *secretid, | |
111 | Error **errp); | |
112 | ||
2b99cfce CK |
113 | static char *qemu_rbd_strchr(char *src, char delim) |
114 | { | |
115 | char *p; | |
116 | ||
117 | for (p = src; *p; ++p) { | |
118 | if (*p == delim) { | |
119 | return p; | |
120 | } | |
121 | if (*p == '\\' && p[1] != '\0') { | |
122 | ++p; | |
123 | } | |
124 | } | |
125 | ||
126 | return NULL; | |
127 | } | |
128 | ||
129 | ||
730b00bb | 130 | static char *qemu_rbd_next_tok(char *src, char delim, char **p) |
f27aaf4b | 131 | { |
f27aaf4b CB |
132 | char *end; |
133 | ||
134 | *p = NULL; | |
135 | ||
2b99cfce CK |
136 | end = qemu_rbd_strchr(src, delim); |
137 | if (end) { | |
8efb339d MA |
138 | *p = end + 1; |
139 | *end = '\0'; | |
140 | } | |
7830f909 | 141 | return src; |
f27aaf4b CB |
142 | } |
143 | ||
16a06b24 SW |
144 | static void qemu_rbd_unescape(char *src) |
145 | { | |
146 | char *p; | |
147 | ||
148 | for (p = src; *src; ++src, ++p) { | |
149 | if (*src == '\\' && src[1] != '\0') { | |
150 | src++; | |
151 | } | |
152 | *p = *src; | |
153 | } | |
154 | *p = '\0'; | |
155 | } | |
156 | ||
c7cacb3e JC |
157 | static void qemu_rbd_parse_filename(const char *filename, QDict *options, |
158 | Error **errp) | |
f27aaf4b CB |
159 | { |
160 | const char *start; | |
e98c6961 EB |
161 | char *p, *buf; |
162 | QList *keypairs = NULL; | |
19ae9ae0 | 163 | char *found_str, *image_name; |
f27aaf4b CB |
164 | |
165 | if (!strstart(filename, "rbd:", &start)) { | |
d61563b2 | 166 | error_setg(errp, "File name must start with 'rbd:'"); |
c7cacb3e | 167 | return; |
f27aaf4b CB |
168 | } |
169 | ||
7267c094 | 170 | buf = g_strdup(start); |
f27aaf4b CB |
171 | p = buf; |
172 | ||
730b00bb | 173 | found_str = qemu_rbd_next_tok(p, '/', &p); |
7830f909 | 174 | if (!p) { |
7830f909 | 175 | error_setg(errp, "Pool name is required"); |
f27aaf4b CB |
176 | goto done; |
177 | } | |
7830f909 | 178 | qemu_rbd_unescape(found_str); |
46f5ac20 | 179 | qdict_put_str(options, "pool", found_str); |
fab5cf59 | 180 | |
2b99cfce | 181 | if (qemu_rbd_strchr(p, '@')) { |
19ae9ae0 | 182 | image_name = qemu_rbd_next_tok(p, '@', &p); |
7830f909 | 183 | |
730b00bb | 184 | found_str = qemu_rbd_next_tok(p, ':', &p); |
7830f909 | 185 | qemu_rbd_unescape(found_str); |
46f5ac20 | 186 | qdict_put_str(options, "snapshot", found_str); |
fab5cf59 | 187 | } else { |
19ae9ae0 FF |
188 | image_name = qemu_rbd_next_tok(p, ':', &p); |
189 | } | |
190 | /* Check for namespace in the image_name */ | |
2b99cfce | 191 | if (qemu_rbd_strchr(image_name, '/')) { |
19ae9ae0 | 192 | found_str = qemu_rbd_next_tok(image_name, '/', &image_name); |
7830f909 | 193 | qemu_rbd_unescape(found_str); |
19ae9ae0 FF |
194 | qdict_put_str(options, "namespace", found_str); |
195 | } else { | |
196 | qdict_put_str(options, "namespace", ""); | |
f27aaf4b | 197 | } |
19ae9ae0 FF |
198 | qemu_rbd_unescape(image_name); |
199 | qdict_put_str(options, "image", image_name); | |
7830f909 | 200 | if (!p) { |
f27aaf4b CB |
201 | goto done; |
202 | } | |
203 | ||
c7cacb3e JC |
204 | /* The following are essentially all key/value pairs, and we treat |
205 | * 'id' and 'conf' a bit special. Key/value pairs may be in any order. */ | |
206 | while (p) { | |
207 | char *name, *value; | |
730b00bb | 208 | name = qemu_rbd_next_tok(p, '=', &p); |
c7cacb3e JC |
209 | if (!p) { |
210 | error_setg(errp, "conf option %s has no value", name); | |
211 | break; | |
7c7e9df0 | 212 | } |
c7cacb3e JC |
213 | |
214 | qemu_rbd_unescape(name); | |
215 | ||
730b00bb | 216 | value = qemu_rbd_next_tok(p, ':', &p); |
c7cacb3e JC |
217 | qemu_rbd_unescape(value); |
218 | ||
219 | if (!strcmp(name, "conf")) { | |
46f5ac20 | 220 | qdict_put_str(options, "conf", value); |
c7cacb3e | 221 | } else if (!strcmp(name, "id")) { |
46f5ac20 | 222 | qdict_put_str(options, "user", value); |
c7cacb3e | 223 | } else { |
e98c6961 EB |
224 | /* |
225 | * We pass these internally to qemu_rbd_set_keypairs(), so | |
226 | * we can get away with the simpler list of [ "key1", | |
227 | * "value1", "key2", "value2" ] rather than a raw dict | |
228 | * { "key1": "value1", "key2": "value2" } where we can't | |
229 | * guarantee order, or even a more correct but complex | |
230 | * [ { "key1": "value1" }, { "key2": "value2" } ] | |
231 | */ | |
232 | if (!keypairs) { | |
233 | keypairs = qlist_new(); | |
c7cacb3e | 234 | } |
46f5ac20 EB |
235 | qlist_append_str(keypairs, name); |
236 | qlist_append_str(keypairs, value); | |
c7cacb3e | 237 | } |
7c7e9df0 | 238 | } |
c7cacb3e | 239 | |
e98c6961 EB |
240 | if (keypairs) { |
241 | qdict_put(options, "=keyvalue-pairs", | |
eab3a467 | 242 | qstring_from_gstring(qobject_to_json(QOBJECT(keypairs)))); |
c7cacb3e JC |
243 | } |
244 | ||
c7cacb3e | 245 | done: |
c7cacb3e | 246 | g_free(buf); |
cb3e7f08 | 247 | qobject_unref(keypairs); |
c7cacb3e | 248 | return; |
7c7e9df0 SW |
249 | } |
250 | ||
60390a21 | 251 | |
e8e16d4b EB |
252 | static void qemu_rbd_refresh_limits(BlockDriverState *bs, Error **errp) |
253 | { | |
254 | /* XXX Does RBD support AIO on less than 512-byte alignment? */ | |
255 | bs->bl.request_alignment = 512; | |
256 | } | |
257 | ||
258 | ||
d083f954 | 259 | static int qemu_rbd_set_auth(rados_t cluster, BlockdevOptionsRbd *opts, |
60390a21 DB |
260 | Error **errp) |
261 | { | |
d083f954 | 262 | char *key, *acr; |
a3699de4 MA |
263 | int r; |
264 | GString *accu; | |
265 | RbdAuthModeList *auth; | |
266 | ||
d083f954 MA |
267 | if (opts->key_secret) { |
268 | key = qcrypto_secret_lookup_as_base64(opts->key_secret, errp); | |
269 | if (!key) { | |
270 | return -EIO; | |
271 | } | |
272 | r = rados_conf_set(cluster, "key", key); | |
273 | g_free(key); | |
274 | if (r < 0) { | |
275 | error_setg_errno(errp, -r, "Could not set 'key'"); | |
276 | return r; | |
a3699de4 | 277 | } |
60390a21 DB |
278 | } |
279 | ||
a3699de4 MA |
280 | if (opts->has_auth_client_required) { |
281 | accu = g_string_new(""); | |
282 | for (auth = opts->auth_client_required; auth; auth = auth->next) { | |
283 | if (accu->str[0]) { | |
284 | g_string_append_c(accu, ';'); | |
285 | } | |
286 | g_string_append(accu, RbdAuthMode_str(auth->value)); | |
287 | } | |
288 | acr = g_string_free(accu, FALSE); | |
289 | r = rados_conf_set(cluster, "auth_client_required", acr); | |
290 | g_free(acr); | |
291 | if (r < 0) { | |
292 | error_setg_errno(errp, -r, | |
293 | "Could not set 'auth_client_required'"); | |
294 | return r; | |
295 | } | |
296 | } | |
60390a21 DB |
297 | |
298 | return 0; | |
299 | } | |
300 | ||
e98c6961 | 301 | static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs_json, |
c7cacb3e | 302 | Error **errp) |
fab5cf59 | 303 | { |
e98c6961 EB |
304 | QList *keypairs; |
305 | QString *name; | |
306 | QString *value; | |
307 | const char *key; | |
308 | size_t remaining; | |
fab5cf59 JD |
309 | int ret = 0; |
310 | ||
e98c6961 EB |
311 | if (!keypairs_json) { |
312 | return ret; | |
313 | } | |
7dc847eb HR |
314 | keypairs = qobject_to(QList, |
315 | qobject_from_json(keypairs_json, &error_abort)); | |
e98c6961 EB |
316 | remaining = qlist_size(keypairs) / 2; |
317 | assert(remaining); | |
318 | ||
319 | while (remaining--) { | |
7dc847eb HR |
320 | name = qobject_to(QString, qlist_pop(keypairs)); |
321 | value = qobject_to(QString, qlist_pop(keypairs)); | |
e98c6961 EB |
322 | assert(name && value); |
323 | key = qstring_get_str(name); | |
324 | ||
325 | ret = rados_conf_set(cluster, key, qstring_get_str(value)); | |
cb3e7f08 | 326 | qobject_unref(value); |
c7cacb3e | 327 | if (ret < 0) { |
e98c6961 | 328 | error_setg_errno(errp, -ret, "invalid conf option %s", key); |
cb3e7f08 | 329 | qobject_unref(name); |
c7cacb3e JC |
330 | ret = -EINVAL; |
331 | break; | |
fab5cf59 | 332 | } |
cb3e7f08 | 333 | qobject_unref(name); |
fab5cf59 JD |
334 | } |
335 | ||
cb3e7f08 | 336 | qobject_unref(keypairs); |
fab5cf59 JD |
337 | return ret; |
338 | } | |
339 | ||
1d393bde | 340 | static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs) |
341 | { | |
48672ac0 PL |
342 | RBDAIOCB *acb = rcb->acb; |
343 | iov_memset(acb->qiov->iov, acb->qiov->niov, offs, 0, | |
344 | acb->qiov->size - offs); | |
1d393bde | 345 | } |
346 | ||
42e4ac9e OO |
347 | #ifdef LIBRBD_SUPPORTS_ENCRYPTION |
348 | static int qemu_rbd_convert_luks_options( | |
349 | RbdEncryptionOptionsLUKSBase *luks_opts, | |
350 | char **passphrase, | |
351 | size_t *passphrase_len, | |
352 | Error **errp) | |
353 | { | |
354 | return qcrypto_secret_lookup(luks_opts->key_secret, (uint8_t **)passphrase, | |
355 | passphrase_len, errp); | |
356 | } | |
357 | ||
358 | static int qemu_rbd_convert_luks_create_options( | |
359 | RbdEncryptionCreateOptionsLUKSBase *luks_opts, | |
360 | rbd_encryption_algorithm_t *alg, | |
361 | char **passphrase, | |
362 | size_t *passphrase_len, | |
363 | Error **errp) | |
364 | { | |
365 | int r = 0; | |
366 | ||
367 | r = qemu_rbd_convert_luks_options( | |
368 | qapi_RbdEncryptionCreateOptionsLUKSBase_base(luks_opts), | |
369 | passphrase, passphrase_len, errp); | |
370 | if (r < 0) { | |
371 | return r; | |
372 | } | |
373 | ||
374 | if (luks_opts->has_cipher_alg) { | |
375 | switch (luks_opts->cipher_alg) { | |
376 | case QCRYPTO_CIPHER_ALG_AES_128: { | |
377 | *alg = RBD_ENCRYPTION_ALGORITHM_AES128; | |
378 | break; | |
379 | } | |
380 | case QCRYPTO_CIPHER_ALG_AES_256: { | |
381 | *alg = RBD_ENCRYPTION_ALGORITHM_AES256; | |
382 | break; | |
383 | } | |
384 | default: { | |
385 | r = -ENOTSUP; | |
386 | error_setg_errno(errp, -r, "unknown encryption algorithm: %u", | |
387 | luks_opts->cipher_alg); | |
388 | return r; | |
389 | } | |
390 | } | |
391 | } else { | |
392 | /* default alg */ | |
393 | *alg = RBD_ENCRYPTION_ALGORITHM_AES256; | |
394 | } | |
395 | ||
396 | return 0; | |
397 | } | |
398 | ||
399 | static int qemu_rbd_encryption_format(rbd_image_t image, | |
400 | RbdEncryptionCreateOptions *encrypt, | |
401 | Error **errp) | |
402 | { | |
403 | int r = 0; | |
404 | g_autofree char *passphrase = NULL; | |
405 | size_t passphrase_len; | |
406 | rbd_encryption_format_t format; | |
407 | rbd_encryption_options_t opts; | |
408 | rbd_encryption_luks1_format_options_t luks_opts; | |
409 | rbd_encryption_luks2_format_options_t luks2_opts; | |
410 | size_t opts_size; | |
411 | uint64_t raw_size, effective_size; | |
412 | ||
413 | r = rbd_get_size(image, &raw_size); | |
414 | if (r < 0) { | |
415 | error_setg_errno(errp, -r, "cannot get raw image size"); | |
416 | return r; | |
417 | } | |
418 | ||
419 | switch (encrypt->format) { | |
420 | case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS: { | |
421 | memset(&luks_opts, 0, sizeof(luks_opts)); | |
422 | format = RBD_ENCRYPTION_FORMAT_LUKS1; | |
423 | opts = &luks_opts; | |
424 | opts_size = sizeof(luks_opts); | |
425 | r = qemu_rbd_convert_luks_create_options( | |
426 | qapi_RbdEncryptionCreateOptionsLUKS_base(&encrypt->u.luks), | |
427 | &luks_opts.alg, &passphrase, &passphrase_len, errp); | |
428 | if (r < 0) { | |
429 | return r; | |
430 | } | |
431 | luks_opts.passphrase = passphrase; | |
432 | luks_opts.passphrase_size = passphrase_len; | |
433 | break; | |
434 | } | |
435 | case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2: { | |
436 | memset(&luks2_opts, 0, sizeof(luks2_opts)); | |
437 | format = RBD_ENCRYPTION_FORMAT_LUKS2; | |
438 | opts = &luks2_opts; | |
439 | opts_size = sizeof(luks2_opts); | |
440 | r = qemu_rbd_convert_luks_create_options( | |
441 | qapi_RbdEncryptionCreateOptionsLUKS2_base( | |
442 | &encrypt->u.luks2), | |
443 | &luks2_opts.alg, &passphrase, &passphrase_len, errp); | |
444 | if (r < 0) { | |
445 | return r; | |
446 | } | |
447 | luks2_opts.passphrase = passphrase; | |
448 | luks2_opts.passphrase_size = passphrase_len; | |
449 | break; | |
450 | } | |
451 | default: { | |
452 | r = -ENOTSUP; | |
453 | error_setg_errno( | |
454 | errp, -r, "unknown image encryption format: %u", | |
455 | encrypt->format); | |
456 | return r; | |
457 | } | |
458 | } | |
459 | ||
460 | r = rbd_encryption_format(image, format, opts, opts_size); | |
461 | if (r < 0) { | |
462 | error_setg_errno(errp, -r, "encryption format fail"); | |
463 | return r; | |
464 | } | |
465 | ||
466 | r = rbd_get_size(image, &effective_size); | |
467 | if (r < 0) { | |
468 | error_setg_errno(errp, -r, "cannot get effective image size"); | |
469 | return r; | |
470 | } | |
471 | ||
472 | r = rbd_resize(image, raw_size + (raw_size - effective_size)); | |
473 | if (r < 0) { | |
474 | error_setg_errno(errp, -r, "cannot resize image after format"); | |
475 | return r; | |
476 | } | |
477 | ||
478 | return 0; | |
479 | } | |
480 | ||
481 | static int qemu_rbd_encryption_load(rbd_image_t image, | |
482 | RbdEncryptionOptions *encrypt, | |
483 | Error **errp) | |
484 | { | |
485 | int r = 0; | |
486 | g_autofree char *passphrase = NULL; | |
487 | size_t passphrase_len; | |
488 | rbd_encryption_luks1_format_options_t luks_opts; | |
489 | rbd_encryption_luks2_format_options_t luks2_opts; | |
490 | rbd_encryption_format_t format; | |
491 | rbd_encryption_options_t opts; | |
492 | size_t opts_size; | |
493 | ||
494 | switch (encrypt->format) { | |
495 | case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS: { | |
496 | memset(&luks_opts, 0, sizeof(luks_opts)); | |
497 | format = RBD_ENCRYPTION_FORMAT_LUKS1; | |
498 | opts = &luks_opts; | |
499 | opts_size = sizeof(luks_opts); | |
500 | r = qemu_rbd_convert_luks_options( | |
501 | qapi_RbdEncryptionOptionsLUKS_base(&encrypt->u.luks), | |
502 | &passphrase, &passphrase_len, errp); | |
503 | if (r < 0) { | |
504 | return r; | |
505 | } | |
506 | luks_opts.passphrase = passphrase; | |
507 | luks_opts.passphrase_size = passphrase_len; | |
508 | break; | |
509 | } | |
510 | case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2: { | |
511 | memset(&luks2_opts, 0, sizeof(luks2_opts)); | |
512 | format = RBD_ENCRYPTION_FORMAT_LUKS2; | |
513 | opts = &luks2_opts; | |
514 | opts_size = sizeof(luks2_opts); | |
515 | r = qemu_rbd_convert_luks_options( | |
516 | qapi_RbdEncryptionOptionsLUKS2_base(&encrypt->u.luks2), | |
517 | &passphrase, &passphrase_len, errp); | |
518 | if (r < 0) { | |
519 | return r; | |
520 | } | |
521 | luks2_opts.passphrase = passphrase; | |
522 | luks2_opts.passphrase_size = passphrase_len; | |
523 | break; | |
524 | } | |
525 | default: { | |
526 | r = -ENOTSUP; | |
527 | error_setg_errno( | |
528 | errp, -r, "unknown image encryption format: %u", | |
529 | encrypt->format); | |
530 | return r; | |
531 | } | |
532 | } | |
533 | ||
534 | r = rbd_encryption_load(image, format, opts, opts_size); | |
535 | if (r < 0) { | |
536 | error_setg_errno(errp, -r, "encryption load fail"); | |
537 | return r; | |
538 | } | |
539 | ||
540 | return 0; | |
541 | } | |
542 | #endif | |
543 | ||
d083f954 | 544 | /* FIXME Deprecate and remove keypairs or make it available in QMP. */ |
1bebea37 KW |
545 | static int qemu_rbd_do_create(BlockdevCreateOptions *options, |
546 | const char *keypairs, const char *password_secret, | |
547 | Error **errp) | |
f27aaf4b | 548 | { |
1bebea37 | 549 | BlockdevCreateOptionsRbd *opts = &options->u.rbd; |
ad32e9c0 JD |
550 | rados_t cluster; |
551 | rados_ioctx_t io_ctx; | |
1bebea37 KW |
552 | int obj_order = 0; |
553 | int ret; | |
554 | ||
555 | assert(options->driver == BLOCKDEV_DRIVER_RBD); | |
556 | if (opts->location->has_snapshot) { | |
557 | error_setg(errp, "Can't use snapshot name for image creation"); | |
558 | return -EINVAL; | |
559 | } | |
f27aaf4b | 560 | |
42e4ac9e OO |
561 | #ifndef LIBRBD_SUPPORTS_ENCRYPTION |
562 | if (opts->has_encrypt) { | |
563 | error_setg(errp, "RBD library does not support image encryption"); | |
564 | return -ENOTSUP; | |
565 | } | |
566 | #endif | |
567 | ||
1bebea37 KW |
568 | if (opts->has_cluster_size) { |
569 | int64_t objsize = opts->cluster_size; | |
bd0cf596 CL |
570 | if ((objsize - 1) & objsize) { /* not a power of 2? */ |
571 | error_setg(errp, "obj size needs to be power of 2"); | |
1bebea37 | 572 | return -EINVAL; |
bd0cf596 CL |
573 | } |
574 | if (objsize < 4096) { | |
575 | error_setg(errp, "obj size too small"); | |
1bebea37 | 576 | return -EINVAL; |
f27aaf4b | 577 | } |
786a4ea8 | 578 | obj_order = ctz32(objsize); |
f27aaf4b CB |
579 | } |
580 | ||
aa045c2d KW |
581 | ret = qemu_rbd_connect(&cluster, &io_ctx, opts->location, false, keypairs, |
582 | password_secret, errp); | |
87cd3d20 | 583 | if (ret < 0) { |
1bebea37 | 584 | return ret; |
f27aaf4b CB |
585 | } |
586 | ||
1bebea37 | 587 | ret = rbd_create(io_ctx, opts->location->image, opts->size, &obj_order); |
87cd3d20 VU |
588 | if (ret < 0) { |
589 | error_setg_errno(errp, -ret, "error rbd create"); | |
aa045c2d | 590 | goto out; |
87cd3d20 | 591 | } |
f27aaf4b | 592 | |
42e4ac9e OO |
593 | #ifdef LIBRBD_SUPPORTS_ENCRYPTION |
594 | if (opts->has_encrypt) { | |
595 | rbd_image_t image; | |
596 | ||
597 | ret = rbd_open(io_ctx, opts->location->image, &image, NULL); | |
598 | if (ret < 0) { | |
599 | error_setg_errno(errp, -ret, | |
600 | "error opening image '%s' for encryption format", | |
601 | opts->location->image); | |
602 | goto out; | |
603 | } | |
604 | ||
605 | ret = qemu_rbd_encryption_format(image, opts->encrypt, errp); | |
606 | rbd_close(image); | |
607 | if (ret < 0) { | |
608 | /* encryption format fail, try removing the image */ | |
609 | rbd_remove(io_ctx, opts->location->image); | |
610 | goto out; | |
611 | } | |
612 | } | |
613 | #endif | |
614 | ||
1bebea37 | 615 | ret = 0; |
aa045c2d KW |
616 | out: |
617 | rados_ioctx_destroy(io_ctx); | |
e38f643a | 618 | rados_shutdown(cluster); |
1bebea37 KW |
619 | return ret; |
620 | } | |
621 | ||
622 | static int qemu_rbd_co_create(BlockdevCreateOptions *options, Error **errp) | |
623 | { | |
624 | return qemu_rbd_do_create(options, NULL, NULL, errp); | |
625 | } | |
626 | ||
42e4ac9e OO |
627 | static int qemu_rbd_extract_encryption_create_options( |
628 | QemuOpts *opts, | |
629 | RbdEncryptionCreateOptions **spec, | |
630 | Error **errp) | |
631 | { | |
632 | QDict *opts_qdict; | |
633 | QDict *encrypt_qdict; | |
634 | Visitor *v; | |
635 | int ret = 0; | |
636 | ||
637 | opts_qdict = qemu_opts_to_qdict(opts, NULL); | |
638 | qdict_extract_subqdict(opts_qdict, &encrypt_qdict, "encrypt."); | |
639 | qobject_unref(opts_qdict); | |
640 | if (!qdict_size(encrypt_qdict)) { | |
641 | *spec = NULL; | |
642 | goto exit; | |
643 | } | |
644 | ||
645 | /* Convert options into a QAPI object */ | |
646 | v = qobject_input_visitor_new_flat_confused(encrypt_qdict, errp); | |
647 | if (!v) { | |
648 | ret = -EINVAL; | |
649 | goto exit; | |
650 | } | |
651 | ||
652 | visit_type_RbdEncryptionCreateOptions(v, NULL, spec, errp); | |
653 | visit_free(v); | |
654 | if (!*spec) { | |
655 | ret = -EINVAL; | |
656 | goto exit; | |
657 | } | |
658 | ||
659 | exit: | |
660 | qobject_unref(encrypt_qdict); | |
661 | return ret; | |
662 | } | |
663 | ||
b92902df ML |
664 | static int coroutine_fn qemu_rbd_co_create_opts(BlockDriver *drv, |
665 | const char *filename, | |
1bebea37 KW |
666 | QemuOpts *opts, |
667 | Error **errp) | |
668 | { | |
669 | BlockdevCreateOptions *create_options; | |
670 | BlockdevCreateOptionsRbd *rbd_opts; | |
671 | BlockdevOptionsRbd *loc; | |
42e4ac9e | 672 | RbdEncryptionCreateOptions *encrypt = NULL; |
1bebea37 KW |
673 | Error *local_err = NULL; |
674 | const char *keypairs, *password_secret; | |
675 | QDict *options = NULL; | |
676 | int ret = 0; | |
677 | ||
678 | create_options = g_new0(BlockdevCreateOptions, 1); | |
679 | create_options->driver = BLOCKDEV_DRIVER_RBD; | |
680 | rbd_opts = &create_options->u.rbd; | |
681 | ||
682 | rbd_opts->location = g_new0(BlockdevOptionsRbd, 1); | |
683 | ||
684 | password_secret = qemu_opt_get(opts, "password-secret"); | |
685 | ||
686 | /* Read out options */ | |
687 | rbd_opts->size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), | |
688 | BDRV_SECTOR_SIZE); | |
689 | rbd_opts->cluster_size = qemu_opt_get_size_del(opts, | |
690 | BLOCK_OPT_CLUSTER_SIZE, 0); | |
691 | rbd_opts->has_cluster_size = (rbd_opts->cluster_size != 0); | |
692 | ||
693 | options = qdict_new(); | |
694 | qemu_rbd_parse_filename(filename, options, &local_err); | |
695 | if (local_err) { | |
696 | ret = -EINVAL; | |
697 | error_propagate(errp, local_err); | |
698 | goto exit; | |
699 | } | |
700 | ||
42e4ac9e OO |
701 | ret = qemu_rbd_extract_encryption_create_options(opts, &encrypt, errp); |
702 | if (ret < 0) { | |
703 | goto exit; | |
704 | } | |
705 | rbd_opts->encrypt = encrypt; | |
706 | rbd_opts->has_encrypt = !!encrypt; | |
707 | ||
1bebea37 KW |
708 | /* |
709 | * Caution: while qdict_get_try_str() is fine, getting non-string | |
710 | * types would require more care. When @options come from -blockdev | |
711 | * or blockdev_add, its members are typed according to the QAPI | |
712 | * schema, but when they come from -drive, they're all QString. | |
713 | */ | |
714 | loc = rbd_opts->location; | |
19ae9ae0 FF |
715 | loc->pool = g_strdup(qdict_get_try_str(options, "pool")); |
716 | loc->conf = g_strdup(qdict_get_try_str(options, "conf")); | |
717 | loc->has_conf = !!loc->conf; | |
718 | loc->user = g_strdup(qdict_get_try_str(options, "user")); | |
719 | loc->has_user = !!loc->user; | |
720 | loc->q_namespace = g_strdup(qdict_get_try_str(options, "namespace")); | |
b084b420 | 721 | loc->has_q_namespace = !!loc->q_namespace; |
19ae9ae0 FF |
722 | loc->image = g_strdup(qdict_get_try_str(options, "image")); |
723 | keypairs = qdict_get_try_str(options, "=keyvalue-pairs"); | |
1bebea37 KW |
724 | |
725 | ret = qemu_rbd_do_create(create_options, keypairs, password_secret, errp); | |
726 | if (ret < 0) { | |
727 | goto exit; | |
728 | } | |
c7cacb3e JC |
729 | |
730 | exit: | |
cb3e7f08 | 731 | qobject_unref(options); |
1bebea37 | 732 | qapi_free_BlockdevCreateOptions(create_options); |
f27aaf4b CB |
733 | return ret; |
734 | } | |
735 | ||
736 | /* | |
e04fb07f SH |
737 | * This aio completion is being called from rbd_finish_bh() and runs in qemu |
738 | * BH context. | |
f27aaf4b | 739 | */ |
ad32e9c0 | 740 | static void qemu_rbd_complete_aio(RADOSCB *rcb) |
f27aaf4b CB |
741 | { |
742 | RBDAIOCB *acb = rcb->acb; | |
743 | int64_t r; | |
744 | ||
f27aaf4b CB |
745 | r = rcb->ret; |
746 | ||
dc7588c1 | 747 | if (acb->cmd != RBD_AIO_READ) { |
f27aaf4b CB |
748 | if (r < 0) { |
749 | acb->ret = r; | |
750 | acb->error = 1; | |
751 | } else if (!acb->error) { | |
ad32e9c0 | 752 | acb->ret = rcb->size; |
f27aaf4b CB |
753 | } |
754 | } else { | |
ad32e9c0 | 755 | if (r < 0) { |
1d393bde | 756 | qemu_rbd_memset(rcb, 0); |
f27aaf4b CB |
757 | acb->ret = r; |
758 | acb->error = 1; | |
ad32e9c0 | 759 | } else if (r < rcb->size) { |
1d393bde | 760 | qemu_rbd_memset(rcb, r); |
f27aaf4b | 761 | if (!acb->error) { |
ad32e9c0 | 762 | acb->ret = rcb->size; |
f27aaf4b CB |
763 | } |
764 | } else if (!acb->error) { | |
ad32e9c0 | 765 | acb->ret = r; |
f27aaf4b CB |
766 | } |
767 | } | |
f27aaf4b | 768 | |
e04fb07f | 769 | g_free(rcb); |
f27aaf4b | 770 | |
e04fb07f | 771 | acb->common.cb(acb->common.opaque, (acb->ret > 0 ? 0 : acb->ret)); |
f27aaf4b | 772 | |
8007429a | 773 | qemu_aio_unref(acb); |
f27aaf4b CB |
774 | } |
775 | ||
4bfb2741 | 776 | static char *qemu_rbd_mon_host(BlockdevOptionsRbd *opts, Error **errp) |
0a55679b | 777 | { |
4bfb2741 | 778 | const char **vals; |
2836284d MA |
779 | const char *host, *port; |
780 | char *rados_str; | |
4bfb2741 KW |
781 | InetSocketAddressBaseList *p; |
782 | int i, cnt; | |
783 | ||
784 | if (!opts->has_server) { | |
785 | return NULL; | |
786 | } | |
787 | ||
788 | for (cnt = 0, p = opts->server; p; p = p->next) { | |
789 | cnt++; | |
790 | } | |
791 | ||
792 | vals = g_new(const char *, cnt + 1); | |
793 | ||
794 | for (i = 0, p = opts->server; p; p = p->next, i++) { | |
795 | host = p->value->host; | |
796 | port = p->value->port; | |
0a55679b | 797 | |
2836284d | 798 | if (strchr(host, ':')) { |
4bfb2741 | 799 | vals[i] = g_strdup_printf("[%s]:%s", host, port); |
0a55679b | 800 | } else { |
4bfb2741 | 801 | vals[i] = g_strdup_printf("%s:%s", host, port); |
0a55679b | 802 | } |
0a55679b | 803 | } |
2836284d | 804 | vals[i] = NULL; |
0a55679b | 805 | |
2836284d | 806 | rados_str = i ? g_strjoinv(";", (char **)vals) : NULL; |
2836284d | 807 | g_strfreev((char **)vals); |
0a55679b JC |
808 | return rados_str; |
809 | } | |
810 | ||
3d9136f9 | 811 | static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, |
4bfb2741 | 812 | BlockdevOptionsRbd *opts, bool cache, |
4ff45049 KW |
813 | const char *keypairs, const char *secretid, |
814 | Error **errp) | |
f27aaf4b | 815 | { |
0a55679b | 816 | char *mon_host = NULL; |
3d9136f9 | 817 | Error *local_err = NULL; |
f27aaf4b CB |
818 | int r; |
819 | ||
d083f954 MA |
820 | if (secretid) { |
821 | if (opts->key_secret) { | |
822 | error_setg(errp, | |
823 | "Legacy 'password-secret' clashes with 'key-secret'"); | |
824 | return -EINVAL; | |
825 | } | |
826 | opts->key_secret = g_strdup(secretid); | |
827 | opts->has_key_secret = true; | |
828 | } | |
829 | ||
4bfb2741 | 830 | mon_host = qemu_rbd_mon_host(opts, &local_err); |
0a55679b JC |
831 | if (local_err) { |
832 | error_propagate(errp, local_err); | |
833 | r = -EINVAL; | |
c1c1f6cf | 834 | goto out; |
0a55679b JC |
835 | } |
836 | ||
4bfb2741 | 837 | r = rados_create(cluster, opts->user); |
ad32e9c0 | 838 | if (r < 0) { |
87cd3d20 | 839 | error_setg_errno(errp, -r, "error initializing"); |
c1c1f6cf | 840 | goto out; |
f27aaf4b CB |
841 | } |
842 | ||
c7cacb3e | 843 | /* try default location when conf=NULL, but ignore failure */ |
4bfb2741 KW |
844 | r = rados_conf_read_file(*cluster, opts->conf); |
845 | if (opts->has_conf && r < 0) { | |
846 | error_setg_errno(errp, -r, "error reading conf file %s", opts->conf); | |
c7cacb3e | 847 | goto failed_shutdown; |
99a3c89d JD |
848 | } |
849 | ||
3d9136f9 | 850 | r = qemu_rbd_set_keypairs(*cluster, keypairs, errp); |
c7cacb3e JC |
851 | if (r < 0) { |
852 | goto failed_shutdown; | |
99a3c89d JD |
853 | } |
854 | ||
0a55679b | 855 | if (mon_host) { |
3d9136f9 | 856 | r = rados_conf_set(*cluster, "mon_host", mon_host); |
0a55679b JC |
857 | if (r < 0) { |
858 | goto failed_shutdown; | |
859 | } | |
860 | } | |
861 | ||
d083f954 MA |
862 | r = qemu_rbd_set_auth(*cluster, opts, errp); |
863 | if (r < 0) { | |
60390a21 DB |
864 | goto failed_shutdown; |
865 | } | |
866 | ||
b11f38fc JD |
867 | /* |
868 | * Fallback to more conservative semantics if setting cache | |
869 | * options fails. Ignore errors from setting rbd_cache because the | |
870 | * only possible error is that the option does not exist, and | |
871 | * librbd defaults to no caching. If write through caching cannot | |
872 | * be set up, fall back to no caching. | |
873 | */ | |
3d9136f9 KW |
874 | if (cache) { |
875 | rados_conf_set(*cluster, "rbd_cache", "true"); | |
b11f38fc | 876 | } else { |
3d9136f9 | 877 | rados_conf_set(*cluster, "rbd_cache", "false"); |
b11f38fc JD |
878 | } |
879 | ||
3d9136f9 | 880 | r = rados_connect(*cluster); |
ad32e9c0 | 881 | if (r < 0) { |
87cd3d20 | 882 | error_setg_errno(errp, -r, "error connecting"); |
eb93d5d9 | 883 | goto failed_shutdown; |
f27aaf4b CB |
884 | } |
885 | ||
4bfb2741 | 886 | r = rados_ioctx_create(*cluster, opts->pool, io_ctx); |
ad32e9c0 | 887 | if (r < 0) { |
4bfb2741 | 888 | error_setg_errno(errp, -r, "error opening pool %s", opts->pool); |
eb93d5d9 | 889 | goto failed_shutdown; |
f27aaf4b | 890 | } |
19ae9ae0 FF |
891 | /* |
892 | * Set the namespace after opening the io context on the pool, | |
893 | * if nspace == NULL or if nspace == "", it is just as we did nothing | |
894 | */ | |
895 | rados_ioctx_set_namespace(*io_ctx, opts->q_namespace); | |
f27aaf4b | 896 | |
c1c1f6cf SG |
897 | r = 0; |
898 | goto out; | |
3d9136f9 KW |
899 | |
900 | failed_shutdown: | |
901 | rados_shutdown(*cluster); | |
c1c1f6cf | 902 | out: |
3d9136f9 KW |
903 | g_free(mon_host); |
904 | return r; | |
905 | } | |
906 | ||
f24b03b5 JC |
907 | static int qemu_rbd_convert_options(QDict *options, BlockdevOptionsRbd **opts, |
908 | Error **errp) | |
909 | { | |
910 | Visitor *v; | |
f24b03b5 JC |
911 | |
912 | /* Convert the remaining options into a QAPI object */ | |
913 | v = qobject_input_visitor_new_flat_confused(options, errp); | |
914 | if (!v) { | |
915 | return -EINVAL; | |
916 | } | |
917 | ||
b11a093c | 918 | visit_type_BlockdevOptionsRbd(v, NULL, opts, errp); |
f24b03b5 | 919 | visit_free(v); |
b11a093c | 920 | if (!opts) { |
f24b03b5 JC |
921 | return -EINVAL; |
922 | } | |
923 | ||
924 | return 0; | |
925 | } | |
926 | ||
084d1d13 JC |
927 | static int qemu_rbd_attempt_legacy_options(QDict *options, |
928 | BlockdevOptionsRbd **opts, | |
929 | char **keypairs) | |
930 | { | |
931 | char *filename; | |
932 | int r; | |
933 | ||
934 | filename = g_strdup(qdict_get_try_str(options, "filename")); | |
935 | if (!filename) { | |
936 | return -EINVAL; | |
937 | } | |
938 | qdict_del(options, "filename"); | |
939 | ||
940 | qemu_rbd_parse_filename(filename, options, NULL); | |
941 | ||
942 | /* keypairs freed by caller */ | |
943 | *keypairs = g_strdup(qdict_get_try_str(options, "=keyvalue-pairs")); | |
944 | if (*keypairs) { | |
945 | qdict_del(options, "=keyvalue-pairs"); | |
946 | } | |
947 | ||
948 | r = qemu_rbd_convert_options(options, opts, NULL); | |
949 | ||
950 | g_free(filename); | |
951 | return r; | |
952 | } | |
953 | ||
3d9136f9 KW |
954 | static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, |
955 | Error **errp) | |
956 | { | |
957 | BDRVRBDState *s = bs->opaque; | |
4bfb2741 | 958 | BlockdevOptionsRbd *opts = NULL; |
bfb15b4b | 959 | const QDictEntry *e; |
3d9136f9 | 960 | Error *local_err = NULL; |
4ff45049 | 961 | char *keypairs, *secretid; |
832a93dc | 962 | rbd_image_info_t info; |
3d9136f9 KW |
963 | int r; |
964 | ||
4ff45049 KW |
965 | keypairs = g_strdup(qdict_get_try_str(options, "=keyvalue-pairs")); |
966 | if (keypairs) { | |
967 | qdict_del(options, "=keyvalue-pairs"); | |
968 | } | |
969 | ||
970 | secretid = g_strdup(qdict_get_try_str(options, "password-secret")); | |
971 | if (secretid) { | |
972 | qdict_del(options, "password-secret"); | |
973 | } | |
974 | ||
f24b03b5 | 975 | r = qemu_rbd_convert_options(options, &opts, &local_err); |
4bfb2741 | 976 | if (local_err) { |
084d1d13 JC |
977 | /* If keypairs are present, that means some options are present in |
978 | * the modern option format. Don't attempt to parse legacy option | |
979 | * formats, as we won't support mixed usage. */ | |
980 | if (keypairs) { | |
981 | error_propagate(errp, local_err); | |
982 | goto out; | |
983 | } | |
984 | ||
985 | /* If the initial attempt to convert and process the options failed, | |
986 | * we may be attempting to open an image file that has the rbd options | |
987 | * specified in the older format consisting of all key/value pairs | |
988 | * encoded in the filename. Go ahead and attempt to parse the | |
989 | * filename, and see if we can pull out the required options. */ | |
990 | r = qemu_rbd_attempt_legacy_options(options, &opts, &keypairs); | |
991 | if (r < 0) { | |
992 | /* Propagate the original error, not the legacy parsing fallback | |
993 | * error, as the latter was just a best-effort attempt. */ | |
994 | error_propagate(errp, local_err); | |
995 | goto out; | |
996 | } | |
997 | /* Take care whenever deciding to actually deprecate; once this ability | |
998 | * is removed, we will not be able to open any images with legacy-styled | |
999 | * backing image strings. */ | |
5197f445 MA |
1000 | warn_report("RBD options encoded in the filename as keyvalue pairs " |
1001 | "is deprecated"); | |
4bfb2741 KW |
1002 | } |
1003 | ||
bfb15b4b JC |
1004 | /* Remove the processed options from the QDict (the visitor processes |
1005 | * _all_ options in the QDict) */ | |
1006 | while ((e = qdict_first(options))) { | |
1007 | qdict_del(options, e->key); | |
1008 | } | |
1009 | ||
d41a5588 KW |
1010 | r = qemu_rbd_connect(&s->cluster, &s->io_ctx, opts, |
1011 | !(flags & BDRV_O_NOCACHE), keypairs, secretid, errp); | |
3d9136f9 | 1012 | if (r < 0) { |
4ff45049 | 1013 | goto out; |
3d9136f9 KW |
1014 | } |
1015 | ||
d41a5588 KW |
1016 | s->snap = g_strdup(opts->snapshot); |
1017 | s->image_name = g_strdup(opts->image); | |
1018 | ||
e2b8247a | 1019 | /* rbd_open is always r/w */ |
80b61a27 | 1020 | r = rbd_open(s->io_ctx, s->image_name, &s->image, s->snap); |
f27aaf4b | 1021 | if (r < 0) { |
80b61a27 JC |
1022 | error_setg_errno(errp, -r, "error reading header from %s", |
1023 | s->image_name); | |
eb93d5d9 | 1024 | goto failed_open; |
f27aaf4b CB |
1025 | } |
1026 | ||
42e4ac9e OO |
1027 | if (opts->has_encrypt) { |
1028 | #ifdef LIBRBD_SUPPORTS_ENCRYPTION | |
1029 | r = qemu_rbd_encryption_load(s->image, opts->encrypt, errp); | |
1030 | if (r < 0) { | |
1031 | goto failed_post_open; | |
1032 | } | |
1033 | #else | |
1034 | r = -ENOTSUP; | |
1035 | error_setg(errp, "RBD library does not support image encryption"); | |
1036 | goto failed_post_open; | |
1037 | #endif | |
1038 | } | |
1039 | ||
832a93dc | 1040 | r = rbd_stat(s->image, &info, sizeof(info)); |
d24f8023 | 1041 | if (r < 0) { |
832a93dc | 1042 | error_setg_errno(errp, -r, "error getting image info from %s", |
d24f8023 | 1043 | s->image_name); |
42e4ac9e | 1044 | goto failed_post_open; |
d24f8023 | 1045 | } |
832a93dc PL |
1046 | s->image_size = info.size; |
1047 | s->object_size = info.obj_size; | |
d24f8023 | 1048 | |
e2b8247a JC |
1049 | /* If we are using an rbd snapshot, we must be r/o, otherwise |
1050 | * leave as-is */ | |
1051 | if (s->snap != NULL) { | |
eaa2410f KW |
1052 | r = bdrv_apply_auto_read_only(bs, "rbd snapshots are read-only", errp); |
1053 | if (r < 0) { | |
42e4ac9e | 1054 | goto failed_post_open; |
e2b8247a JC |
1055 | } |
1056 | } | |
f27aaf4b | 1057 | |
2f98910d EB |
1058 | /* When extending regular files, we get zeros from the OS */ |
1059 | bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE; | |
1060 | ||
4ff45049 KW |
1061 | r = 0; |
1062 | goto out; | |
f27aaf4b | 1063 | |
42e4ac9e OO |
1064 | failed_post_open: |
1065 | rbd_close(s->image); | |
eb93d5d9 | 1066 | failed_open: |
ad32e9c0 | 1067 | rados_ioctx_destroy(s->io_ctx); |
eb93d5d9 | 1068 | g_free(s->snap); |
80b61a27 | 1069 | g_free(s->image_name); |
3d9136f9 | 1070 | rados_shutdown(s->cluster); |
4ff45049 | 1071 | out: |
4bfb2741 | 1072 | qapi_free_BlockdevOptionsRbd(opts); |
4ff45049 KW |
1073 | g_free(keypairs); |
1074 | g_free(secretid); | |
f27aaf4b CB |
1075 | return r; |
1076 | } | |
1077 | ||
56e7cf8d JC |
1078 | |
1079 | /* Since RBD is currently always opened R/W via the API, | |
1080 | * we just need to check if we are using a snapshot or not, in | |
1081 | * order to determine if we will allow it to be R/W */ | |
1082 | static int qemu_rbd_reopen_prepare(BDRVReopenState *state, | |
1083 | BlockReopenQueue *queue, Error **errp) | |
1084 | { | |
1085 | BDRVRBDState *s = state->bs->opaque; | |
1086 | int ret = 0; | |
1087 | ||
1088 | if (s->snap && state->flags & BDRV_O_RDWR) { | |
1089 | error_setg(errp, | |
1090 | "Cannot change node '%s' to r/w when using RBD snapshot", | |
1091 | bdrv_get_device_or_node_name(state->bs)); | |
1092 | ret = -EINVAL; | |
1093 | } | |
1094 | ||
1095 | return ret; | |
1096 | } | |
1097 | ||
ad32e9c0 | 1098 | static void qemu_rbd_close(BlockDriverState *bs) |
f27aaf4b CB |
1099 | { |
1100 | BDRVRBDState *s = bs->opaque; | |
1101 | ||
ad32e9c0 JD |
1102 | rbd_close(s->image); |
1103 | rados_ioctx_destroy(s->io_ctx); | |
7267c094 | 1104 | g_free(s->snap); |
80b61a27 | 1105 | g_free(s->image_name); |
ad32e9c0 | 1106 | rados_shutdown(s->cluster); |
f27aaf4b CB |
1107 | } |
1108 | ||
d24f8023 SG |
1109 | /* Resize the RBD image and update the 'image_size' with the current size */ |
1110 | static int qemu_rbd_resize(BlockDriverState *bs, uint64_t size) | |
1111 | { | |
1112 | BDRVRBDState *s = bs->opaque; | |
1113 | int r; | |
1114 | ||
1115 | r = rbd_resize(s->image, size); | |
1116 | if (r < 0) { | |
1117 | return r; | |
1118 | } | |
1119 | ||
1120 | s->image_size = size; | |
1121 | ||
1122 | return 0; | |
1123 | } | |
1124 | ||
d7331bed | 1125 | static const AIOCBInfo rbd_aiocb_info = { |
f27aaf4b | 1126 | .aiocb_size = sizeof(RBDAIOCB), |
f27aaf4b CB |
1127 | }; |
1128 | ||
e04fb07f | 1129 | static void rbd_finish_bh(void *opaque) |
f27aaf4b | 1130 | { |
e04fb07f | 1131 | RADOSCB *rcb = opaque; |
e04fb07f | 1132 | qemu_rbd_complete_aio(rcb); |
ad32e9c0 JD |
1133 | } |
1134 | ||
1135 | /* | |
1136 | * This is the callback function for rbd_aio_read and _write | |
1137 | * | |
1138 | * Note: this function is being called from a non qemu thread so | |
1139 | * we need to be careful about what we do here. Generally we only | |
e04fb07f SH |
1140 | * schedule a BH, and do the rest of the io completion handling |
1141 | * from rbd_finish_bh() which runs in a qemu context. | |
ad32e9c0 JD |
1142 | */ |
1143 | static void rbd_finish_aiocb(rbd_completion_t c, RADOSCB *rcb) | |
1144 | { | |
e04fb07f SH |
1145 | RBDAIOCB *acb = rcb->acb; |
1146 | ||
ad32e9c0 JD |
1147 | rcb->ret = rbd_aio_get_return_value(c); |
1148 | rbd_aio_release(c); | |
f27aaf4b | 1149 | |
e4ec5ad4 PD |
1150 | replay_bh_schedule_oneshot_event(bdrv_get_aio_context(acb->common.bs), |
1151 | rbd_finish_bh, rcb); | |
f27aaf4b CB |
1152 | } |
1153 | ||
7c84b1b8 | 1154 | static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, |
7bbca9e2 | 1155 | int64_t off, |
7c84b1b8 | 1156 | QEMUIOVector *qiov, |
7bbca9e2 | 1157 | int64_t size, |
097310b5 | 1158 | BlockCompletionFunc *cb, |
7c84b1b8 MA |
1159 | void *opaque, |
1160 | RBDAIOCmd cmd) | |
f27aaf4b CB |
1161 | { |
1162 | RBDAIOCB *acb; | |
0f7a0237 | 1163 | RADOSCB *rcb = NULL; |
ad32e9c0 | 1164 | rbd_completion_t c; |
51a13528 | 1165 | int r; |
f27aaf4b CB |
1166 | |
1167 | BDRVRBDState *s = bs->opaque; | |
1168 | ||
d7331bed | 1169 | acb = qemu_aio_get(&rbd_aiocb_info, bs, cb, opaque); |
787f3133 | 1170 | acb->cmd = cmd; |
f27aaf4b | 1171 | acb->qiov = qiov; |
7bbca9e2 | 1172 | assert(!qiov || qiov->size == size); |
1d393bde | 1173 | |
1174 | rcb = g_new(RADOSCB, 1); | |
1175 | ||
f27aaf4b CB |
1176 | acb->ret = 0; |
1177 | acb->error = 0; | |
1178 | acb->s = s; | |
f27aaf4b | 1179 | |
ad32e9c0 | 1180 | rcb->acb = acb; |
ad32e9c0 JD |
1181 | rcb->s = acb->s; |
1182 | rcb->size = size; | |
51a13528 JD |
1183 | r = rbd_aio_create_completion(rcb, (rbd_callback_t) rbd_finish_aiocb, &c); |
1184 | if (r < 0) { | |
1185 | goto failed; | |
1186 | } | |
f27aaf4b | 1187 | |
787f3133 | 1188 | switch (cmd) { |
48672ac0 | 1189 | case RBD_AIO_WRITE: |
d24f8023 SG |
1190 | /* |
1191 | * RBD APIs don't allow us to write more than actual size, so in order | |
1192 | * to support growing images, we resize the image before write | |
1193 | * operations that exceed the current size. | |
1194 | */ | |
1195 | if (off + size > s->image_size) { | |
1196 | r = qemu_rbd_resize(bs, off + size); | |
1197 | if (r < 0) { | |
1198 | goto failed_completion; | |
1199 | } | |
1200 | } | |
48672ac0 | 1201 | r = rbd_aio_writev(s->image, qiov->iov, qiov->niov, off, c); |
787f3133 JD |
1202 | break; |
1203 | case RBD_AIO_READ: | |
48672ac0 | 1204 | r = rbd_aio_readv(s->image, qiov->iov, qiov->niov, off, c); |
787f3133 JD |
1205 | break; |
1206 | case RBD_AIO_DISCARD: | |
48672ac0 | 1207 | r = rbd_aio_discard(s->image, off, size, c); |
787f3133 | 1208 | break; |
dc7588c1 | 1209 | case RBD_AIO_FLUSH: |
48672ac0 | 1210 | r = rbd_aio_flush(s->image, c); |
dc7588c1 | 1211 | break; |
787f3133 JD |
1212 | default: |
1213 | r = -EINVAL; | |
51a13528 JD |
1214 | } |
1215 | ||
1216 | if (r < 0) { | |
405a2764 | 1217 | goto failed_completion; |
f27aaf4b | 1218 | } |
f27aaf4b | 1219 | return &acb->common; |
51a13528 | 1220 | |
405a2764 KW |
1221 | failed_completion: |
1222 | rbd_aio_release(c); | |
51a13528 | 1223 | failed: |
7267c094 | 1224 | g_free(rcb); |
1d393bde | 1225 | |
8007429a | 1226 | qemu_aio_unref(acb); |
51a13528 | 1227 | return NULL; |
f27aaf4b CB |
1228 | } |
1229 | ||
e8e16d4b EB |
1230 | static BlockAIOCB *qemu_rbd_aio_preadv(BlockDriverState *bs, |
1231 | uint64_t offset, uint64_t bytes, | |
1232 | QEMUIOVector *qiov, int flags, | |
1233 | BlockCompletionFunc *cb, | |
1234 | void *opaque) | |
f27aaf4b | 1235 | { |
e8e16d4b | 1236 | return rbd_start_aio(bs, offset, qiov, bytes, cb, opaque, |
787f3133 | 1237 | RBD_AIO_READ); |
f27aaf4b CB |
1238 | } |
1239 | ||
e8e16d4b EB |
1240 | static BlockAIOCB *qemu_rbd_aio_pwritev(BlockDriverState *bs, |
1241 | uint64_t offset, uint64_t bytes, | |
1242 | QEMUIOVector *qiov, int flags, | |
1243 | BlockCompletionFunc *cb, | |
1244 | void *opaque) | |
f27aaf4b | 1245 | { |
e8e16d4b | 1246 | return rbd_start_aio(bs, offset, qiov, bytes, cb, opaque, |
787f3133 | 1247 | RBD_AIO_WRITE); |
f27aaf4b CB |
1248 | } |
1249 | ||
7c84b1b8 | 1250 | static BlockAIOCB *qemu_rbd_aio_flush(BlockDriverState *bs, |
097310b5 | 1251 | BlockCompletionFunc *cb, |
7c84b1b8 | 1252 | void *opaque) |
dc7588c1 JD |
1253 | { |
1254 | return rbd_start_aio(bs, 0, NULL, 0, cb, opaque, RBD_AIO_FLUSH); | |
1255 | } | |
1256 | ||
ad32e9c0 | 1257 | static int qemu_rbd_getinfo(BlockDriverState *bs, BlockDriverInfo *bdi) |
f27aaf4b CB |
1258 | { |
1259 | BDRVRBDState *s = bs->opaque; | |
832a93dc | 1260 | bdi->cluster_size = s->object_size; |
f27aaf4b CB |
1261 | return 0; |
1262 | } | |
1263 | ||
42e4ac9e OO |
1264 | static ImageInfoSpecific *qemu_rbd_get_specific_info(BlockDriverState *bs, |
1265 | Error **errp) | |
1266 | { | |
1267 | BDRVRBDState *s = bs->opaque; | |
1268 | ImageInfoSpecific *spec_info; | |
1269 | char buf[RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN] = {0}; | |
1270 | int r; | |
1271 | ||
1272 | if (s->image_size >= RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) { | |
1273 | r = rbd_read(s->image, 0, | |
1274 | RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN, buf); | |
1275 | if (r < 0) { | |
1276 | error_setg_errno(errp, -r, "cannot read image start for probe"); | |
1277 | return NULL; | |
1278 | } | |
1279 | } | |
1280 | ||
1281 | spec_info = g_new(ImageInfoSpecific, 1); | |
1282 | *spec_info = (ImageInfoSpecific){ | |
1283 | .type = IMAGE_INFO_SPECIFIC_KIND_RBD, | |
1284 | .u.rbd.data = g_new0(ImageInfoSpecificRbd, 1), | |
1285 | }; | |
1286 | ||
1287 | if (memcmp(buf, rbd_luks_header_verification, | |
1288 | RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) { | |
1289 | spec_info->u.rbd.data->encryption_format = | |
1290 | RBD_IMAGE_ENCRYPTION_FORMAT_LUKS; | |
1291 | spec_info->u.rbd.data->has_encryption_format = true; | |
1292 | } else if (memcmp(buf, rbd_luks2_header_verification, | |
1293 | RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) == 0) { | |
1294 | spec_info->u.rbd.data->encryption_format = | |
1295 | RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2; | |
1296 | spec_info->u.rbd.data->has_encryption_format = true; | |
1297 | } else { | |
1298 | spec_info->u.rbd.data->has_encryption_format = false; | |
1299 | } | |
1300 | ||
1301 | return spec_info; | |
1302 | } | |
1303 | ||
ad32e9c0 | 1304 | static int64_t qemu_rbd_getlength(BlockDriverState *bs) |
f27aaf4b CB |
1305 | { |
1306 | BDRVRBDState *s = bs->opaque; | |
ad32e9c0 | 1307 | int r; |
f27aaf4b | 1308 | |
6d921418 | 1309 | r = rbd_get_size(s->image, &s->image_size); |
ad32e9c0 JD |
1310 | if (r < 0) { |
1311 | return r; | |
1312 | } | |
1313 | ||
6d921418 | 1314 | return s->image_size; |
f27aaf4b CB |
1315 | } |
1316 | ||
061ca8a3 KW |
1317 | static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs, |
1318 | int64_t offset, | |
c80d8b06 | 1319 | bool exact, |
061ca8a3 | 1320 | PreallocMode prealloc, |
92b92799 | 1321 | BdrvRequestFlags flags, |
061ca8a3 | 1322 | Error **errp) |
30cdc48c | 1323 | { |
30cdc48c JD |
1324 | int r; |
1325 | ||
8243ccb7 HR |
1326 | if (prealloc != PREALLOC_MODE_OFF) { |
1327 | error_setg(errp, "Unsupported preallocation mode '%s'", | |
977c736f | 1328 | PreallocMode_str(prealloc)); |
8243ccb7 HR |
1329 | return -ENOTSUP; |
1330 | } | |
1331 | ||
d24f8023 | 1332 | r = qemu_rbd_resize(bs, offset); |
30cdc48c | 1333 | if (r < 0) { |
f59adb32 | 1334 | error_setg_errno(errp, -r, "Failed to resize file"); |
30cdc48c JD |
1335 | return r; |
1336 | } | |
1337 | ||
1338 | return 0; | |
1339 | } | |
1340 | ||
ad32e9c0 JD |
1341 | static int qemu_rbd_snap_create(BlockDriverState *bs, |
1342 | QEMUSnapshotInfo *sn_info) | |
f27aaf4b CB |
1343 | { |
1344 | BDRVRBDState *s = bs->opaque; | |
f27aaf4b | 1345 | int r; |
f27aaf4b CB |
1346 | |
1347 | if (sn_info->name[0] == '\0') { | |
1348 | return -EINVAL; /* we need a name for rbd snapshots */ | |
1349 | } | |
1350 | ||
1351 | /* | |
1352 | * rbd snapshots are using the name as the user controlled unique identifier | |
1353 | * we can't use the rbd snapid for that purpose, as it can't be set | |
1354 | */ | |
1355 | if (sn_info->id_str[0] != '\0' && | |
1356 | strcmp(sn_info->id_str, sn_info->name) != 0) { | |
1357 | return -EINVAL; | |
1358 | } | |
1359 | ||
1360 | if (strlen(sn_info->name) >= sizeof(sn_info->id_str)) { | |
1361 | return -ERANGE; | |
1362 | } | |
1363 | ||
ad32e9c0 | 1364 | r = rbd_snap_create(s->image, sn_info->name); |
f27aaf4b | 1365 | if (r < 0) { |
ad32e9c0 | 1366 | error_report("failed to create snap: %s", strerror(-r)); |
f27aaf4b CB |
1367 | return r; |
1368 | } | |
1369 | ||
f27aaf4b CB |
1370 | return 0; |
1371 | } | |
1372 | ||
bd603247 | 1373 | static int qemu_rbd_snap_remove(BlockDriverState *bs, |
a89d89d3 WX |
1374 | const char *snapshot_id, |
1375 | const char *snapshot_name, | |
1376 | Error **errp) | |
bd603247 GF |
1377 | { |
1378 | BDRVRBDState *s = bs->opaque; | |
1379 | int r; | |
1380 | ||
a89d89d3 WX |
1381 | if (!snapshot_name) { |
1382 | error_setg(errp, "rbd need a valid snapshot name"); | |
1383 | return -EINVAL; | |
1384 | } | |
1385 | ||
1386 | /* If snapshot_id is specified, it must be equal to name, see | |
1387 | qemu_rbd_snap_list() */ | |
1388 | if (snapshot_id && strcmp(snapshot_id, snapshot_name)) { | |
1389 | error_setg(errp, | |
1390 | "rbd do not support snapshot id, it should be NULL or " | |
1391 | "equal to snapshot name"); | |
1392 | return -EINVAL; | |
1393 | } | |
1394 | ||
bd603247 | 1395 | r = rbd_snap_remove(s->image, snapshot_name); |
a89d89d3 WX |
1396 | if (r < 0) { |
1397 | error_setg_errno(errp, -r, "Failed to remove the snapshot"); | |
1398 | } | |
bd603247 GF |
1399 | return r; |
1400 | } | |
1401 | ||
1402 | static int qemu_rbd_snap_rollback(BlockDriverState *bs, | |
1403 | const char *snapshot_name) | |
1404 | { | |
1405 | BDRVRBDState *s = bs->opaque; | |
bd603247 | 1406 | |
9be38598 | 1407 | return rbd_snap_rollback(s->image, snapshot_name); |
bd603247 GF |
1408 | } |
1409 | ||
ad32e9c0 JD |
1410 | static int qemu_rbd_snap_list(BlockDriverState *bs, |
1411 | QEMUSnapshotInfo **psn_tab) | |
f27aaf4b CB |
1412 | { |
1413 | BDRVRBDState *s = bs->opaque; | |
f27aaf4b | 1414 | QEMUSnapshotInfo *sn_info, *sn_tab = NULL; |
ad32e9c0 JD |
1415 | int i, snap_count; |
1416 | rbd_snap_info_t *snaps; | |
1417 | int max_snaps = RBD_MAX_SNAPS; | |
f27aaf4b | 1418 | |
ad32e9c0 | 1419 | do { |
02c4f26b | 1420 | snaps = g_new(rbd_snap_info_t, max_snaps); |
ad32e9c0 | 1421 | snap_count = rbd_snap_list(s->image, snaps, &max_snaps); |
9e6337d0 | 1422 | if (snap_count <= 0) { |
7267c094 | 1423 | g_free(snaps); |
f27aaf4b | 1424 | } |
ad32e9c0 | 1425 | } while (snap_count == -ERANGE); |
f27aaf4b | 1426 | |
ad32e9c0 | 1427 | if (snap_count <= 0) { |
b9c53290 | 1428 | goto done; |
f27aaf4b CB |
1429 | } |
1430 | ||
5839e53b | 1431 | sn_tab = g_new0(QEMUSnapshotInfo, snap_count); |
f27aaf4b | 1432 | |
ad32e9c0 JD |
1433 | for (i = 0; i < snap_count; i++) { |
1434 | const char *snap_name = snaps[i].name; | |
f27aaf4b CB |
1435 | |
1436 | sn_info = sn_tab + i; | |
1437 | pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), snap_name); | |
1438 | pstrcpy(sn_info->name, sizeof(sn_info->name), snap_name); | |
f27aaf4b | 1439 | |
ad32e9c0 | 1440 | sn_info->vm_state_size = snaps[i].size; |
f27aaf4b CB |
1441 | sn_info->date_sec = 0; |
1442 | sn_info->date_nsec = 0; | |
1443 | sn_info->vm_clock_nsec = 0; | |
1444 | } | |
ad32e9c0 | 1445 | rbd_snap_list_end(snaps); |
9e6337d0 | 1446 | g_free(snaps); |
ad32e9c0 | 1447 | |
b9c53290 | 1448 | done: |
f27aaf4b | 1449 | *psn_tab = sn_tab; |
f27aaf4b | 1450 | return snap_count; |
f27aaf4b CB |
1451 | } |
1452 | ||
4da444a0 EB |
1453 | static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverState *bs, |
1454 | int64_t offset, | |
f5a5ca79 | 1455 | int bytes, |
4da444a0 EB |
1456 | BlockCompletionFunc *cb, |
1457 | void *opaque) | |
787f3133 | 1458 | { |
f5a5ca79 | 1459 | return rbd_start_aio(bs, offset, NULL, bytes, cb, opaque, |
787f3133 JD |
1460 | RBD_AIO_DISCARD); |
1461 | } | |
787f3133 | 1462 | |
2b148f39 PB |
1463 | static void coroutine_fn qemu_rbd_co_invalidate_cache(BlockDriverState *bs, |
1464 | Error **errp) | |
be217884 AC |
1465 | { |
1466 | BDRVRBDState *s = bs->opaque; | |
1467 | int r = rbd_invalidate_cache(s->image); | |
1468 | if (r < 0) { | |
1469 | error_setg_errno(errp, -r, "Failed to invalidate the cache"); | |
1470 | } | |
1471 | } | |
be217884 | 1472 | |
bd0cf596 CL |
1473 | static QemuOptsList qemu_rbd_create_opts = { |
1474 | .name = "rbd-create-opts", | |
1475 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head), | |
1476 | .desc = { | |
1477 | { | |
1478 | .name = BLOCK_OPT_SIZE, | |
1479 | .type = QEMU_OPT_SIZE, | |
1480 | .help = "Virtual disk size" | |
1481 | }, | |
1482 | { | |
1483 | .name = BLOCK_OPT_CLUSTER_SIZE, | |
1484 | .type = QEMU_OPT_SIZE, | |
1485 | .help = "RBD object size" | |
1486 | }, | |
60390a21 DB |
1487 | { |
1488 | .name = "password-secret", | |
1489 | .type = QEMU_OPT_STRING, | |
1490 | .help = "ID of secret providing the password", | |
1491 | }, | |
42e4ac9e OO |
1492 | { |
1493 | .name = "encrypt.format", | |
1494 | .type = QEMU_OPT_STRING, | |
1495 | .help = "Encrypt the image, format choices: 'luks', 'luks2'", | |
1496 | }, | |
1497 | { | |
1498 | .name = "encrypt.cipher-alg", | |
1499 | .type = QEMU_OPT_STRING, | |
1500 | .help = "Name of encryption cipher algorithm" | |
1501 | " (allowed values: aes-128, aes-256)", | |
1502 | }, | |
1503 | { | |
1504 | .name = "encrypt.key-secret", | |
1505 | .type = QEMU_OPT_STRING, | |
1506 | .help = "ID of secret providing LUKS passphrase", | |
1507 | }, | |
bd0cf596 CL |
1508 | { /* end of list */ } |
1509 | } | |
f27aaf4b CB |
1510 | }; |
1511 | ||
2654267c HR |
1512 | static const char *const qemu_rbd_strong_runtime_opts[] = { |
1513 | "pool", | |
7bae7c80 | 1514 | "namespace", |
2654267c HR |
1515 | "image", |
1516 | "conf", | |
1517 | "snapshot", | |
1518 | "user", | |
1519 | "server.", | |
1520 | "password-secret", | |
1521 | ||
1522 | NULL | |
1523 | }; | |
1524 | ||
f27aaf4b | 1525 | static BlockDriver bdrv_rbd = { |
c7cacb3e JC |
1526 | .format_name = "rbd", |
1527 | .instance_size = sizeof(BDRVRBDState), | |
1528 | .bdrv_parse_filename = qemu_rbd_parse_filename, | |
e8e16d4b | 1529 | .bdrv_refresh_limits = qemu_rbd_refresh_limits, |
c7cacb3e JC |
1530 | .bdrv_file_open = qemu_rbd_open, |
1531 | .bdrv_close = qemu_rbd_close, | |
56e7cf8d | 1532 | .bdrv_reopen_prepare = qemu_rbd_reopen_prepare, |
1bebea37 | 1533 | .bdrv_co_create = qemu_rbd_co_create, |
efc75e2a | 1534 | .bdrv_co_create_opts = qemu_rbd_co_create_opts, |
c7cacb3e JC |
1535 | .bdrv_has_zero_init = bdrv_has_zero_init_1, |
1536 | .bdrv_get_info = qemu_rbd_getinfo, | |
42e4ac9e | 1537 | .bdrv_get_specific_info = qemu_rbd_get_specific_info, |
c7cacb3e JC |
1538 | .create_opts = &qemu_rbd_create_opts, |
1539 | .bdrv_getlength = qemu_rbd_getlength, | |
061ca8a3 | 1540 | .bdrv_co_truncate = qemu_rbd_co_truncate, |
c7cacb3e | 1541 | .protocol_name = "rbd", |
f27aaf4b | 1542 | |
e8e16d4b EB |
1543 | .bdrv_aio_preadv = qemu_rbd_aio_preadv, |
1544 | .bdrv_aio_pwritev = qemu_rbd_aio_pwritev, | |
dc7588c1 | 1545 | |
dc7588c1 | 1546 | .bdrv_aio_flush = qemu_rbd_aio_flush, |
4da444a0 | 1547 | .bdrv_aio_pdiscard = qemu_rbd_aio_pdiscard, |
787f3133 | 1548 | |
c68b89ac | 1549 | .bdrv_snapshot_create = qemu_rbd_snap_create, |
bd603247 | 1550 | .bdrv_snapshot_delete = qemu_rbd_snap_remove, |
c68b89ac | 1551 | .bdrv_snapshot_list = qemu_rbd_snap_list, |
bd603247 | 1552 | .bdrv_snapshot_goto = qemu_rbd_snap_rollback, |
2b148f39 | 1553 | .bdrv_co_invalidate_cache = qemu_rbd_co_invalidate_cache, |
2654267c HR |
1554 | |
1555 | .strong_runtime_opts = qemu_rbd_strong_runtime_opts, | |
f27aaf4b CB |
1556 | }; |
1557 | ||
1558 | static void bdrv_rbd_init(void) | |
1559 | { | |
1560 | bdrv_register(&bdrv_rbd); | |
1561 | } | |
1562 | ||
1563 | block_init(bdrv_rbd_init); |