Lines Matching refs:bs

78 qcow2_co_preadv_compressed(BlockDriverState *bs,
103 BlockDriverState *bs = opaque; in qcow2_crypto_hdr_read_func() local
104 BDRVQcow2State *s = bs->opaque; in qcow2_crypto_hdr_read_func()
112 ret = bdrv_pread(bs->file, s->crypto_header.offset + offset, buflen, buf, in qcow2_crypto_hdr_read_func()
126 BlockDriverState *bs = opaque; in qcow2_crypto_hdr_init_func() local
127 BDRVQcow2State *s = bs->opaque; in qcow2_crypto_hdr_init_func()
131 ret = qcow2_alloc_clusters(bs, headerlen); in qcow2_crypto_hdr_init_func()
148 assert(qcow2_pre_write_overlap_check(bs, 0, ret, clusterlen, false) == 0); in qcow2_crypto_hdr_init_func()
149 ret = bdrv_co_pwrite_zeroes(bs->file, ret, clusterlen, 0); in qcow2_crypto_hdr_init_func()
165 BlockDriverState *bs = opaque; in qcow2_crypto_hdr_write_func() local
166 BDRVQcow2State *s = bs->opaque; in qcow2_crypto_hdr_write_func()
174 ret = bdrv_pwrite(bs->file, s->crypto_header.offset + offset, buflen, buf, in qcow2_crypto_hdr_write_func()
205 qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, in qcow2_read_extensions() argument
209 BDRVQcow2State *s = bs->opaque; in qcow2_read_extensions()
233 ret = bdrv_co_pread(bs->file, offset, sizeof(ext), &ext, 0); in qcow2_read_extensions()
255 if (ext.len >= sizeof(bs->backing_format)) { in qcow2_read_extensions()
258 sizeof(bs->backing_format)); in qcow2_read_extensions()
261 ret = bdrv_co_pread(bs->file, offset, ext.len, bs->backing_format, 0); in qcow2_read_extensions()
267 bs->backing_format[ext.len] = '\0'; in qcow2_read_extensions()
268 s->image_backing_format = g_strdup(bs->backing_format); in qcow2_read_extensions()
270 printf("Qcow2: Got format extension %s\n", bs->backing_format); in qcow2_read_extensions()
277 ret = bdrv_co_pread(bs->file, offset, ext.len, feature_table, 0); in qcow2_read_extensions()
303 ret = bdrv_co_pread(bs->file, offset, ext.len, &s->crypto_header, 0); in qcow2_read_extensions()
324 bs, cflags, errp); in qcow2_read_extensions()
359 ret = bdrv_co_pread(bs->file, offset, ext.len, &bitmaps_ext, 0); in qcow2_read_extensions()
423 ret = bdrv_co_pread(bs->file, offset, ext.len, s->image_data_file, 0); in qcow2_read_extensions()
447 ret = bdrv_co_pread(bs->file, offset, uext->len, uext->data, 0); in qcow2_read_extensions()
463 static void cleanup_unknown_header_ext(BlockDriverState *bs) in cleanup_unknown_header_ext() argument
465 BDRVQcow2State *s = bs->opaque; in cleanup_unknown_header_ext()
510 int qcow2_mark_dirty(BlockDriverState *bs) in qcow2_mark_dirty() argument
512 BDRVQcow2State *s = bs->opaque; in qcow2_mark_dirty()
523 ret = bdrv_pwrite_sync(bs->file, in qcow2_mark_dirty()
540 static int GRAPH_RDLOCK qcow2_mark_clean(BlockDriverState *bs) in qcow2_mark_clean() argument
542 BDRVQcow2State *s = bs->opaque; in qcow2_mark_clean()
549 ret = qcow2_flush_caches(bs); in qcow2_mark_clean()
554 return qcow2_update_header(bs); in qcow2_mark_clean()
562 int qcow2_mark_corrupt(BlockDriverState *bs) in qcow2_mark_corrupt() argument
564 BDRVQcow2State *s = bs->opaque; in qcow2_mark_corrupt()
567 return qcow2_update_header(bs); in qcow2_mark_corrupt()
575 qcow2_mark_consistent(BlockDriverState *bs) in qcow2_mark_consistent() argument
577 BDRVQcow2State *s = bs->opaque; in qcow2_mark_consistent()
580 int ret = qcow2_flush_caches(bs); in qcow2_mark_consistent()
586 return qcow2_update_header(bs); in qcow2_mark_consistent()
608 qcow2_co_check_locked(BlockDriverState *bs, BdrvCheckResult *result, in qcow2_co_check_locked() argument
617 ret = qcow2_check_read_snapshot_table(bs, &snapshot_res, fix); in qcow2_co_check_locked()
623 ret = qcow2_check_refcounts(bs, &refcount_res, fix); in qcow2_co_check_locked()
630 ret = qcow2_check_fix_snapshot_table(bs, &snapshot_res, fix); in qcow2_co_check_locked()
637 ret = qcow2_mark_clean(bs); in qcow2_co_check_locked()
641 return qcow2_mark_consistent(bs); in qcow2_co_check_locked()
647 qcow2_co_check(BlockDriverState *bs, BdrvCheckResult *result, in qcow2_co_check() argument
650 BDRVQcow2State *s = bs->opaque; in qcow2_co_check()
654 ret = qcow2_co_check_locked(bs, result, fix); in qcow2_co_check()
659 int qcow2_validate_table(BlockDriverState *bs, uint64_t offset, in qcow2_validate_table() argument
664 BDRVQcow2State *s = bs->opaque; in qcow2_validate_table()
840 BlockDriverState *bs = opaque; in cache_clean_timer_cb() local
841 BDRVQcow2State *s = bs->opaque; in cache_clean_timer_cb()
848 static void cache_clean_timer_init(BlockDriverState *bs, AioContext *context) in cache_clean_timer_init() argument
850 BDRVQcow2State *s = bs->opaque; in cache_clean_timer_init()
855 cache_clean_timer_cb, bs); in cache_clean_timer_init()
861 static void cache_clean_timer_del(BlockDriverState *bs) in cache_clean_timer_del() argument
863 BDRVQcow2State *s = bs->opaque; in cache_clean_timer_del()
870 static void qcow2_detach_aio_context(BlockDriverState *bs) in qcow2_detach_aio_context() argument
872 cache_clean_timer_del(bs); in qcow2_detach_aio_context()
875 static void qcow2_attach_aio_context(BlockDriverState *bs, in qcow2_attach_aio_context() argument
878 cache_clean_timer_init(bs, new_context); in qcow2_attach_aio_context()
881 static bool read_cache_sizes(BlockDriverState *bs, QemuOpts *opts, in read_cache_sizes() argument
886 BDRVQcow2State *s = bs->opaque; in read_cache_sizes()
891 uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE; in read_cache_sizes()
986 qcow2_update_options_prepare(BlockDriverState *bs, Qcow2ReopenState *r, in qcow2_update_options_prepare() argument
989 BDRVQcow2State *s = bs->opaque; in qcow2_update_options_prepare()
1009 if (!read_cache_sizes(bs, opts, &l2_cache_size, &l2_cache_entry_size, in qcow2_update_options_prepare()
1037 ret = qcow2_cache_flush(bs, s->l2_table_cache); in qcow2_update_options_prepare()
1045 ret = qcow2_cache_flush(bs, s->refcount_block_cache); in qcow2_update_options_prepare()
1054 r->l2_table_cache = qcow2_cache_create(bs, l2_cache_size, in qcow2_update_options_prepare()
1056 r->refcount_block_cache = qcow2_cache_create(bs, refcount_cache_size, in qcow2_update_options_prepare()
1093 ret = qcow2_mark_clean(bs); in qcow2_update_options_prepare()
1217 static void qcow2_update_options_commit(BlockDriverState *bs, in qcow2_update_options_commit() argument
1220 BDRVQcow2State *s = bs->opaque; in qcow2_update_options_commit()
1243 cache_clean_timer_del(bs); in qcow2_update_options_commit()
1245 cache_clean_timer_init(bs, bdrv_get_aio_context(bs)); in qcow2_update_options_commit()
1252 static void qcow2_update_options_abort(BlockDriverState *bs, in qcow2_update_options_abort() argument
1265 qcow2_update_options(BlockDriverState *bs, QDict *options, int flags, in qcow2_update_options() argument
1271 ret = qcow2_update_options_prepare(bs, &r, options, flags, errp); in qcow2_update_options()
1273 qcow2_update_options_commit(bs, &r); in qcow2_update_options()
1275 qcow2_update_options_abort(bs, &r); in qcow2_update_options()
1319 qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, in qcow2_do_open() argument
1323 BDRVQcow2State *s = bs->opaque; in qcow2_do_open()
1331 ret = bdrv_co_pread(bs->file, 0, sizeof(header), &header, 0); in qcow2_do_open()
1407 ret = bdrv_co_pread(bs->file, sizeof(header), in qcow2_do_open()
1453 qcow2_read_extensions(bs, header.header_length, ext_end, in qcow2_do_open()
1522 bs->encrypted = true; in qcow2_do_open()
1530 bs->total_sectors = header.size / BDRV_SECTOR_SIZE; in qcow2_do_open()
1545 ret = qcow2_validate_table(bs, s->refcount_table_offset, in qcow2_do_open()
1560 ret = qcow2_validate_table(bs, header.snapshots_offset, in qcow2_do_open()
1572 ret = qcow2_validate_table(bs, header.l1_table_offset, in qcow2_do_open()
1598 s->l1_table = qemu_try_blockalign(bs->file->bs, s->l1_size * L1E_SIZE); in qcow2_do_open()
1604 ret = bdrv_co_pread(bs->file, s->l1_table_offset, s->l1_size * L1E_SIZE, in qcow2_do_open()
1616 ret = qcow2_update_options(bs, options, flags, errp); in qcow2_do_open()
1623 ret = qcow2_refcount_init(bs); in qcow2_do_open()
1633 if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL, in qcow2_do_open()
1650 s->data_file = bs->file; in qcow2_do_open()
1657 s->data_file = bdrv_co_open_child(NULL, options, "data-file", bs, in qcow2_do_open()
1670 "data-file", bs, in qcow2_do_open()
1686 bs->file->role &= ~BDRV_CHILD_DATA; in qcow2_do_open()
1689 bdrv_child_refresh_perms(bs, bs->file, &error_abort); in qcow2_do_open()
1698 s->data_file = bs->file; in qcow2_do_open()
1700 if (data_file_is_raw(bs)) { in qcow2_do_open()
1736 len >= sizeof(bs->backing_file)) { in qcow2_do_open()
1743 ret = bdrv_co_pread(bs->file, header.backing_file_offset, len, in qcow2_do_open()
1756 if (!g_str_equal(s->image_backing_file, bs->backing_file)) { in qcow2_do_open()
1757 pstrcpy(bs->backing_file, sizeof(bs->backing_file), in qcow2_do_open()
1759 pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), in qcow2_do_open()
1773 ret = qcow2_read_snapshots(bs, errp); in qcow2_do_open()
1781 update_header = update_header && bdrv_is_writable(bs); in qcow2_do_open()
1844 if (!(bdrv_get_flags(bs) & BDRV_O_INACTIVE)) { in qcow2_do_open()
1847 if (!qcow2_load_dirty_bitmaps(bs, &header_updated, errp)) { in qcow2_do_open()
1856 ret = qcow2_update_header(bs); in qcow2_do_open()
1863 bs->supported_zero_flags = header.version >= 3 ? in qcow2_do_open()
1865 bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE; in qcow2_do_open()
1868 if (!(flags & BDRV_O_CHECK) && bdrv_is_writable(bs) && in qcow2_do_open()
1872 ret = qcow2_co_check_locked(bs, &result, in qcow2_do_open()
1886 qcow2_check_refcounts(bs, &result, 0); in qcow2_do_open()
1896 if (open_data_file && has_data_file(bs)) { in qcow2_do_open()
1898 bdrv_co_unref_child(bs, s->data_file); in qcow2_do_open()
1903 cleanup_unknown_header_ext(bs); in qcow2_do_open()
1904 qcow2_free_snapshots(bs); in qcow2_do_open()
1905 qcow2_refcount_close(bs); in qcow2_do_open()
1909 cache_clean_timer_del(bs); in qcow2_do_open()
1922 BlockDriverState *bs; member
1932 BDRVQcow2State *s = qoc->bs->opaque; in qcow2_open_entry()
1937 qoc->ret = qcow2_do_open(qoc->bs, qoc->options, qoc->flags, true, in qcow2_open_entry()
1944 static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, in qcow2_open() argument
1947 BDRVQcow2State *s = bs->opaque; in qcow2_open()
1949 .bs = bs, in qcow2_open()
1957 ret = bdrv_open_file_child(NULL, options, "file", bs, errp); in qcow2_open()
1968 aio_co_enter(bdrv_get_aio_context(bs), in qcow2_open()
1975 static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp) in qcow2_refresh_limits() argument
1977 BDRVQcow2State *s = bs->opaque; in qcow2_refresh_limits()
1979 if (bs->encrypted) { in qcow2_refresh_limits()
1981 bs->bl.request_alignment = qcrypto_block_get_sector_size(s->crypto); in qcow2_refresh_limits()
1983 bs->bl.pwrite_zeroes_alignment = s->subcluster_size; in qcow2_refresh_limits()
1984 bs->bl.pdiscard_alignment = s->cluster_size; in qcow2_refresh_limits()
1991 BDRVQcow2State *s = state->bs->opaque; in qcow2_reopen_prepare()
2001 ret = qcow2_update_options_prepare(state->bs, r, state->options, in qcow2_reopen_prepare()
2009 ret = qcow2_reopen_bitmaps_ro(state->bs, errp); in qcow2_reopen_prepare()
2014 ret = bdrv_flush(state->bs); in qcow2_reopen_prepare()
2019 ret = qcow2_mark_clean(state->bs); in qcow2_reopen_prepare()
2030 if (!has_data_file(state->bs)) { in qcow2_reopen_prepare()
2031 assert(s->data_file == state->bs->file); in qcow2_reopen_prepare()
2038 qcow2_update_options_abort(state->bs, r); in qcow2_reopen_prepare()
2045 BDRVQcow2State *s = state->bs->opaque; in qcow2_reopen_commit()
2049 qcow2_update_options_commit(state->bs, state->opaque); in qcow2_reopen_commit()
2055 s->data_file = state->bs->file; in qcow2_reopen_commit()
2067 if (qcow2_reopen_bitmaps_rw(state->bs, &local_err) < 0) { in qcow2_reopen_commit_post()
2075 bdrv_get_node_name(state->bs)); in qcow2_reopen_commit_post()
2082 BDRVQcow2State *s = state->bs->opaque; in qcow2_reopen_abort()
2091 s->data_file = state->bs->file; in qcow2_reopen_abort()
2093 qcow2_update_options_abort(state->bs, state->opaque); in qcow2_reopen_abort()
2144 qcow2_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, in qcow2_co_block_status() argument
2148 BDRVQcow2State *s = bs->opaque; in qcow2_co_block_status()
2157 ret = qcow2_detect_metadata_preallocation(bs); in qcow2_co_block_status()
2163 ret = qcow2_get_host_offset(bs, offset, &bytes, &host_offset, &type); in qcow2_co_block_status()
2175 *file = s->data_file->bs; in qcow2_co_block_status()
2197 qcow2_handle_l2meta(BlockDriverState *bs, QCowL2Meta **pl2meta, bool link_l2) in qcow2_handle_l2meta() argument
2206 ret = qcow2_alloc_cluster_link_l2(bs, l2meta); in qcow2_handle_l2meta()
2211 qcow2_alloc_cluster_abort(bs, l2meta); in qcow2_handle_l2meta()
2229 qcow2_co_preadv_encrypted(BlockDriverState *bs, in qcow2_co_preadv_encrypted() argument
2237 BDRVQcow2State *s = bs->opaque; in qcow2_co_preadv_encrypted()
2240 assert(bs->encrypted && s->crypto); in qcow2_co_preadv_encrypted()
2251 buf = qemu_try_blockalign(s->data_file->bs, bytes); in qcow2_co_preadv_encrypted()
2256 BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO); in qcow2_co_preadv_encrypted()
2262 if (qcow2_co_decrypt(bs, host_offset, offset, buf, bytes) < 0) in qcow2_co_preadv_encrypted()
2278 BlockDriverState *bs; member
2289 static coroutine_fn int qcow2_add_task(BlockDriverState *bs, in qcow2_add_task() argument
2305 .bs = bs, in qcow2_add_task()
2315 trace_qcow2_add_task(qemu_coroutine_self(), bs, pool, in qcow2_add_task()
2330 qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type, in qcow2_co_preadv_task() argument
2334 BDRVQcow2State *s = bs->opaque; in qcow2_co_preadv_task()
2344 assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part */ in qcow2_co_preadv_task()
2346 BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); in qcow2_co_preadv_task()
2347 return bdrv_co_preadv_part(bs->backing, offset, bytes, in qcow2_co_preadv_task()
2351 return qcow2_co_preadv_compressed(bs, host_offset, in qcow2_co_preadv_task()
2355 if (bs->encrypted) { in qcow2_co_preadv_task()
2356 return qcow2_co_preadv_encrypted(bs, host_offset, in qcow2_co_preadv_task()
2360 BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO); in qcow2_co_preadv_task()
2381 return qcow2_co_preadv_task(t->bs, t->subcluster_type, in qcow2_co_preadv_task_entry()
2387 qcow2_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, in qcow2_co_preadv_part() argument
2391 BDRVQcow2State *s = bs->opaque; in qcow2_co_preadv_part()
2407 ret = qcow2_get_host_offset(bs, offset, &cur_bytes, in qcow2_co_preadv_part()
2416 (type == QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && !bs->backing) || in qcow2_co_preadv_part()
2417 (type == QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && !bs->backing)) in qcow2_co_preadv_part()
2424 ret = qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, type, in qcow2_co_preadv_part()
2510 is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) in is_zero_cow() argument
2518 int ret = bdrv_co_is_zero_fast(bs, m->offset + m->cow_start.offset, in is_zero_cow()
2524 return bdrv_co_is_zero_fast(bs, m->offset + m->cow_end.offset, in is_zero_cow()
2529 handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) in handle_alloc_space() argument
2531 BDRVQcow2State *s = bs->opaque; in handle_alloc_space()
2534 if (!(s->data_file->bs->supported_zero_flags & BDRV_REQ_NO_FALLBACK)) { in handle_alloc_space()
2538 if (bs->encrypted) { in handle_alloc_space()
2552 ret = is_zero_cow(bs, m); in handle_alloc_space()
2564 ret = qcow2_pre_write_overlap_check(bs, 0, start_offset, nb_bytes, in handle_alloc_space()
2570 BLKDBG_CO_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE); in handle_alloc_space()
2593 int qcow2_co_pwritev_task(BlockDriverState *bs, uint64_t host_offset, in qcow2_co_pwritev_task() argument
2598 BDRVQcow2State *s = bs->opaque; in qcow2_co_pwritev_task()
2602 if (bs->encrypted) { in qcow2_co_pwritev_task()
2605 crypt_buf = qemu_try_blockalign(bs->file->bs, bytes); in qcow2_co_pwritev_task()
2612 if (qcow2_co_encrypt(bs, host_offset, offset, crypt_buf, bytes) < 0) { in qcow2_co_pwritev_task()
2623 ret = handle_alloc_space(bs, l2meta); in qcow2_co_pwritev_task()
2635 BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO); in qcow2_co_pwritev_task()
2646 ret = qcow2_handle_l2meta(bs, &l2meta, true); in qcow2_co_pwritev_task()
2653 qcow2_handle_l2meta(bs, &l2meta, false); in qcow2_co_pwritev_task()
2671 return qcow2_co_pwritev_task(t->bs, t->host_offset, in qcow2_co_pwritev_task_entry()
2677 qcow2_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t bytes, in qcow2_co_pwritev_part() argument
2681 BDRVQcow2State *s = bs->opaque; in qcow2_co_pwritev_part()
2698 if (bs->encrypted) { in qcow2_co_pwritev_part()
2706 ret = qcow2_alloc_host_offset(bs, offset, &cur_bytes, in qcow2_co_pwritev_part()
2712 ret = qcow2_pre_write_overlap_check(bs, 0, host_offset, in qcow2_co_pwritev_part()
2723 ret = qcow2_add_task(bs, aio, qcow2_co_pwritev_task_entry, 0, in qcow2_co_pwritev_part()
2741 qcow2_handle_l2meta(bs, &l2meta, false); in qcow2_co_pwritev_part()
2759 static int GRAPH_RDLOCK qcow2_inactivate(BlockDriverState *bs) in qcow2_inactivate() argument
2761 BDRVQcow2State *s = bs->opaque; in qcow2_inactivate()
2765 qcow2_store_persistent_dirty_bitmaps(bs, true, &local_err); in qcow2_inactivate()
2770 bdrv_get_device_or_node_name(bs)); in qcow2_inactivate()
2773 ret = qcow2_cache_flush(bs, s->l2_table_cache); in qcow2_inactivate()
2780 ret = qcow2_cache_flush(bs, s->refcount_block_cache); in qcow2_inactivate()
2788 qcow2_mark_clean(bs); in qcow2_inactivate()
2795 qcow2_do_close(BlockDriverState *bs, bool close_data_file) in qcow2_do_close() argument
2797 BDRVQcow2State *s = bs->opaque; in qcow2_do_close()
2803 qcow2_inactivate(bs); in qcow2_do_close()
2806 cache_clean_timer_del(bs); in qcow2_do_close()
2815 cleanup_unknown_header_ext(bs); in qcow2_do_close()
2821 if (close_data_file && has_data_file(bs)) { in qcow2_do_close()
2825 bdrv_unref_child(bs, s->data_file); in qcow2_do_close()
2831 qcow2_refcount_close(bs); in qcow2_do_close()
2832 qcow2_free_snapshots(bs); in qcow2_do_close()
2835 static void GRAPH_UNLOCKED qcow2_close(BlockDriverState *bs) in qcow2_close() argument
2840 qcow2_do_close(bs, true); in qcow2_close()
2844 qcow2_co_invalidate_cache(BlockDriverState *bs, Error **errp) in qcow2_co_invalidate_cache() argument
2847 BDRVQcow2State *s = bs->opaque; in qcow2_co_invalidate_cache()
2869 qcow2_do_close(bs, false); in qcow2_co_invalidate_cache()
2875 options = qdict_clone_shallow(bs->options); in qcow2_co_invalidate_cache()
2879 ret = qcow2_do_open(bs, options, flags, false, errp); in qcow2_co_invalidate_cache()
2884 bs->drv = NULL; in qcow2_co_invalidate_cache()
2921 int qcow2_update_header(BlockDriverState *bs) in qcow2_update_header() argument
2923 BDRVQcow2State *s = bs->opaque; in qcow2_update_header()
2933 buf = qemu_blockalign(bs, buflen); in qcow2_update_header()
2944 total_size = bs->total_sectors * BDRV_SECTOR_SIZE; in qcow2_update_header()
3021 if (has_data_file(bs) && s->image_data_file) { in qcow2_update_header()
3166 ret = bdrv_pwrite(bs->file, 0, s->cluster_size, header, 0); in qcow2_update_header()
3178 qcow2_co_change_backing_file(BlockDriverState *bs, const char *backing_file, in qcow2_co_change_backing_file() argument
3181 BDRVQcow2State *s = bs->opaque; in qcow2_co_change_backing_file()
3185 if (backing_file && data_file_is_raw(bs)) { in qcow2_co_change_backing_file()
3193 pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), in qcow2_co_change_backing_file()
3195 pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: ""); in qcow2_co_change_backing_file()
3196 pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?: ""); in qcow2_co_change_backing_file()
3201 s->image_backing_file = backing_file ? g_strdup(bs->backing_file) : NULL; in qcow2_co_change_backing_file()
3202 s->image_backing_format = backing_fmt ? g_strdup(bs->backing_format) : NULL; in qcow2_co_change_backing_file()
3204 return qcow2_update_header(bs); in qcow2_co_change_backing_file()
3208 qcow2_set_up_encryption(BlockDriverState *bs, in qcow2_set_up_encryption() argument
3212 BDRVQcow2State *s = bs->opaque; in qcow2_set_up_encryption()
3233 bs, 0, errp); in qcow2_set_up_encryption()
3238 ret = qcow2_update_header(bs); in qcow2_set_up_encryption()
3258 preallocate_co(BlockDriverState *bs, uint64_t offset, uint64_t new_length, in preallocate_co() argument
3261 BDRVQcow2State *s = bs->opaque; in preallocate_co()
3274 ret = qcow2_alloc_host_offset(bs, offset, &cur_bytes, in preallocate_co()
3285 ret = qcow2_handle_l2meta(bs, &meta, true); in preallocate_co()
3302 file_length = bdrv_co_getlength(s->data_file->bs); in preallocate_co()
3323 qcow2_handle_l2meta(bs, &meta, false); in preallocate_co()
3517 BlockDriverState *bs = NULL; in qcow2_co_create() local
3530 bs = bdrv_co_open_blockdev_ref(qcow2_opts->file, errp); in qcow2_co_create()
3531 if (bs == NULL) { in qcow2_co_create()
3705 blk = blk_co_new_with_bs(bs, BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL, in qcow2_co_create()
3784 qdict_put_str(options, "file", bs->node_name); in qcow2_co_create()
3875 qdict_put_str(options, "file", bs->node_name); in qcow2_co_create()
3890 bdrv_co_unref(bs); in qcow2_co_create()
3902 BlockDriverState *bs = NULL; in qcow2_co_create_opts() local
3962 bs = bdrv_co_open(filename, NULL, NULL, in qcow2_co_create_opts()
3964 if (bs == NULL) { in qcow2_co_create_opts()
3991 qdict_put_str(qdict, "file", bs->node_name); in qcow2_co_create_opts()
4016 bdrv_co_delete_file_noerr(bs); in qcow2_co_create_opts()
4024 bdrv_co_unref(bs); in qcow2_co_create_opts()
4032 is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes) in is_zero() argument
4038 if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { in is_zero()
4039 bytes = bs->total_sectors * BDRV_SECTOR_SIZE - offset; in is_zero()
4053 res = bdrv_co_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); in is_zero()
4062 qcow2_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, in qcow2_co_pwrite_zeroes() argument
4066 BDRVQcow2State *s = bs->opaque; in qcow2_co_pwrite_zeroes()
4073 if (offset + bytes == bs->total_sectors * BDRV_SECTOR_SIZE) { in qcow2_co_pwrite_zeroes()
4085 if (!(is_zero(bs, offset - head, head) && in qcow2_co_pwrite_zeroes()
4086 is_zero(bs, offset + bytes, tail))) { in qcow2_co_pwrite_zeroes()
4095 ret = qcow2_get_host_offset(bs, offset, &nr, &off, &type); in qcow2_co_pwrite_zeroes()
4111 ret = qcow2_subcluster_zeroize(bs, offset, bytes, flags); in qcow2_co_pwrite_zeroes()
4118 qcow2_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) in qcow2_co_pdiscard() argument
4121 BDRVQcow2State *s = bs->opaque; in qcow2_co_pdiscard()
4125 if (s->qcow_version < 3 && bs->backing) { in qcow2_co_pdiscard()
4134 offset + bytes != bs->total_sectors * BDRV_SECTOR_SIZE) { in qcow2_co_pdiscard()
4140 ret = qcow2_cluster_discard(bs, offset, bytes, QCOW2_DISCARD_REQUEST, in qcow2_co_pdiscard()
4147 qcow2_co_copy_range_from(BlockDriverState *bs, in qcow2_co_copy_range_from() argument
4153 BDRVQcow2State *s = bs->opaque; in qcow2_co_copy_range_from()
4159 assert(!bs->encrypted); in qcow2_co_copy_range_from()
4169 ret = qcow2_get_host_offset(bs, src_offset, &cur_bytes, in qcow2_co_copy_range_from()
4178 if (bs->backing && bs->backing->bs) { in qcow2_co_copy_range_from()
4179 int64_t backing_length = bdrv_co_getlength(bs->backing->bs); in qcow2_co_copy_range_from()
4183 child = bs->backing; in qcow2_co_copy_range_from()
4230 qcow2_co_copy_range_to(BlockDriverState *bs, in qcow2_co_copy_range_to() argument
4236 BDRVQcow2State *s = bs->opaque; in qcow2_co_copy_range_to()
4242 assert(!bs->encrypted); in qcow2_co_copy_range_to()
4256 ret = qcow2_alloc_host_offset(bs, dst_offset, &cur_bytes, in qcow2_co_copy_range_to()
4262 ret = qcow2_pre_write_overlap_check(bs, 0, host_offset, cur_bytes, in qcow2_co_copy_range_to()
4276 ret = qcow2_handle_l2meta(bs, &l2meta, true); in qcow2_co_copy_range_to()
4288 qcow2_handle_l2meta(bs, &l2meta, false); in qcow2_co_copy_range_to()
4298 qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, in qcow2_co_truncate() argument
4302 BDRVQcow2State *s = bs->opaque; in qcow2_co_truncate()
4335 if (qcow2_truncate_bitmaps_check(bs, errp)) { in qcow2_co_truncate()
4340 old_length = bs->total_sectors * BDRV_SECTOR_SIZE; in qcow2_co_truncate()
4352 ret = qcow2_cluster_discard(bs, ROUND_UP(offset, s->cluster_size), in qcow2_co_truncate()
4361 ret = qcow2_shrink_l1_table(bs, new_l1_size); in qcow2_co_truncate()
4368 ret = qcow2_shrink_reftable(bs); in qcow2_co_truncate()
4375 old_file_size = bdrv_co_getlength(bs->file->bs); in qcow2_co_truncate()
4382 last_cluster = qcow2_get_last_cluster(bs, old_file_size); in qcow2_co_truncate()
4399 bdrv_co_truncate(bs->file, (last_cluster + 1) * s->cluster_size, in qcow2_co_truncate()
4407 ret = qcow2_grow_l1_table(bs, new_l1_size, true); in qcow2_co_truncate()
4413 if (data_file_is_raw(bs) && prealloc == PREALLOC_MODE_OFF) { in qcow2_co_truncate()
4428 if (has_data_file(bs)) { in qcow2_co_truncate()
4443 ret = preallocate_co(bs, old_length, offset, prealloc, errp); in qcow2_co_truncate()
4460 if (has_data_file(bs)) { in qcow2_co_truncate()
4461 ret = preallocate_co(bs, old_length, offset, prealloc, errp); in qcow2_co_truncate()
4468 old_file_size = bdrv_co_getlength(bs->file->bs); in qcow2_co_truncate()
4476 last_cluster = qcow2_get_last_cluster(bs, old_file_size); in qcow2_co_truncate()
4502 allocation_start = qcow2_refcount_area(bs, old_file_size, in qcow2_co_truncate()
4513 clusters_allocated = qcow2_alloc_clusters_at(bs, allocation_start, in qcow2_co_truncate()
4534 ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, in qcow2_co_truncate()
4545 ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, 0, in qcow2_co_truncate()
4550 qcow2_free_clusters(bs, allocation_start, in qcow2_co_truncate()
4582 ret = qcow2_alloc_cluster_link_l2(bs, &allocation); in qcow2_co_truncate()
4585 qcow2_free_clusters(bs, host_offset, in qcow2_co_truncate()
4611 ret = qcow2_subcluster_zeroize(bs, zero_start, offset - zero_start, in qcow2_co_truncate()
4622 uint8_t *buf = qemu_blockalign0(bs, len); in qcow2_co_truncate()
4627 ret = qcow2_co_pwritev_part(bs, old_length, len, &qiov, 0, 0); in qcow2_co_truncate()
4640 ret = qcow2_write_caches(bs); in qcow2_co_truncate()
4648 bs->total_sectors = offset / BDRV_SECTOR_SIZE; in qcow2_co_truncate()
4652 ret = bdrv_co_pwrite_sync(bs->file, offsetof(QCowHeader, size), in qcow2_co_truncate()
4662 options = qdict_clone_shallow(bs->options); in qcow2_co_truncate()
4663 ret = qcow2_update_options(bs, options, s->flags, errp); in qcow2_co_truncate()
4675 qcow2_co_pwritev_compressed_task(BlockDriverState *bs, in qcow2_co_pwritev_compressed_task() argument
4679 BDRVQcow2State *s = bs->opaque; in qcow2_co_pwritev_compressed_task()
4686 (offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS))); in qcow2_co_pwritev_compressed_task()
4688 buf = qemu_blockalign(bs, s->cluster_size); in qcow2_co_pwritev_compressed_task()
4697 out_len = qcow2_co_compress(bs, out_buf, s->cluster_size - 1, in qcow2_co_pwritev_compressed_task()
4701 ret = qcow2_co_pwritev_part(bs, offset, bytes, qiov, qiov_offset, 0); in qcow2_co_pwritev_compressed_task()
4712 ret = qcow2_alloc_compressed_cluster_offset(bs, offset, out_len, in qcow2_co_pwritev_compressed_task()
4719 ret = qcow2_pre_write_overlap_check(bs, 0, cluster_offset, out_len, true); in qcow2_co_pwritev_compressed_task()
4750 return qcow2_co_pwritev_compressed_task(t->bs, t->offset, t->bytes, t->qiov, in qcow2_co_pwritev_compressed_task_entry()
4759 qcow2_co_pwritev_compressed_part(BlockDriverState *bs, in qcow2_co_pwritev_compressed_part() argument
4763 BDRVQcow2State *s = bs->opaque; in qcow2_co_pwritev_compressed_part()
4767 if (has_data_file(bs)) { in qcow2_co_pwritev_compressed_part()
4776 int64_t len = bdrv_co_getlength(bs->file->bs); in qcow2_co_pwritev_compressed_part()
4780 return bdrv_co_truncate(bs->file, len, false, PREALLOC_MODE_OFF, 0, in qcow2_co_pwritev_compressed_part()
4789 (offset + bytes) != (bs->total_sectors << BDRV_SECTOR_BITS)) { in qcow2_co_pwritev_compressed_part()
4800 ret = qcow2_add_task(bs, aio, qcow2_co_pwritev_compressed_task_entry, in qcow2_co_pwritev_compressed_part()
4822 qcow2_co_preadv_compressed(BlockDriverState *bs, in qcow2_co_preadv_compressed() argument
4829 BDRVQcow2State *s = bs->opaque; in qcow2_co_preadv_compressed()
4835 qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize); in qcow2_co_preadv_compressed()
4842 out_buf = qemu_blockalign(bs, s->cluster_size); in qcow2_co_preadv_compressed()
4844 BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_COMPRESSED); in qcow2_co_preadv_compressed()
4845 ret = bdrv_co_pread(bs->file, coffset, csize, buf, 0); in qcow2_co_preadv_compressed()
4850 if (qcow2_co_decompress(bs, out_buf, s->cluster_size, buf, csize) < 0) { in qcow2_co_preadv_compressed()
4864 static int GRAPH_RDLOCK make_completely_empty(BlockDriverState *bs) in make_completely_empty() argument
4866 BDRVQcow2State *s = bs->opaque; in make_completely_empty()
4878 ret = qcow2_cache_empty(bs, s->l2_table_cache); in make_completely_empty()
4883 ret = qcow2_cache_empty(bs, s->refcount_block_cache); in make_completely_empty()
4889 ret = qcow2_mark_dirty(bs); in make_completely_empty()
4894 BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); in make_completely_empty()
4902 ret = bdrv_pwrite_zeroes(bs->file, s->l1_table_offset, in make_completely_empty()
4909 BLKDBG_EVENT(bs->file, BLKDBG_EMPTY_IMAGE_PREPARE); in make_completely_empty()
4916 ret = bdrv_pwrite_zeroes(bs->file, s->cluster_size, in make_completely_empty()
4926 BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); in make_completely_empty()
4927 BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_UPDATE); in make_completely_empty()
4935 ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_table_offset), in make_completely_empty()
4963 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC); in make_completely_empty()
4967 ret = bdrv_pwrite_sync(bs->file, s->cluster_size, sizeof(rt_entry), in make_completely_empty()
4976 offset = qcow2_alloc_clusters(bs, 3 * s->cluster_size + l1_size2); in make_completely_empty()
4987 ret = qcow2_mark_clean(bs); in make_completely_empty()
4992 ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size, false, in make_completely_empty()
5008 bs->drv = NULL; in make_completely_empty()
5015 static int GRAPH_RDLOCK qcow2_make_empty(BlockDriverState *bs) in qcow2_make_empty() argument
5017 BDRVQcow2State *s = bs->opaque; in qcow2_make_empty()
5027 !has_data_file(bs)) { in qcow2_make_empty()
5037 return make_completely_empty(bs); in qcow2_make_empty()
5042 end_offset = bs->total_sectors * BDRV_SECTOR_SIZE; in qcow2_make_empty()
5049 ret = qcow2_cluster_discard(bs, offset, MIN(step, end_offset - offset), in qcow2_make_empty()
5059 static coroutine_fn GRAPH_RDLOCK int qcow2_co_flush_to_os(BlockDriverState *bs) in qcow2_co_flush_to_os() argument
5061 BDRVQcow2State *s = bs->opaque; in qcow2_co_flush_to_os()
5065 ret = qcow2_write_caches(bs); in qcow2_co_flush_to_os()
5240 qcow2_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) in qcow2_co_get_info() argument
5242 BDRVQcow2State *s = bs->opaque; in qcow2_co_get_info()
5251 qcow2_get_specific_info(BlockDriverState *bs, Error **errp) in qcow2_get_specific_info() argument
5253 BDRVQcow2State *s = bs->opaque; in qcow2_get_specific_info()
5276 if (!qcow2_get_bitmap_info_list(bs, &bitmaps, errp)) { in qcow2_get_specific_info()
5295 .has_data_file_raw = has_data_file(bs), in qcow2_get_specific_info()
5296 .data_file_raw = data_file_is_raw(bs), in qcow2_get_specific_info()
5331 qcow2_has_zero_init(BlockDriverState *bs) in qcow2_has_zero_init() argument
5333 BDRVQcow2State *s = bs->opaque; in qcow2_has_zero_init()
5351 } else if (bs->encrypted) { in qcow2_has_zero_init()
5354 return bdrv_has_zero_init(s->data_file->bs); in qcow2_has_zero_init()
5362 static int64_t qcow2_check_vmstate_request(BlockDriverState *bs, in qcow2_check_vmstate_request() argument
5365 BDRVQcow2State *s = bs->opaque; in qcow2_check_vmstate_request()
5386 qcow2_co_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos) in qcow2_co_save_vmstate() argument
5388 int64_t offset = qcow2_check_vmstate_request(bs, qiov, pos); in qcow2_co_save_vmstate()
5393 BLKDBG_CO_EVENT(bs->file, BLKDBG_VMSTATE_SAVE); in qcow2_co_save_vmstate()
5394 return bs->drv->bdrv_co_pwritev_part(bs, offset, qiov->size, qiov, 0, 0); in qcow2_co_save_vmstate()
5398 qcow2_co_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos) in qcow2_co_load_vmstate() argument
5400 int64_t offset = qcow2_check_vmstate_request(bs, qiov, pos); in qcow2_co_load_vmstate()
5405 BLKDBG_CO_EVENT(bs->file, BLKDBG_VMSTATE_LOAD); in qcow2_co_load_vmstate()
5406 return bs->drv->bdrv_co_preadv_part(bs, offset, qiov->size, qiov, 0, 0); in qcow2_co_load_vmstate()
5409 static int GRAPH_RDLOCK qcow2_has_compressed_clusters(BlockDriverState *bs) in qcow2_has_compressed_clusters() argument
5412 int64_t bytes = bdrv_getlength(bs); in qcow2_has_compressed_clusters()
5424 ret = qcow2_get_host_offset(bs, offset, &cur_bytes, &host_offset, in qcow2_has_compressed_clusters()
5446 qcow2_downgrade(BlockDriverState *bs, int target_version, in qcow2_downgrade() argument
5450 BDRVQcow2State *s = bs->opaque; in qcow2_downgrade()
5466 if (has_data_file(bs)) { in qcow2_downgrade()
5480 s->snapshots[i].disk_size != bs->total_sectors * BDRV_SECTOR_SIZE) { in qcow2_downgrade()
5488 ret = qcow2_mark_clean(bs); in qcow2_downgrade()
5514 ret = qcow2_expand_zero_clusters(bs, status_cb, cb_opaque); in qcow2_downgrade()
5521 ret = qcow2_has_compressed_clusters(bs); in qcow2_downgrade()
5542 ret = qcow2_update_header(bs); in qcow2_downgrade()
5557 qcow2_upgrade(BlockDriverState *bs, int target_version, in qcow2_upgrade() argument
5561 BDRVQcow2State *s = bs->opaque; in qcow2_upgrade()
5573 status_cb(bs, 0, 2, cb_opaque); in qcow2_upgrade()
5593 ret = qcow2_write_snapshots(bs); in qcow2_upgrade()
5599 status_cb(bs, 1, 2, cb_opaque); in qcow2_upgrade()
5602 ret = qcow2_update_header(bs); in qcow2_upgrade()
5608 status_cb(bs, 2, 2, cb_opaque); in qcow2_upgrade()
5648 static void qcow2_amend_helper_cb(BlockDriverState *bs, in qcow2_amend_helper_cb() argument
5680 info->original_status_cb(bs, info->offset_completed + operation_offset, in qcow2_amend_helper_cb()
5686 qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts, in qcow2_amend_options() argument
5690 BDRVQcow2State *s = bs->opaque; in qcow2_amend_options()
5695 bool data_file_raw = data_file_is_raw(bs); in qcow2_amend_options()
5756 if (data_file && !has_data_file(bs)) { in qcow2_amend_options()
5764 if (data_file_raw && !data_file_is_raw(bs)) { in qcow2_amend_options()
5789 ret = qcow2_upgrade(bs, new_version, &qcow2_amend_helper_cb, in qcow2_amend_options()
5813 bs, in qcow2_amend_options()
5834 ret = qcow2_change_refcount_order(bs, refcount_order, in qcow2_amend_options()
5854 ret = qcow2_update_header(bs); in qcow2_amend_options()
5879 ret = qcow2_update_header(bs); in qcow2_amend_options()
5888 ret = qcow2_mark_clean(bs); in qcow2_amend_options()
5895 ret = qcow2_update_header(bs); in qcow2_amend_options()
5906 BlockBackend *blk = blk_new_with_bs(bs, BLK_PERM_RESIZE, BLK_PERM_ALL, in qcow2_amend_options()
5926 ret = qcow2_downgrade(bs, new_version, &qcow2_amend_helper_cb, in qcow2_amend_options()
5936 static int coroutine_fn qcow2_co_amend(BlockDriverState *bs, in qcow2_co_amend() argument
5942 BDRVQcow2State *s = bs->opaque; in qcow2_co_amend()
5966 bs, in qcow2_co_amend()
5980 void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset, in qcow2_signal_corruption() argument
5983 BDRVQcow2State *s = bs->opaque; in qcow2_signal_corruption()
5988 fatal = fatal && bdrv_is_writable(bs); in qcow2_signal_corruption()
6008 node_name = bdrv_get_node_name(bs); in qcow2_signal_corruption()
6009 qapi_event_send_block_image_corrupted(bdrv_get_device_name(bs), in qcow2_signal_corruption()
6017 qcow2_mark_corrupt(bs); in qcow2_signal_corruption()
6018 bs->drv = NULL; /* make BDS unusable */ in qcow2_signal_corruption()