2 * QEMU Enhanced Disk Format
4 * Copyright IBM, Corp. 2010
7 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
8 * Anthony Liguori <aliguori@us.ibm.com>
10 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
11 * See the COPYING.LIB file in the top-level directory.
15 #include "qemu/osdep.h"
16 #include "qapi/error.h"
17 #include "qemu/timer.h"
18 #include "qemu/bswap.h"
19 #include "qemu/option.h"
22 #include "sysemu/block-backend.h"
24 static int bdrv_qed_probe(const uint8_t *buf
, int buf_size
,
27 const QEDHeader
*header
= (const QEDHeader
*)buf
;
29 if (buf_size
< sizeof(*header
)) {
32 if (le32_to_cpu(header
->magic
) != QED_MAGIC
) {
39 * Check whether an image format is raw
41 * @fmt: Backing file format, may be NULL
43 static bool qed_fmt_is_raw(const char *fmt
)
45 return fmt
&& strcmp(fmt
, "raw") == 0;
48 static void qed_header_le_to_cpu(const QEDHeader
*le
, QEDHeader
*cpu
)
50 cpu
->magic
= le32_to_cpu(le
->magic
);
51 cpu
->cluster_size
= le32_to_cpu(le
->cluster_size
);
52 cpu
->table_size
= le32_to_cpu(le
->table_size
);
53 cpu
->header_size
= le32_to_cpu(le
->header_size
);
54 cpu
->features
= le64_to_cpu(le
->features
);
55 cpu
->compat_features
= le64_to_cpu(le
->compat_features
);
56 cpu
->autoclear_features
= le64_to_cpu(le
->autoclear_features
);
57 cpu
->l1_table_offset
= le64_to_cpu(le
->l1_table_offset
);
58 cpu
->image_size
= le64_to_cpu(le
->image_size
);
59 cpu
->backing_filename_offset
= le32_to_cpu(le
->backing_filename_offset
);
60 cpu
->backing_filename_size
= le32_to_cpu(le
->backing_filename_size
);
63 static void qed_header_cpu_to_le(const QEDHeader
*cpu
, QEDHeader
*le
)
65 le
->magic
= cpu_to_le32(cpu
->magic
);
66 le
->cluster_size
= cpu_to_le32(cpu
->cluster_size
);
67 le
->table_size
= cpu_to_le32(cpu
->table_size
);
68 le
->header_size
= cpu_to_le32(cpu
->header_size
);
69 le
->features
= cpu_to_le64(cpu
->features
);
70 le
->compat_features
= cpu_to_le64(cpu
->compat_features
);
71 le
->autoclear_features
= cpu_to_le64(cpu
->autoclear_features
);
72 le
->l1_table_offset
= cpu_to_le64(cpu
->l1_table_offset
);
73 le
->image_size
= cpu_to_le64(cpu
->image_size
);
74 le
->backing_filename_offset
= cpu_to_le32(cpu
->backing_filename_offset
);
75 le
->backing_filename_size
= cpu_to_le32(cpu
->backing_filename_size
);
78 int qed_write_header_sync(BDRVQEDState
*s
)
83 qed_header_cpu_to_le(&s
->header
, &le
);
84 ret
= bdrv_pwrite(s
->bs
->file
, 0, &le
, sizeof(le
));
85 if (ret
!= sizeof(le
)) {
92 * Update header in-place (does not rewrite backing filename or other strings)
94 * This function only updates known header fields in-place and does not affect
95 * extra data after the QED header.
97 * No new allocating reqs can start while this function runs.
99 static int coroutine_fn
qed_write_header(BDRVQEDState
*s
)
101 /* We must write full sectors for O_DIRECT but cannot necessarily generate
102 * the data following the header if an unrecognized compat feature is
103 * active. Therefore, first read the sectors containing the header, update
104 * them, and write back.
107 int nsectors
= DIV_ROUND_UP(sizeof(QEDHeader
), BDRV_SECTOR_SIZE
);
108 size_t len
= nsectors
* BDRV_SECTOR_SIZE
;
114 assert(s
->allocating_acb
|| s
->allocating_write_reqs_plugged
);
116 buf
= qemu_blockalign(s
->bs
, len
);
117 iov
= (struct iovec
) {
121 qemu_iovec_init_external(&qiov
, &iov
, 1);
123 ret
= bdrv_co_preadv(s
->bs
->file
, 0, qiov
.size
, &qiov
, 0);
129 qed_header_cpu_to_le(&s
->header
, (QEDHeader
*) buf
);
131 ret
= bdrv_co_pwritev(s
->bs
->file
, 0, qiov
.size
, &qiov
, 0);
142 static uint64_t qed_max_image_size(uint32_t cluster_size
, uint32_t table_size
)
144 uint64_t table_entries
;
147 table_entries
= (table_size
* cluster_size
) / sizeof(uint64_t);
148 l2_size
= table_entries
* cluster_size
;
150 return l2_size
* table_entries
;
153 static bool qed_is_cluster_size_valid(uint32_t cluster_size
)
155 if (cluster_size
< QED_MIN_CLUSTER_SIZE
||
156 cluster_size
> QED_MAX_CLUSTER_SIZE
) {
159 if (cluster_size
& (cluster_size
- 1)) {
160 return false; /* not power of 2 */
165 static bool qed_is_table_size_valid(uint32_t table_size
)
167 if (table_size
< QED_MIN_TABLE_SIZE
||
168 table_size
> QED_MAX_TABLE_SIZE
) {
171 if (table_size
& (table_size
- 1)) {
172 return false; /* not power of 2 */
177 static bool qed_is_image_size_valid(uint64_t image_size
, uint32_t cluster_size
,
180 if (image_size
% BDRV_SECTOR_SIZE
!= 0) {
181 return false; /* not multiple of sector size */
183 if (image_size
> qed_max_image_size(cluster_size
, table_size
)) {
184 return false; /* image is too large */
190 * Read a string of known length from the image file
193 * @offset: File offset to start of string, in bytes
194 * @n: String length in bytes
195 * @buf: Destination buffer
196 * @buflen: Destination buffer length in bytes
197 * @ret: 0 on success, -errno on failure
199 * The string is NUL-terminated.
201 static int qed_read_string(BdrvChild
*file
, uint64_t offset
, size_t n
,
202 char *buf
, size_t buflen
)
208 ret
= bdrv_pread(file
, offset
, buf
, n
);
217 * Allocate new clusters
220 * @n: Number of contiguous clusters to allocate
221 * @ret: Offset of first allocated cluster
223 * This function only produces the offset where the new clusters should be
224 * written. It updates BDRVQEDState but does not make any changes to the image
227 * Called with table_lock held.
229 static uint64_t qed_alloc_clusters(BDRVQEDState
*s
, unsigned int n
)
231 uint64_t offset
= s
->file_size
;
232 s
->file_size
+= n
* s
->header
.cluster_size
;
236 QEDTable
*qed_alloc_table(BDRVQEDState
*s
)
238 /* Honor O_DIRECT memory alignment requirements */
239 return qemu_blockalign(s
->bs
,
240 s
->header
.cluster_size
* s
->header
.table_size
);
244 * Allocate a new zeroed L2 table
246 * Called with table_lock held.
248 static CachedL2Table
*qed_new_l2_table(BDRVQEDState
*s
)
250 CachedL2Table
*l2_table
= qed_alloc_l2_cache_entry(&s
->l2_cache
);
252 l2_table
->table
= qed_alloc_table(s
);
253 l2_table
->offset
= qed_alloc_clusters(s
, s
->header
.table_size
);
255 memset(l2_table
->table
->offsets
, 0,
256 s
->header
.cluster_size
* s
->header
.table_size
);
260 static bool qed_plug_allocating_write_reqs(BDRVQEDState
*s
)
262 qemu_co_mutex_lock(&s
->table_lock
);
264 /* No reentrancy is allowed. */
265 assert(!s
->allocating_write_reqs_plugged
);
266 if (s
->allocating_acb
!= NULL
) {
267 /* Another allocating write came concurrently. This cannot happen
268 * from bdrv_qed_co_drain_begin, but it can happen when the timer runs.
270 qemu_co_mutex_unlock(&s
->table_lock
);
274 s
->allocating_write_reqs_plugged
= true;
275 qemu_co_mutex_unlock(&s
->table_lock
);
279 static void qed_unplug_allocating_write_reqs(BDRVQEDState
*s
)
281 qemu_co_mutex_lock(&s
->table_lock
);
282 assert(s
->allocating_write_reqs_plugged
);
283 s
->allocating_write_reqs_plugged
= false;
284 qemu_co_queue_next(&s
->allocating_write_reqs
);
285 qemu_co_mutex_unlock(&s
->table_lock
);
288 static void coroutine_fn
qed_need_check_timer_entry(void *opaque
)
290 BDRVQEDState
*s
= opaque
;
293 trace_qed_need_check_timer_cb(s
);
295 if (!qed_plug_allocating_write_reqs(s
)) {
299 /* Ensure writes are on disk before clearing flag */
300 ret
= bdrv_co_flush(s
->bs
->file
->bs
);
302 qed_unplug_allocating_write_reqs(s
);
306 s
->header
.features
&= ~QED_F_NEED_CHECK
;
307 ret
= qed_write_header(s
);
310 qed_unplug_allocating_write_reqs(s
);
312 ret
= bdrv_co_flush(s
->bs
);
316 static void qed_need_check_timer_cb(void *opaque
)
318 Coroutine
*co
= qemu_coroutine_create(qed_need_check_timer_entry
, opaque
);
319 qemu_coroutine_enter(co
);
322 static void qed_start_need_check_timer(BDRVQEDState
*s
)
324 trace_qed_start_need_check_timer(s
);
326 /* Use QEMU_CLOCK_VIRTUAL so we don't alter the image file while suspended for
329 timer_mod(s
->need_check_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
330 NANOSECONDS_PER_SECOND
* QED_NEED_CHECK_TIMEOUT
);
333 /* It's okay to call this multiple times or when no timer is started */
334 static void qed_cancel_need_check_timer(BDRVQEDState
*s
)
336 trace_qed_cancel_need_check_timer(s
);
337 timer_del(s
->need_check_timer
);
340 static void bdrv_qed_detach_aio_context(BlockDriverState
*bs
)
342 BDRVQEDState
*s
= bs
->opaque
;
344 qed_cancel_need_check_timer(s
);
345 timer_free(s
->need_check_timer
);
348 static void bdrv_qed_attach_aio_context(BlockDriverState
*bs
,
349 AioContext
*new_context
)
351 BDRVQEDState
*s
= bs
->opaque
;
353 s
->need_check_timer
= aio_timer_new(new_context
,
354 QEMU_CLOCK_VIRTUAL
, SCALE_NS
,
355 qed_need_check_timer_cb
, s
);
356 if (s
->header
.features
& QED_F_NEED_CHECK
) {
357 qed_start_need_check_timer(s
);
361 static void coroutine_fn
bdrv_qed_co_drain_begin(BlockDriverState
*bs
)
363 BDRVQEDState
*s
= bs
->opaque
;
365 /* Fire the timer immediately in order to start doing I/O as soon as the
368 if (s
->need_check_timer
&& timer_pending(s
->need_check_timer
)) {
369 qed_cancel_need_check_timer(s
);
370 qed_need_check_timer_entry(s
);
374 static void bdrv_qed_init_state(BlockDriverState
*bs
)
376 BDRVQEDState
*s
= bs
->opaque
;
378 memset(s
, 0, sizeof(BDRVQEDState
));
380 qemu_co_mutex_init(&s
->table_lock
);
381 qemu_co_queue_init(&s
->allocating_write_reqs
);
384 /* Called with table_lock held. */
385 static int coroutine_fn
bdrv_qed_do_open(BlockDriverState
*bs
, QDict
*options
,
386 int flags
, Error
**errp
)
388 BDRVQEDState
*s
= bs
->opaque
;
393 ret
= bdrv_pread(bs
->file
, 0, &le_header
, sizeof(le_header
));
397 qed_header_le_to_cpu(&le_header
, &s
->header
);
399 if (s
->header
.magic
!= QED_MAGIC
) {
400 error_setg(errp
, "Image not in QED format");
403 if (s
->header
.features
& ~QED_FEATURE_MASK
) {
404 /* image uses unsupported feature bits */
405 error_setg(errp
, "Unsupported QED features: %" PRIx64
,
406 s
->header
.features
& ~QED_FEATURE_MASK
);
409 if (!qed_is_cluster_size_valid(s
->header
.cluster_size
)) {
413 /* Round down file size to the last cluster */
414 file_size
= bdrv_getlength(bs
->file
->bs
);
418 s
->file_size
= qed_start_of_cluster(s
, file_size
);
420 if (!qed_is_table_size_valid(s
->header
.table_size
)) {
423 if (!qed_is_image_size_valid(s
->header
.image_size
,
424 s
->header
.cluster_size
,
425 s
->header
.table_size
)) {
428 if (!qed_check_table_offset(s
, s
->header
.l1_table_offset
)) {
432 s
->table_nelems
= (s
->header
.cluster_size
* s
->header
.table_size
) /
434 s
->l2_shift
= ctz32(s
->header
.cluster_size
);
435 s
->l2_mask
= s
->table_nelems
- 1;
436 s
->l1_shift
= s
->l2_shift
+ ctz32(s
->table_nelems
);
438 /* Header size calculation must not overflow uint32_t */
439 if (s
->header
.header_size
> UINT32_MAX
/ s
->header
.cluster_size
) {
443 if ((s
->header
.features
& QED_F_BACKING_FILE
)) {
444 if ((uint64_t)s
->header
.backing_filename_offset
+
445 s
->header
.backing_filename_size
>
446 s
->header
.cluster_size
* s
->header
.header_size
) {
450 ret
= qed_read_string(bs
->file
, s
->header
.backing_filename_offset
,
451 s
->header
.backing_filename_size
, bs
->backing_file
,
452 sizeof(bs
->backing_file
));
457 if (s
->header
.features
& QED_F_BACKING_FORMAT_NO_PROBE
) {
458 pstrcpy(bs
->backing_format
, sizeof(bs
->backing_format
), "raw");
462 /* Reset unknown autoclear feature bits. This is a backwards
463 * compatibility mechanism that allows images to be opened by older
464 * programs, which "knock out" unknown feature bits. When an image is
465 * opened by a newer program again it can detect that the autoclear
466 * feature is no longer valid.
468 if ((s
->header
.autoclear_features
& ~QED_AUTOCLEAR_FEATURE_MASK
) != 0 &&
469 !bdrv_is_read_only(bs
->file
->bs
) && !(flags
& BDRV_O_INACTIVE
)) {
470 s
->header
.autoclear_features
&= QED_AUTOCLEAR_FEATURE_MASK
;
472 ret
= qed_write_header_sync(s
);
477 /* From here on only known autoclear feature bits are valid */
478 bdrv_flush(bs
->file
->bs
);
481 s
->l1_table
= qed_alloc_table(s
);
482 qed_init_l2_cache(&s
->l2_cache
);
484 ret
= qed_read_l1_table_sync(s
);
489 /* If image was not closed cleanly, check consistency */
490 if (!(flags
& BDRV_O_CHECK
) && (s
->header
.features
& QED_F_NEED_CHECK
)) {
491 /* Read-only images cannot be fixed. There is no risk of corruption
492 * since write operations are not possible. Therefore, allow
493 * potentially inconsistent images to be opened read-only. This can
494 * aid data recovery from an otherwise inconsistent image.
496 if (!bdrv_is_read_only(bs
->file
->bs
) &&
497 !(flags
& BDRV_O_INACTIVE
)) {
498 BdrvCheckResult result
= {0};
500 ret
= qed_check(s
, &result
, true);
507 bdrv_qed_attach_aio_context(bs
, bdrv_get_aio_context(bs
));
511 qed_free_l2_cache(&s
->l2_cache
);
512 qemu_vfree(s
->l1_table
);
517 typedef struct QEDOpenCo
{
518 BlockDriverState
*bs
;
525 static void coroutine_fn
bdrv_qed_open_entry(void *opaque
)
527 QEDOpenCo
*qoc
= opaque
;
528 BDRVQEDState
*s
= qoc
->bs
->opaque
;
530 qemu_co_mutex_lock(&s
->table_lock
);
531 qoc
->ret
= bdrv_qed_do_open(qoc
->bs
, qoc
->options
, qoc
->flags
, qoc
->errp
);
532 qemu_co_mutex_unlock(&s
->table_lock
);
535 static int bdrv_qed_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
546 bs
->file
= bdrv_open_child(NULL
, options
, "file", bs
, &child_file
,
552 bdrv_qed_init_state(bs
);
553 if (qemu_in_coroutine()) {
554 bdrv_qed_open_entry(&qoc
);
556 qemu_coroutine_enter(qemu_coroutine_create(bdrv_qed_open_entry
, &qoc
));
557 BDRV_POLL_WHILE(bs
, qoc
.ret
== -EINPROGRESS
);
559 BDRV_POLL_WHILE(bs
, qoc
.ret
== -EINPROGRESS
);
563 static void bdrv_qed_refresh_limits(BlockDriverState
*bs
, Error
**errp
)
565 BDRVQEDState
*s
= bs
->opaque
;
567 bs
->bl
.pwrite_zeroes_alignment
= s
->header
.cluster_size
;
570 /* We have nothing to do for QED reopen, stubs just return
572 static int bdrv_qed_reopen_prepare(BDRVReopenState
*state
,
573 BlockReopenQueue
*queue
, Error
**errp
)
578 static void bdrv_qed_close(BlockDriverState
*bs
)
580 BDRVQEDState
*s
= bs
->opaque
;
582 bdrv_qed_detach_aio_context(bs
);
584 /* Ensure writes reach stable storage */
585 bdrv_flush(bs
->file
->bs
);
587 /* Clean shutdown, no check required on next open */
588 if (s
->header
.features
& QED_F_NEED_CHECK
) {
589 s
->header
.features
&= ~QED_F_NEED_CHECK
;
590 qed_write_header_sync(s
);
593 qed_free_l2_cache(&s
->l2_cache
);
594 qemu_vfree(s
->l1_table
);
597 static int qed_create(const char *filename
, uint32_t cluster_size
,
598 uint64_t image_size
, uint32_t table_size
,
599 const char *backing_file
, const char *backing_fmt
,
600 QemuOpts
*opts
, Error
**errp
)
604 .cluster_size
= cluster_size
,
605 .table_size
= table_size
,
608 .compat_features
= 0,
609 .l1_table_offset
= cluster_size
,
610 .image_size
= image_size
,
613 uint8_t *l1_table
= NULL
;
614 size_t l1_size
= header
.cluster_size
* header
.table_size
;
615 Error
*local_err
= NULL
;
619 ret
= bdrv_create_file(filename
, opts
, &local_err
);
621 error_propagate(errp
, local_err
);
625 blk
= blk_new_open(filename
, NULL
, NULL
,
626 BDRV_O_RDWR
| BDRV_O_RESIZE
| BDRV_O_PROTOCOL
,
629 error_propagate(errp
, local_err
);
633 blk_set_allow_write_beyond_eof(blk
, true);
635 /* File must start empty and grow, check truncate is supported */
636 ret
= blk_truncate(blk
, 0, PREALLOC_MODE_OFF
, errp
);
642 header
.features
|= QED_F_BACKING_FILE
;
643 header
.backing_filename_offset
= sizeof(le_header
);
644 header
.backing_filename_size
= strlen(backing_file
);
646 if (qed_fmt_is_raw(backing_fmt
)) {
647 header
.features
|= QED_F_BACKING_FORMAT_NO_PROBE
;
651 qed_header_cpu_to_le(&header
, &le_header
);
652 ret
= blk_pwrite(blk
, 0, &le_header
, sizeof(le_header
), 0);
656 ret
= blk_pwrite(blk
, sizeof(le_header
), backing_file
,
657 header
.backing_filename_size
, 0);
662 l1_table
= g_malloc0(l1_size
);
663 ret
= blk_pwrite(blk
, header
.l1_table_offset
, l1_table
, l1_size
, 0);
668 ret
= 0; /* success */
675 static int coroutine_fn
bdrv_qed_co_create_opts(const char *filename
,
679 uint64_t image_size
= 0;
680 uint32_t cluster_size
= QED_DEFAULT_CLUSTER_SIZE
;
681 uint32_t table_size
= QED_DEFAULT_TABLE_SIZE
;
682 char *backing_file
= NULL
;
683 char *backing_fmt
= NULL
;
686 image_size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
688 backing_file
= qemu_opt_get_del(opts
, BLOCK_OPT_BACKING_FILE
);
689 backing_fmt
= qemu_opt_get_del(opts
, BLOCK_OPT_BACKING_FMT
);
690 cluster_size
= qemu_opt_get_size_del(opts
,
691 BLOCK_OPT_CLUSTER_SIZE
,
692 QED_DEFAULT_CLUSTER_SIZE
);
693 table_size
= qemu_opt_get_size_del(opts
, BLOCK_OPT_TABLE_SIZE
,
694 QED_DEFAULT_TABLE_SIZE
);
696 if (!qed_is_cluster_size_valid(cluster_size
)) {
697 error_setg(errp
, "QED cluster size must be within range [%u, %u] "
699 QED_MIN_CLUSTER_SIZE
, QED_MAX_CLUSTER_SIZE
);
703 if (!qed_is_table_size_valid(table_size
)) {
704 error_setg(errp
, "QED table size must be within range [%u, %u] "
706 QED_MIN_TABLE_SIZE
, QED_MAX_TABLE_SIZE
);
710 if (!qed_is_image_size_valid(image_size
, cluster_size
, table_size
)) {
711 error_setg(errp
, "QED image size must be a non-zero multiple of "
712 "cluster size and less than %" PRIu64
" bytes",
713 qed_max_image_size(cluster_size
, table_size
));
718 ret
= qed_create(filename
, cluster_size
, image_size
, table_size
,
719 backing_file
, backing_fmt
, opts
, errp
);
722 g_free(backing_file
);
727 static int coroutine_fn
bdrv_qed_co_block_status(BlockDriverState
*bs
,
729 int64_t pos
, int64_t bytes
,
730 int64_t *pnum
, int64_t *map
,
731 BlockDriverState
**file
)
733 BDRVQEDState
*s
= bs
->opaque
;
734 size_t len
= MIN(bytes
, SIZE_MAX
);
736 QEDRequest request
= { .l2_table
= NULL
};
740 qemu_co_mutex_lock(&s
->table_lock
);
741 ret
= qed_find_cluster(s
, &request
, pos
, &len
, &offset
);
745 case QED_CLUSTER_FOUND
:
746 *map
= offset
| qed_offset_into_cluster(s
, pos
);
747 status
= BDRV_BLOCK_DATA
| BDRV_BLOCK_OFFSET_VALID
;
748 *file
= bs
->file
->bs
;
750 case QED_CLUSTER_ZERO
:
751 status
= BDRV_BLOCK_ZERO
;
763 qed_unref_l2_cache_entry(request
.l2_table
);
764 qemu_co_mutex_unlock(&s
->table_lock
);
769 static BDRVQEDState
*acb_to_s(QEDAIOCB
*acb
)
771 return acb
->bs
->opaque
;
775 * Read from the backing file or zero-fill if no backing file
778 * @pos: Byte position in device
779 * @qiov: Destination I/O vector
780 * @backing_qiov: Possibly shortened copy of qiov, to be allocated here
781 * @cb: Completion function
782 * @opaque: User data for completion function
784 * This function reads qiov->size bytes starting at pos from the backing file.
785 * If there is no backing file then zeroes are read.
787 static int coroutine_fn
qed_read_backing_file(BDRVQEDState
*s
, uint64_t pos
,
789 QEMUIOVector
**backing_qiov
)
791 uint64_t backing_length
= 0;
795 /* If there is a backing file, get its length. Treat the absence of a
796 * backing file like a zero length backing file.
798 if (s
->bs
->backing
) {
799 int64_t l
= bdrv_getlength(s
->bs
->backing
->bs
);
806 /* Zero all sectors if reading beyond the end of the backing file */
807 if (pos
>= backing_length
||
808 pos
+ qiov
->size
> backing_length
) {
809 qemu_iovec_memset(qiov
, 0, 0, qiov
->size
);
812 /* Complete now if there are no backing file sectors to read */
813 if (pos
>= backing_length
) {
817 /* If the read straddles the end of the backing file, shorten it */
818 size
= MIN((uint64_t)backing_length
- pos
, qiov
->size
);
820 assert(*backing_qiov
== NULL
);
821 *backing_qiov
= g_new(QEMUIOVector
, 1);
822 qemu_iovec_init(*backing_qiov
, qiov
->niov
);
823 qemu_iovec_concat(*backing_qiov
, qiov
, 0, size
);
825 BLKDBG_EVENT(s
->bs
->file
, BLKDBG_READ_BACKING_AIO
);
826 ret
= bdrv_co_preadv(s
->bs
->backing
, pos
, size
, *backing_qiov
, 0);
834 * Copy data from backing file into the image
837 * @pos: Byte position in device
838 * @len: Number of bytes
839 * @offset: Byte offset in image file
841 static int coroutine_fn
qed_copy_from_backing_file(BDRVQEDState
*s
,
842 uint64_t pos
, uint64_t len
,
846 QEMUIOVector
*backing_qiov
= NULL
;
850 /* Skip copy entirely if there is no work to do */
855 iov
= (struct iovec
) {
856 .iov_base
= qemu_blockalign(s
->bs
, len
),
859 qemu_iovec_init_external(&qiov
, &iov
, 1);
861 ret
= qed_read_backing_file(s
, pos
, &qiov
, &backing_qiov
);
864 qemu_iovec_destroy(backing_qiov
);
865 g_free(backing_qiov
);
873 BLKDBG_EVENT(s
->bs
->file
, BLKDBG_COW_WRITE
);
874 ret
= bdrv_co_pwritev(s
->bs
->file
, offset
, qiov
.size
, &qiov
, 0);
880 qemu_vfree(iov
.iov_base
);
885 * Link one or more contiguous clusters into a table
889 * @index: First cluster index
890 * @n: Number of contiguous clusters
891 * @cluster: First cluster offset
893 * The cluster offset may be an allocated byte offset in the image file, the
894 * zero cluster marker, or the unallocated cluster marker.
896 * Called with table_lock held.
898 static void coroutine_fn
qed_update_l2_table(BDRVQEDState
*s
, QEDTable
*table
,
899 int index
, unsigned int n
,
903 for (i
= index
; i
< index
+ n
; i
++) {
904 table
->offsets
[i
] = cluster
;
905 if (!qed_offset_is_unalloc_cluster(cluster
) &&
906 !qed_offset_is_zero_cluster(cluster
)) {
907 cluster
+= s
->header
.cluster_size
;
912 /* Called with table_lock held. */
913 static void coroutine_fn
qed_aio_complete(QEDAIOCB
*acb
)
915 BDRVQEDState
*s
= acb_to_s(acb
);
918 qemu_iovec_destroy(&acb
->cur_qiov
);
919 qed_unref_l2_cache_entry(acb
->request
.l2_table
);
921 /* Free the buffer we may have allocated for zero writes */
922 if (acb
->flags
& QED_AIOCB_ZERO
) {
923 qemu_vfree(acb
->qiov
->iov
[0].iov_base
);
924 acb
->qiov
->iov
[0].iov_base
= NULL
;
927 /* Start next allocating write request waiting behind this one. Note that
928 * requests enqueue themselves when they first hit an unallocated cluster
929 * but they wait until the entire request is finished before waking up the
930 * next request in the queue. This ensures that we don't cycle through
931 * requests multiple times but rather finish one at a time completely.
933 if (acb
== s
->allocating_acb
) {
934 s
->allocating_acb
= NULL
;
935 if (!qemu_co_queue_empty(&s
->allocating_write_reqs
)) {
936 qemu_co_queue_next(&s
->allocating_write_reqs
);
937 } else if (s
->header
.features
& QED_F_NEED_CHECK
) {
938 qed_start_need_check_timer(s
);
944 * Update L1 table with new L2 table offset and write it out
946 * Called with table_lock held.
948 static int coroutine_fn
qed_aio_write_l1_update(QEDAIOCB
*acb
)
950 BDRVQEDState
*s
= acb_to_s(acb
);
951 CachedL2Table
*l2_table
= acb
->request
.l2_table
;
952 uint64_t l2_offset
= l2_table
->offset
;
955 index
= qed_l1_index(s
, acb
->cur_pos
);
956 s
->l1_table
->offsets
[index
] = l2_table
->offset
;
958 ret
= qed_write_l1_table(s
, index
, 1);
960 /* Commit the current L2 table to the cache */
961 qed_commit_l2_cache_entry(&s
->l2_cache
, l2_table
);
963 /* This is guaranteed to succeed because we just committed the entry to the
966 acb
->request
.l2_table
= qed_find_l2_cache_entry(&s
->l2_cache
, l2_offset
);
967 assert(acb
->request
.l2_table
!= NULL
);
974 * Update L2 table with new cluster offsets and write them out
976 * Called with table_lock held.
978 static int coroutine_fn
qed_aio_write_l2_update(QEDAIOCB
*acb
, uint64_t offset
)
980 BDRVQEDState
*s
= acb_to_s(acb
);
981 bool need_alloc
= acb
->find_cluster_ret
== QED_CLUSTER_L1
;
985 qed_unref_l2_cache_entry(acb
->request
.l2_table
);
986 acb
->request
.l2_table
= qed_new_l2_table(s
);
989 index
= qed_l2_index(s
, acb
->cur_pos
);
990 qed_update_l2_table(s
, acb
->request
.l2_table
->table
, index
, acb
->cur_nclusters
,
994 /* Write out the whole new L2 table */
995 ret
= qed_write_l2_table(s
, &acb
->request
, 0, s
->table_nelems
, true);
999 return qed_aio_write_l1_update(acb
);
1001 /* Write out only the updated part of the L2 table */
1002 ret
= qed_write_l2_table(s
, &acb
->request
, index
, acb
->cur_nclusters
,
1012 * Write data to the image file
1014 * Called with table_lock *not* held.
1016 static int coroutine_fn
qed_aio_write_main(QEDAIOCB
*acb
)
1018 BDRVQEDState
*s
= acb_to_s(acb
);
1019 uint64_t offset
= acb
->cur_cluster
+
1020 qed_offset_into_cluster(s
, acb
->cur_pos
);
1022 trace_qed_aio_write_main(s
, acb
, 0, offset
, acb
->cur_qiov
.size
);
1024 BLKDBG_EVENT(s
->bs
->file
, BLKDBG_WRITE_AIO
);
1025 return bdrv_co_pwritev(s
->bs
->file
, offset
, acb
->cur_qiov
.size
,
1030 * Populate untouched regions of new data cluster
1032 * Called with table_lock held.
1034 static int coroutine_fn
qed_aio_write_cow(QEDAIOCB
*acb
)
1036 BDRVQEDState
*s
= acb_to_s(acb
);
1037 uint64_t start
, len
, offset
;
1040 qemu_co_mutex_unlock(&s
->table_lock
);
1042 /* Populate front untouched region of new data cluster */
1043 start
= qed_start_of_cluster(s
, acb
->cur_pos
);
1044 len
= qed_offset_into_cluster(s
, acb
->cur_pos
);
1046 trace_qed_aio_write_prefill(s
, acb
, start
, len
, acb
->cur_cluster
);
1047 ret
= qed_copy_from_backing_file(s
, start
, len
, acb
->cur_cluster
);
1052 /* Populate back untouched region of new data cluster */
1053 start
= acb
->cur_pos
+ acb
->cur_qiov
.size
;
1054 len
= qed_start_of_cluster(s
, start
+ s
->header
.cluster_size
- 1) - start
;
1055 offset
= acb
->cur_cluster
+
1056 qed_offset_into_cluster(s
, acb
->cur_pos
) +
1059 trace_qed_aio_write_postfill(s
, acb
, start
, len
, offset
);
1060 ret
= qed_copy_from_backing_file(s
, start
, len
, offset
);
1065 ret
= qed_aio_write_main(acb
);
1070 if (s
->bs
->backing
) {
1072 * Flush new data clusters before updating the L2 table
1074 * This flush is necessary when a backing file is in use. A crash
1075 * during an allocating write could result in empty clusters in the
1076 * image. If the write only touched a subregion of the cluster,
1077 * then backing image sectors have been lost in the untouched
1078 * region. The solution is to flush after writing a new data
1079 * cluster and before updating the L2 table.
1081 ret
= bdrv_co_flush(s
->bs
->file
->bs
);
1085 qemu_co_mutex_lock(&s
->table_lock
);
1090 * Check if the QED_F_NEED_CHECK bit should be set during allocating write
1092 static bool qed_should_set_need_check(BDRVQEDState
*s
)
1094 /* The flush before L2 update path ensures consistency */
1095 if (s
->bs
->backing
) {
1099 return !(s
->header
.features
& QED_F_NEED_CHECK
);
1103 * Write new data cluster
1105 * @acb: Write request
1106 * @len: Length in bytes
1108 * This path is taken when writing to previously unallocated clusters.
1110 * Called with table_lock held.
1112 static int coroutine_fn
qed_aio_write_alloc(QEDAIOCB
*acb
, size_t len
)
1114 BDRVQEDState
*s
= acb_to_s(acb
);
1117 /* Cancel timer when the first allocating request comes in */
1118 if (s
->allocating_acb
== NULL
) {
1119 qed_cancel_need_check_timer(s
);
1122 /* Freeze this request if another allocating write is in progress */
1123 if (s
->allocating_acb
!= acb
|| s
->allocating_write_reqs_plugged
) {
1124 if (s
->allocating_acb
!= NULL
) {
1125 qemu_co_queue_wait(&s
->allocating_write_reqs
, &s
->table_lock
);
1126 assert(s
->allocating_acb
== NULL
);
1128 s
->allocating_acb
= acb
;
1129 return -EAGAIN
; /* start over with looking up table entries */
1132 acb
->cur_nclusters
= qed_bytes_to_clusters(s
,
1133 qed_offset_into_cluster(s
, acb
->cur_pos
) + len
);
1134 qemu_iovec_concat(&acb
->cur_qiov
, acb
->qiov
, acb
->qiov_offset
, len
);
1136 if (acb
->flags
& QED_AIOCB_ZERO
) {
1137 /* Skip ahead if the clusters are already zero */
1138 if (acb
->find_cluster_ret
== QED_CLUSTER_ZERO
) {
1141 acb
->cur_cluster
= 1;
1143 acb
->cur_cluster
= qed_alloc_clusters(s
, acb
->cur_nclusters
);
1146 if (qed_should_set_need_check(s
)) {
1147 s
->header
.features
|= QED_F_NEED_CHECK
;
1148 ret
= qed_write_header(s
);
1154 if (!(acb
->flags
& QED_AIOCB_ZERO
)) {
1155 ret
= qed_aio_write_cow(acb
);
1161 return qed_aio_write_l2_update(acb
, acb
->cur_cluster
);
1165 * Write data cluster in place
1167 * @acb: Write request
1168 * @offset: Cluster offset in bytes
1169 * @len: Length in bytes
1171 * This path is taken when writing to already allocated clusters.
1173 * Called with table_lock held.
1175 static int coroutine_fn
qed_aio_write_inplace(QEDAIOCB
*acb
, uint64_t offset
,
1178 BDRVQEDState
*s
= acb_to_s(acb
);
1181 qemu_co_mutex_unlock(&s
->table_lock
);
1183 /* Allocate buffer for zero writes */
1184 if (acb
->flags
& QED_AIOCB_ZERO
) {
1185 struct iovec
*iov
= acb
->qiov
->iov
;
1187 if (!iov
->iov_base
) {
1188 iov
->iov_base
= qemu_try_blockalign(acb
->bs
, iov
->iov_len
);
1189 if (iov
->iov_base
== NULL
) {
1193 memset(iov
->iov_base
, 0, iov
->iov_len
);
1197 /* Calculate the I/O vector */
1198 acb
->cur_cluster
= offset
;
1199 qemu_iovec_concat(&acb
->cur_qiov
, acb
->qiov
, acb
->qiov_offset
, len
);
1201 /* Do the actual write. */
1202 r
= qed_aio_write_main(acb
);
1204 qemu_co_mutex_lock(&s
->table_lock
);
1209 * Write data cluster
1211 * @opaque: Write request
1212 * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1
1213 * @offset: Cluster offset in bytes
1214 * @len: Length in bytes
1216 * Called with table_lock held.
1218 static int coroutine_fn
qed_aio_write_data(void *opaque
, int ret
,
1219 uint64_t offset
, size_t len
)
1221 QEDAIOCB
*acb
= opaque
;
1223 trace_qed_aio_write_data(acb_to_s(acb
), acb
, ret
, offset
, len
);
1225 acb
->find_cluster_ret
= ret
;
1228 case QED_CLUSTER_FOUND
:
1229 return qed_aio_write_inplace(acb
, offset
, len
);
1231 case QED_CLUSTER_L2
:
1232 case QED_CLUSTER_L1
:
1233 case QED_CLUSTER_ZERO
:
1234 return qed_aio_write_alloc(acb
, len
);
1237 g_assert_not_reached();
1244 * @opaque: Read request
1245 * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1
1246 * @offset: Cluster offset in bytes
1247 * @len: Length in bytes
1249 * Called with table_lock held.
1251 static int coroutine_fn
qed_aio_read_data(void *opaque
, int ret
,
1252 uint64_t offset
, size_t len
)
1254 QEDAIOCB
*acb
= opaque
;
1255 BDRVQEDState
*s
= acb_to_s(acb
);
1256 BlockDriverState
*bs
= acb
->bs
;
1259 qemu_co_mutex_unlock(&s
->table_lock
);
1261 /* Adjust offset into cluster */
1262 offset
+= qed_offset_into_cluster(s
, acb
->cur_pos
);
1264 trace_qed_aio_read_data(s
, acb
, ret
, offset
, len
);
1266 qemu_iovec_concat(&acb
->cur_qiov
, acb
->qiov
, acb
->qiov_offset
, len
);
1268 /* Handle zero cluster and backing file reads, otherwise read
1269 * data cluster directly.
1271 if (ret
== QED_CLUSTER_ZERO
) {
1272 qemu_iovec_memset(&acb
->cur_qiov
, 0, 0, acb
->cur_qiov
.size
);
1274 } else if (ret
!= QED_CLUSTER_FOUND
) {
1275 r
= qed_read_backing_file(s
, acb
->cur_pos
, &acb
->cur_qiov
,
1276 &acb
->backing_qiov
);
1278 BLKDBG_EVENT(bs
->file
, BLKDBG_READ_AIO
);
1279 r
= bdrv_co_preadv(bs
->file
, offset
, acb
->cur_qiov
.size
,
1283 qemu_co_mutex_lock(&s
->table_lock
);
1288 * Begin next I/O or complete the request
1290 static int coroutine_fn
qed_aio_next_io(QEDAIOCB
*acb
)
1292 BDRVQEDState
*s
= acb_to_s(acb
);
1297 qemu_co_mutex_lock(&s
->table_lock
);
1299 trace_qed_aio_next_io(s
, acb
, 0, acb
->cur_pos
+ acb
->cur_qiov
.size
);
1301 if (acb
->backing_qiov
) {
1302 qemu_iovec_destroy(acb
->backing_qiov
);
1303 g_free(acb
->backing_qiov
);
1304 acb
->backing_qiov
= NULL
;
1307 acb
->qiov_offset
+= acb
->cur_qiov
.size
;
1308 acb
->cur_pos
+= acb
->cur_qiov
.size
;
1309 qemu_iovec_reset(&acb
->cur_qiov
);
1311 /* Complete request */
1312 if (acb
->cur_pos
>= acb
->end_pos
) {
1317 /* Find next cluster and start I/O */
1318 len
= acb
->end_pos
- acb
->cur_pos
;
1319 ret
= qed_find_cluster(s
, &acb
->request
, acb
->cur_pos
, &len
, &offset
);
1324 if (acb
->flags
& QED_AIOCB_WRITE
) {
1325 ret
= qed_aio_write_data(acb
, ret
, offset
, len
);
1327 ret
= qed_aio_read_data(acb
, ret
, offset
, len
);
1330 if (ret
< 0 && ret
!= -EAGAIN
) {
1335 trace_qed_aio_complete(s
, acb
, ret
);
1336 qed_aio_complete(acb
);
1337 qemu_co_mutex_unlock(&s
->table_lock
);
1341 static int coroutine_fn
qed_co_request(BlockDriverState
*bs
, int64_t sector_num
,
1342 QEMUIOVector
*qiov
, int nb_sectors
,
1347 .cur_pos
= (uint64_t) sector_num
* BDRV_SECTOR_SIZE
,
1348 .end_pos
= (sector_num
+ nb_sectors
) * BDRV_SECTOR_SIZE
,
1352 qemu_iovec_init(&acb
.cur_qiov
, qiov
->niov
);
1354 trace_qed_aio_setup(bs
->opaque
, &acb
, sector_num
, nb_sectors
, NULL
, flags
);
1357 return qed_aio_next_io(&acb
);
1360 static int coroutine_fn
bdrv_qed_co_readv(BlockDriverState
*bs
,
1361 int64_t sector_num
, int nb_sectors
,
1364 return qed_co_request(bs
, sector_num
, qiov
, nb_sectors
, 0);
1367 static int coroutine_fn
bdrv_qed_co_writev(BlockDriverState
*bs
,
1368 int64_t sector_num
, int nb_sectors
,
1371 return qed_co_request(bs
, sector_num
, qiov
, nb_sectors
, QED_AIOCB_WRITE
);
1374 static int coroutine_fn
bdrv_qed_co_pwrite_zeroes(BlockDriverState
*bs
,
1377 BdrvRequestFlags flags
)
1379 BDRVQEDState
*s
= bs
->opaque
;
1383 /* Fall back if the request is not aligned */
1384 if (qed_offset_into_cluster(s
, offset
) ||
1385 qed_offset_into_cluster(s
, bytes
)) {
1389 /* Zero writes start without an I/O buffer. If a buffer becomes necessary
1390 * then it will be allocated during request processing.
1392 iov
.iov_base
= NULL
;
1393 iov
.iov_len
= bytes
;
1395 qemu_iovec_init_external(&qiov
, &iov
, 1);
1396 return qed_co_request(bs
, offset
>> BDRV_SECTOR_BITS
, &qiov
,
1397 bytes
>> BDRV_SECTOR_BITS
,
1398 QED_AIOCB_WRITE
| QED_AIOCB_ZERO
);
1401 static int bdrv_qed_truncate(BlockDriverState
*bs
, int64_t offset
,
1402 PreallocMode prealloc
, Error
**errp
)
1404 BDRVQEDState
*s
= bs
->opaque
;
1405 uint64_t old_image_size
;
1408 if (prealloc
!= PREALLOC_MODE_OFF
) {
1409 error_setg(errp
, "Unsupported preallocation mode '%s'",
1410 PreallocMode_str(prealloc
));
1414 if (!qed_is_image_size_valid(offset
, s
->header
.cluster_size
,
1415 s
->header
.table_size
)) {
1416 error_setg(errp
, "Invalid image size specified");
1420 if ((uint64_t)offset
< s
->header
.image_size
) {
1421 error_setg(errp
, "Shrinking images is currently not supported");
1425 old_image_size
= s
->header
.image_size
;
1426 s
->header
.image_size
= offset
;
1427 ret
= qed_write_header_sync(s
);
1429 s
->header
.image_size
= old_image_size
;
1430 error_setg_errno(errp
, -ret
, "Failed to update the image size");
1435 static int64_t bdrv_qed_getlength(BlockDriverState
*bs
)
1437 BDRVQEDState
*s
= bs
->opaque
;
1438 return s
->header
.image_size
;
1441 static int bdrv_qed_get_info(BlockDriverState
*bs
, BlockDriverInfo
*bdi
)
1443 BDRVQEDState
*s
= bs
->opaque
;
1445 memset(bdi
, 0, sizeof(*bdi
));
1446 bdi
->cluster_size
= s
->header
.cluster_size
;
1447 bdi
->is_dirty
= s
->header
.features
& QED_F_NEED_CHECK
;
1448 bdi
->unallocated_blocks_are_zero
= true;
1452 static int bdrv_qed_change_backing_file(BlockDriverState
*bs
,
1453 const char *backing_file
,
1454 const char *backing_fmt
)
1456 BDRVQEDState
*s
= bs
->opaque
;
1457 QEDHeader new_header
, le_header
;
1459 size_t buffer_len
, backing_file_len
;
1462 /* Refuse to set backing filename if unknown compat feature bits are
1463 * active. If the image uses an unknown compat feature then we may not
1464 * know the layout of data following the header structure and cannot safely
1467 if (backing_file
&& (s
->header
.compat_features
&
1468 ~QED_COMPAT_FEATURE_MASK
)) {
1472 memcpy(&new_header
, &s
->header
, sizeof(new_header
));
1474 new_header
.features
&= ~(QED_F_BACKING_FILE
|
1475 QED_F_BACKING_FORMAT_NO_PROBE
);
1477 /* Adjust feature flags */
1479 new_header
.features
|= QED_F_BACKING_FILE
;
1481 if (qed_fmt_is_raw(backing_fmt
)) {
1482 new_header
.features
|= QED_F_BACKING_FORMAT_NO_PROBE
;
1486 /* Calculate new header size */
1487 backing_file_len
= 0;
1490 backing_file_len
= strlen(backing_file
);
1493 buffer_len
= sizeof(new_header
);
1494 new_header
.backing_filename_offset
= buffer_len
;
1495 new_header
.backing_filename_size
= backing_file_len
;
1496 buffer_len
+= backing_file_len
;
1498 /* Make sure we can rewrite header without failing */
1499 if (buffer_len
> new_header
.header_size
* new_header
.cluster_size
) {
1503 /* Prepare new header */
1504 buffer
= g_malloc(buffer_len
);
1506 qed_header_cpu_to_le(&new_header
, &le_header
);
1507 memcpy(buffer
, &le_header
, sizeof(le_header
));
1508 buffer_len
= sizeof(le_header
);
1511 memcpy(buffer
+ buffer_len
, backing_file
, backing_file_len
);
1512 buffer_len
+= backing_file_len
;
1515 /* Write new header */
1516 ret
= bdrv_pwrite_sync(bs
->file
, 0, buffer
, buffer_len
);
1519 memcpy(&s
->header
, &new_header
, sizeof(new_header
));
1524 static void coroutine_fn
bdrv_qed_co_invalidate_cache(BlockDriverState
*bs
,
1527 BDRVQEDState
*s
= bs
->opaque
;
1528 Error
*local_err
= NULL
;
1533 bdrv_qed_init_state(bs
);
1534 qemu_co_mutex_lock(&s
->table_lock
);
1535 ret
= bdrv_qed_do_open(bs
, NULL
, bs
->open_flags
, &local_err
);
1536 qemu_co_mutex_unlock(&s
->table_lock
);
1538 error_propagate(errp
, local_err
);
1539 error_prepend(errp
, "Could not reopen qed layer: ");
1541 } else if (ret
< 0) {
1542 error_setg_errno(errp
, -ret
, "Could not reopen qed layer");
1547 static int bdrv_qed_co_check(BlockDriverState
*bs
, BdrvCheckResult
*result
,
1550 BDRVQEDState
*s
= bs
->opaque
;
1553 qemu_co_mutex_lock(&s
->table_lock
);
1554 ret
= qed_check(s
, result
, !!fix
);
1555 qemu_co_mutex_unlock(&s
->table_lock
);
1560 static QemuOptsList qed_create_opts
= {
1561 .name
= "qed-create-opts",
1562 .head
= QTAILQ_HEAD_INITIALIZER(qed_create_opts
.head
),
1565 .name
= BLOCK_OPT_SIZE
,
1566 .type
= QEMU_OPT_SIZE
,
1567 .help
= "Virtual disk size"
1570 .name
= BLOCK_OPT_BACKING_FILE
,
1571 .type
= QEMU_OPT_STRING
,
1572 .help
= "File name of a base image"
1575 .name
= BLOCK_OPT_BACKING_FMT
,
1576 .type
= QEMU_OPT_STRING
,
1577 .help
= "Image format of the base image"
1580 .name
= BLOCK_OPT_CLUSTER_SIZE
,
1581 .type
= QEMU_OPT_SIZE
,
1582 .help
= "Cluster size (in bytes)",
1583 .def_value_str
= stringify(QED_DEFAULT_CLUSTER_SIZE
)
1586 .name
= BLOCK_OPT_TABLE_SIZE
,
1587 .type
= QEMU_OPT_SIZE
,
1588 .help
= "L1/L2 table size (in clusters)"
1590 { /* end of list */ }
1594 static BlockDriver bdrv_qed
= {
1595 .format_name
= "qed",
1596 .instance_size
= sizeof(BDRVQEDState
),
1597 .create_opts
= &qed_create_opts
,
1598 .supports_backing
= true,
1600 .bdrv_probe
= bdrv_qed_probe
,
1601 .bdrv_open
= bdrv_qed_open
,
1602 .bdrv_close
= bdrv_qed_close
,
1603 .bdrv_reopen_prepare
= bdrv_qed_reopen_prepare
,
1604 .bdrv_child_perm
= bdrv_format_default_perms
,
1605 .bdrv_co_create_opts
= bdrv_qed_co_create_opts
,
1606 .bdrv_has_zero_init
= bdrv_has_zero_init_1
,
1607 .bdrv_co_block_status
= bdrv_qed_co_block_status
,
1608 .bdrv_co_readv
= bdrv_qed_co_readv
,
1609 .bdrv_co_writev
= bdrv_qed_co_writev
,
1610 .bdrv_co_pwrite_zeroes
= bdrv_qed_co_pwrite_zeroes
,
1611 .bdrv_truncate
= bdrv_qed_truncate
,
1612 .bdrv_getlength
= bdrv_qed_getlength
,
1613 .bdrv_get_info
= bdrv_qed_get_info
,
1614 .bdrv_refresh_limits
= bdrv_qed_refresh_limits
,
1615 .bdrv_change_backing_file
= bdrv_qed_change_backing_file
,
1616 .bdrv_co_invalidate_cache
= bdrv_qed_co_invalidate_cache
,
1617 .bdrv_co_check
= bdrv_qed_co_check
,
1618 .bdrv_detach_aio_context
= bdrv_qed_detach_aio_context
,
1619 .bdrv_attach_aio_context
= bdrv_qed_attach_aio_context
,
1620 .bdrv_co_drain_begin
= bdrv_qed_co_drain_begin
,
1623 static void bdrv_qed_init(void)
1625 bdrv_register(&bdrv_qed
);
1628 block_init(bdrv_qed_init
);