xref: /openbmc/qemu/block/crypto.c (revision bd6ce9a6)
1 /*
2  * QEMU block full disk encryption
3  *
4  * Copyright (c) 2015-2016 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include "qemu/osdep.h"
22 
23 #include "block/block_int.h"
24 #include "block/qdict.h"
25 #include "sysemu/block-backend.h"
26 #include "crypto/block.h"
27 #include "qapi/opts-visitor.h"
28 #include "qapi/qapi-visit-crypto.h"
29 #include "qapi/qobject-input-visitor.h"
30 #include "qapi/error.h"
31 #include "qemu/module.h"
32 #include "qemu/option.h"
33 #include "crypto.h"
34 
35 typedef struct BlockCrypto BlockCrypto;
36 
37 struct BlockCrypto {
38     QCryptoBlock *block;
39 };
40 
41 
42 static int block_crypto_probe_generic(QCryptoBlockFormat format,
43                                       const uint8_t *buf,
44                                       int buf_size,
45                                       const char *filename)
46 {
47     if (qcrypto_block_has_format(format, buf, buf_size)) {
48         return 100;
49     } else {
50         return 0;
51     }
52 }
53 
54 
55 static ssize_t block_crypto_read_func(QCryptoBlock *block,
56                                       size_t offset,
57                                       uint8_t *buf,
58                                       size_t buflen,
59                                       void *opaque,
60                                       Error **errp)
61 {
62     BlockDriverState *bs = opaque;
63     ssize_t ret;
64 
65     ret = bdrv_pread(bs->file, offset, buf, buflen);
66     if (ret < 0) {
67         error_setg_errno(errp, -ret, "Could not read encryption header");
68         return ret;
69     }
70     return ret;
71 }
72 
73 
74 struct BlockCryptoCreateData {
75     BlockBackend *blk;
76     uint64_t size;
77     PreallocMode prealloc;
78 };
79 
80 
81 static ssize_t block_crypto_write_func(QCryptoBlock *block,
82                                        size_t offset,
83                                        const uint8_t *buf,
84                                        size_t buflen,
85                                        void *opaque,
86                                        Error **errp)
87 {
88     struct BlockCryptoCreateData *data = opaque;
89     ssize_t ret;
90 
91     ret = blk_pwrite(data->blk, offset, buf, buflen, 0);
92     if (ret < 0) {
93         error_setg_errno(errp, -ret, "Could not write encryption header");
94         return ret;
95     }
96     return ret;
97 }
98 
99 
100 static ssize_t block_crypto_init_func(QCryptoBlock *block,
101                                       size_t headerlen,
102                                       void *opaque,
103                                       Error **errp)
104 {
105     struct BlockCryptoCreateData *data = opaque;
106 
107     if (data->size > INT64_MAX || headerlen > INT64_MAX - data->size) {
108         error_setg(errp, "The requested file size is too large");
109         return -EFBIG;
110     }
111 
112     /* User provided size should reflect amount of space made
113      * available to the guest, so we must take account of that
114      * which will be used by the crypto header
115      */
116     return blk_truncate(data->blk, data->size + headerlen, false,
117                         data->prealloc, errp);
118 }
119 
120 
121 static QemuOptsList block_crypto_runtime_opts_luks = {
122     .name = "crypto",
123     .head = QTAILQ_HEAD_INITIALIZER(block_crypto_runtime_opts_luks.head),
124     .desc = {
125         BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(""),
126         { /* end of list */ }
127     },
128 };
129 
130 
131 static QemuOptsList block_crypto_create_opts_luks = {
132     .name = "crypto",
133     .head = QTAILQ_HEAD_INITIALIZER(block_crypto_create_opts_luks.head),
134     .desc = {
135         {
136             .name = BLOCK_OPT_SIZE,
137             .type = QEMU_OPT_SIZE,
138             .help = "Virtual disk size"
139         },
140         BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(""),
141         BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG(""),
142         BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE(""),
143         BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG(""),
144         BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG(""),
145         BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG(""),
146         BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME(""),
147         { /* end of list */ }
148     },
149 };
150 
151 
152 QCryptoBlockOpenOptions *
153 block_crypto_open_opts_init(QDict *opts, Error **errp)
154 {
155     Visitor *v;
156     QCryptoBlockOpenOptions *ret;
157 
158     v = qobject_input_visitor_new_flat_confused(opts, errp);
159     if (!v) {
160         return NULL;
161     }
162 
163     visit_type_QCryptoBlockOpenOptions(v, NULL, &ret, errp);
164 
165     visit_free(v);
166     return ret;
167 }
168 
169 
170 QCryptoBlockCreateOptions *
171 block_crypto_create_opts_init(QDict *opts, Error **errp)
172 {
173     Visitor *v;
174     QCryptoBlockCreateOptions *ret;
175 
176     v = qobject_input_visitor_new_flat_confused(opts, errp);
177     if (!v) {
178         return NULL;
179     }
180 
181     visit_type_QCryptoBlockCreateOptions(v, NULL, &ret, errp);
182 
183     visit_free(v);
184     return ret;
185 }
186 
187 
188 static int block_crypto_open_generic(QCryptoBlockFormat format,
189                                      QemuOptsList *opts_spec,
190                                      BlockDriverState *bs,
191                                      QDict *options,
192                                      int flags,
193                                      Error **errp)
194 {
195     BlockCrypto *crypto = bs->opaque;
196     QemuOpts *opts = NULL;
197     Error *local_err = NULL;
198     int ret = -EINVAL;
199     QCryptoBlockOpenOptions *open_opts = NULL;
200     unsigned int cflags = 0;
201     QDict *cryptoopts = NULL;
202 
203     bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
204                                false, errp);
205     if (!bs->file) {
206         return -EINVAL;
207     }
208 
209     bs->supported_write_flags = BDRV_REQ_FUA &
210         bs->file->bs->supported_write_flags;
211 
212     opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort);
213     qemu_opts_absorb_qdict(opts, options, &local_err);
214     if (local_err) {
215         error_propagate(errp, local_err);
216         goto cleanup;
217     }
218 
219     cryptoopts = qemu_opts_to_qdict(opts, NULL);
220     qdict_put_str(cryptoopts, "format", QCryptoBlockFormat_str(format));
221 
222     open_opts = block_crypto_open_opts_init(cryptoopts, errp);
223     if (!open_opts) {
224         goto cleanup;
225     }
226 
227     if (flags & BDRV_O_NO_IO) {
228         cflags |= QCRYPTO_BLOCK_OPEN_NO_IO;
229     }
230     crypto->block = qcrypto_block_open(open_opts, NULL,
231                                        block_crypto_read_func,
232                                        bs,
233                                        cflags,
234                                        1,
235                                        errp);
236 
237     if (!crypto->block) {
238         ret = -EIO;
239         goto cleanup;
240     }
241 
242     bs->encrypted = true;
243 
244     ret = 0;
245  cleanup:
246     qobject_unref(cryptoopts);
247     qapi_free_QCryptoBlockOpenOptions(open_opts);
248     return ret;
249 }
250 
251 
252 static int block_crypto_co_create_generic(BlockDriverState *bs,
253                                           int64_t size,
254                                           QCryptoBlockCreateOptions *opts,
255                                           PreallocMode prealloc,
256                                           Error **errp)
257 {
258     int ret;
259     BlockBackend *blk;
260     QCryptoBlock *crypto = NULL;
261     struct BlockCryptoCreateData data;
262 
263     blk = blk_new(bdrv_get_aio_context(bs),
264                   BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL);
265 
266     ret = blk_insert_bs(blk, bs, errp);
267     if (ret < 0) {
268         goto cleanup;
269     }
270 
271     if (prealloc == PREALLOC_MODE_METADATA) {
272         prealloc = PREALLOC_MODE_OFF;
273     }
274 
275     data = (struct BlockCryptoCreateData) {
276         .blk = blk,
277         .size = size,
278         .prealloc = prealloc,
279     };
280 
281     crypto = qcrypto_block_create(opts, NULL,
282                                   block_crypto_init_func,
283                                   block_crypto_write_func,
284                                   &data,
285                                   errp);
286 
287     if (!crypto) {
288         ret = -EIO;
289         goto cleanup;
290     }
291 
292     ret = 0;
293  cleanup:
294     qcrypto_block_free(crypto);
295     blk_unref(blk);
296     return ret;
297 }
298 
299 static int coroutine_fn
300 block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
301                          PreallocMode prealloc, Error **errp)
302 {
303     BlockCrypto *crypto = bs->opaque;
304     uint64_t payload_offset =
305         qcrypto_block_get_payload_offset(crypto->block);
306 
307     if (payload_offset > INT64_MAX - offset) {
308         error_setg(errp, "The requested file size is too large");
309         return -EFBIG;
310     }
311 
312     offset += payload_offset;
313 
314     return bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
315 }
316 
317 static void block_crypto_close(BlockDriverState *bs)
318 {
319     BlockCrypto *crypto = bs->opaque;
320     qcrypto_block_free(crypto->block);
321 }
322 
323 static int block_crypto_reopen_prepare(BDRVReopenState *state,
324                                        BlockReopenQueue *queue, Error **errp)
325 {
326     /* nothing needs checking */
327     return 0;
328 }
329 
330 /*
331  * 1 MB bounce buffer gives good performance / memory tradeoff
332  * when using cache=none|directsync.
333  */
334 #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024)
335 
336 static coroutine_fn int
337 block_crypto_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
338                        QEMUIOVector *qiov, int flags)
339 {
340     BlockCrypto *crypto = bs->opaque;
341     uint64_t cur_bytes; /* number of bytes in current iteration */
342     uint64_t bytes_done = 0;
343     uint8_t *cipher_data = NULL;
344     QEMUIOVector hd_qiov;
345     int ret = 0;
346     uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block);
347     uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block);
348 
349     assert(!flags);
350     assert(payload_offset < INT64_MAX);
351     assert(QEMU_IS_ALIGNED(offset, sector_size));
352     assert(QEMU_IS_ALIGNED(bytes, sector_size));
353 
354     qemu_iovec_init(&hd_qiov, qiov->niov);
355 
356     /* Bounce buffer because we don't wish to expose cipher text
357      * in qiov which points to guest memory.
358      */
359     cipher_data =
360         qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE,
361                                               qiov->size));
362     if (cipher_data == NULL) {
363         ret = -ENOMEM;
364         goto cleanup;
365     }
366 
367     while (bytes) {
368         cur_bytes = MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE);
369 
370         qemu_iovec_reset(&hd_qiov);
371         qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes);
372 
373         ret = bdrv_co_preadv(bs->file, payload_offset + offset + bytes_done,
374                              cur_bytes, &hd_qiov, 0);
375         if (ret < 0) {
376             goto cleanup;
377         }
378 
379         if (qcrypto_block_decrypt(crypto->block, offset + bytes_done,
380                                   cipher_data, cur_bytes, NULL) < 0) {
381             ret = -EIO;
382             goto cleanup;
383         }
384 
385         qemu_iovec_from_buf(qiov, bytes_done, cipher_data, cur_bytes);
386 
387         bytes -= cur_bytes;
388         bytes_done += cur_bytes;
389     }
390 
391  cleanup:
392     qemu_iovec_destroy(&hd_qiov);
393     qemu_vfree(cipher_data);
394 
395     return ret;
396 }
397 
398 
399 static coroutine_fn int
400 block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
401                         QEMUIOVector *qiov, int flags)
402 {
403     BlockCrypto *crypto = bs->opaque;
404     uint64_t cur_bytes; /* number of bytes in current iteration */
405     uint64_t bytes_done = 0;
406     uint8_t *cipher_data = NULL;
407     QEMUIOVector hd_qiov;
408     int ret = 0;
409     uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block);
410     uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block);
411 
412     assert(!(flags & ~BDRV_REQ_FUA));
413     assert(payload_offset < INT64_MAX);
414     assert(QEMU_IS_ALIGNED(offset, sector_size));
415     assert(QEMU_IS_ALIGNED(bytes, sector_size));
416 
417     qemu_iovec_init(&hd_qiov, qiov->niov);
418 
419     /* Bounce buffer because we're not permitted to touch
420      * contents of qiov - it points to guest memory.
421      */
422     cipher_data =
423         qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE,
424                                               qiov->size));
425     if (cipher_data == NULL) {
426         ret = -ENOMEM;
427         goto cleanup;
428     }
429 
430     while (bytes) {
431         cur_bytes = MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE);
432 
433         qemu_iovec_to_buf(qiov, bytes_done, cipher_data, cur_bytes);
434 
435         if (qcrypto_block_encrypt(crypto->block, offset + bytes_done,
436                                   cipher_data, cur_bytes, NULL) < 0) {
437             ret = -EIO;
438             goto cleanup;
439         }
440 
441         qemu_iovec_reset(&hd_qiov);
442         qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes);
443 
444         ret = bdrv_co_pwritev(bs->file, payload_offset + offset + bytes_done,
445                               cur_bytes, &hd_qiov, flags);
446         if (ret < 0) {
447             goto cleanup;
448         }
449 
450         bytes -= cur_bytes;
451         bytes_done += cur_bytes;
452     }
453 
454  cleanup:
455     qemu_iovec_destroy(&hd_qiov);
456     qemu_vfree(cipher_data);
457 
458     return ret;
459 }
460 
461 static void block_crypto_refresh_limits(BlockDriverState *bs, Error **errp)
462 {
463     BlockCrypto *crypto = bs->opaque;
464     uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block);
465     bs->bl.request_alignment = sector_size; /* No sub-sector I/O */
466 }
467 
468 
469 static int64_t block_crypto_getlength(BlockDriverState *bs)
470 {
471     BlockCrypto *crypto = bs->opaque;
472     int64_t len = bdrv_getlength(bs->file->bs);
473 
474     uint64_t offset = qcrypto_block_get_payload_offset(crypto->block);
475     assert(offset < INT64_MAX);
476 
477     if (offset > len) {
478         return -EIO;
479     }
480 
481     len -= offset;
482 
483     return len;
484 }
485 
486 
487 static BlockMeasureInfo *block_crypto_measure(QemuOpts *opts,
488                                               BlockDriverState *in_bs,
489                                               Error **errp)
490 {
491     g_autoptr(QCryptoBlockCreateOptions) create_opts = NULL;
492     Error *local_err = NULL;
493     BlockMeasureInfo *info;
494     uint64_t size;
495     size_t luks_payload_size;
496     QDict *cryptoopts;
497 
498     /*
499      * Preallocation mode doesn't affect size requirements but we must consume
500      * the option.
501      */
502     g_free(qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC));
503 
504     size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
505 
506     if (in_bs) {
507         int64_t ssize = bdrv_getlength(in_bs);
508 
509         if (ssize < 0) {
510             error_setg_errno(&local_err, -ssize,
511                              "Unable to get image virtual_size");
512             goto err;
513         }
514 
515         size = ssize;
516     }
517 
518     cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL,
519             &block_crypto_create_opts_luks, true);
520     qdict_put_str(cryptoopts, "format", "luks");
521     create_opts = block_crypto_create_opts_init(cryptoopts, &local_err);
522     qobject_unref(cryptoopts);
523     if (!create_opts) {
524         goto err;
525     }
526 
527     if (!qcrypto_block_calculate_payload_offset(create_opts, NULL,
528                                                 &luks_payload_size,
529                                                 &local_err)) {
530         goto err;
531     }
532 
533     /*
534      * Unallocated blocks are still encrypted so allocation status makes no
535      * difference to the file size.
536      */
537     info = g_new(BlockMeasureInfo, 1);
538     info->fully_allocated = luks_payload_size + size;
539     info->required = luks_payload_size + size;
540     return info;
541 
542 err:
543     error_propagate(errp, local_err);
544     return NULL;
545 }
546 
547 
548 static int block_crypto_probe_luks(const uint8_t *buf,
549                                    int buf_size,
550                                    const char *filename) {
551     return block_crypto_probe_generic(Q_CRYPTO_BLOCK_FORMAT_LUKS,
552                                       buf, buf_size, filename);
553 }
554 
555 static int block_crypto_open_luks(BlockDriverState *bs,
556                                   QDict *options,
557                                   int flags,
558                                   Error **errp)
559 {
560     return block_crypto_open_generic(Q_CRYPTO_BLOCK_FORMAT_LUKS,
561                                      &block_crypto_runtime_opts_luks,
562                                      bs, options, flags, errp);
563 }
564 
565 static int coroutine_fn
566 block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp)
567 {
568     BlockdevCreateOptionsLUKS *luks_opts;
569     BlockDriverState *bs = NULL;
570     QCryptoBlockCreateOptions create_opts;
571     PreallocMode preallocation = PREALLOC_MODE_OFF;
572     int ret;
573 
574     assert(create_options->driver == BLOCKDEV_DRIVER_LUKS);
575     luks_opts = &create_options->u.luks;
576 
577     bs = bdrv_open_blockdev_ref(luks_opts->file, errp);
578     if (bs == NULL) {
579         return -EIO;
580     }
581 
582     create_opts = (QCryptoBlockCreateOptions) {
583         .format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
584         .u.luks = *qapi_BlockdevCreateOptionsLUKS_base(luks_opts),
585     };
586 
587     if (luks_opts->has_preallocation) {
588         preallocation = luks_opts->preallocation;
589     }
590 
591     ret = block_crypto_co_create_generic(bs, luks_opts->size, &create_opts,
592                                          preallocation, errp);
593     if (ret < 0) {
594         goto fail;
595     }
596 
597     ret = 0;
598 fail:
599     bdrv_unref(bs);
600     return ret;
601 }
602 
603 static int coroutine_fn block_crypto_co_create_opts_luks(const char *filename,
604                                                          QemuOpts *opts,
605                                                          Error **errp)
606 {
607     QCryptoBlockCreateOptions *create_opts = NULL;
608     BlockDriverState *bs = NULL;
609     QDict *cryptoopts;
610     PreallocMode prealloc;
611     char *buf = NULL;
612     int64_t size;
613     int ret;
614     Error *local_err = NULL;
615 
616     /* Parse options */
617     size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
618 
619     buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
620     prealloc = qapi_enum_parse(&PreallocMode_lookup, buf,
621                                PREALLOC_MODE_OFF, &local_err);
622     g_free(buf);
623     if (local_err) {
624         error_propagate(errp, local_err);
625         return -EINVAL;
626     }
627 
628     cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL,
629                                              &block_crypto_create_opts_luks,
630                                              true);
631 
632     qdict_put_str(cryptoopts, "format", "luks");
633     create_opts = block_crypto_create_opts_init(cryptoopts, errp);
634     if (!create_opts) {
635         ret = -EINVAL;
636         goto fail;
637     }
638 
639     /* Create protocol layer */
640     ret = bdrv_create_file(filename, opts, errp);
641     if (ret < 0) {
642         goto fail;
643     }
644 
645     bs = bdrv_open(filename, NULL, NULL,
646                    BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp);
647     if (!bs) {
648         ret = -EINVAL;
649         goto fail;
650     }
651 
652     /* Create format layer */
653     ret = block_crypto_co_create_generic(bs, size, create_opts, prealloc, errp);
654     if (ret < 0) {
655         goto fail;
656     }
657 
658     ret = 0;
659 fail:
660     bdrv_unref(bs);
661     qapi_free_QCryptoBlockCreateOptions(create_opts);
662     qobject_unref(cryptoopts);
663     return ret;
664 }
665 
666 static int block_crypto_get_info_luks(BlockDriverState *bs,
667                                       BlockDriverInfo *bdi)
668 {
669     BlockDriverInfo subbdi;
670     int ret;
671 
672     ret = bdrv_get_info(bs->file->bs, &subbdi);
673     if (ret != 0) {
674         return ret;
675     }
676 
677     bdi->unallocated_blocks_are_zero = false;
678     bdi->cluster_size = subbdi.cluster_size;
679 
680     return 0;
681 }
682 
683 static ImageInfoSpecific *
684 block_crypto_get_specific_info_luks(BlockDriverState *bs, Error **errp)
685 {
686     BlockCrypto *crypto = bs->opaque;
687     ImageInfoSpecific *spec_info;
688     QCryptoBlockInfo *info;
689 
690     info = qcrypto_block_get_info(crypto->block, errp);
691     if (!info) {
692         return NULL;
693     }
694     assert(info->format == Q_CRYPTO_BLOCK_FORMAT_LUKS);
695 
696     spec_info = g_new(ImageInfoSpecific, 1);
697     spec_info->type = IMAGE_INFO_SPECIFIC_KIND_LUKS;
698     spec_info->u.luks.data = g_new(QCryptoBlockInfoLUKS, 1);
699     *spec_info->u.luks.data = info->u.luks;
700 
701     /* Blank out pointers we've just stolen to avoid double free */
702     memset(&info->u.luks, 0, sizeof(info->u.luks));
703 
704     qapi_free_QCryptoBlockInfo(info);
705 
706     return spec_info;
707 }
708 
709 static const char *const block_crypto_strong_runtime_opts[] = {
710     BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET,
711 
712     NULL
713 };
714 
715 static BlockDriver bdrv_crypto_luks = {
716     .format_name        = "luks",
717     .instance_size      = sizeof(BlockCrypto),
718     .bdrv_probe         = block_crypto_probe_luks,
719     .bdrv_open          = block_crypto_open_luks,
720     .bdrv_close         = block_crypto_close,
721     /* This driver doesn't modify LUKS metadata except when creating image.
722      * Allow share-rw=on as a special case. */
723     .bdrv_child_perm    = bdrv_filter_default_perms,
724     .bdrv_co_create     = block_crypto_co_create_luks,
725     .bdrv_co_create_opts = block_crypto_co_create_opts_luks,
726     .bdrv_co_truncate   = block_crypto_co_truncate,
727     .create_opts        = &block_crypto_create_opts_luks,
728 
729     .bdrv_reopen_prepare = block_crypto_reopen_prepare,
730     .bdrv_refresh_limits = block_crypto_refresh_limits,
731     .bdrv_co_preadv     = block_crypto_co_preadv,
732     .bdrv_co_pwritev    = block_crypto_co_pwritev,
733     .bdrv_getlength     = block_crypto_getlength,
734     .bdrv_measure       = block_crypto_measure,
735     .bdrv_get_info      = block_crypto_get_info_luks,
736     .bdrv_get_specific_info = block_crypto_get_specific_info_luks,
737 
738     .strong_runtime_opts = block_crypto_strong_runtime_opts,
739 };
740 
741 static void block_crypto_init(void)
742 {
743     bdrv_register(&bdrv_crypto_luks);
744 }
745 
746 block_init(block_crypto_init);
747