Lines Matching refs:bs

35 static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size,
39 static int update_refcount(BlockDriverState *bs,
101 int coroutine_fn qcow2_refcount_init(BlockDriverState *bs) in qcow2_refcount_init() argument
103 BDRVQcow2State *s = bs->opaque; in qcow2_refcount_init()
121 BLKDBG_CO_EVENT(bs->file, BLKDBG_REFTABLE_LOAD); in qcow2_refcount_init()
122 ret = bdrv_co_pread(bs->file, s->refcount_table_offset, in qcow2_refcount_init()
136 void qcow2_refcount_close(BlockDriverState *bs) in qcow2_refcount_close() argument
138 BDRVQcow2State *s = bs->opaque; in qcow2_refcount_close()
233 load_refcount_block(BlockDriverState *bs, int64_t refcount_block_offset, in load_refcount_block() argument
236 BDRVQcow2State *s = bs->opaque; in load_refcount_block()
238 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_LOAD); in load_refcount_block()
239 return qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset, in load_refcount_block()
247 int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index, in qcow2_get_refcount() argument
250 BDRVQcow2State *s = bs->opaque; in qcow2_get_refcount()
269 qcow2_signal_corruption(bs, true, -1, -1, "Refblock offset %#" PRIx64 in qcow2_get_refcount()
275 ret = qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset, in qcow2_get_refcount()
306 alloc_refcount_block(BlockDriverState *bs, int64_t cluster_index, in alloc_refcount_block() argument
309 BDRVQcow2State *s = bs->opaque; in alloc_refcount_block()
313 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC); in alloc_refcount_block()
326 qcow2_signal_corruption(bs, true, -1, -1, "Refblock offset %#" in alloc_refcount_block()
333 return load_refcount_block(bs, refcount_block_offset, in alloc_refcount_block()
364 ret = qcow2_cache_flush(bs, s->l2_table_cache); in alloc_refcount_block()
370 int64_t new_block = alloc_clusters_noref(bs, s->cluster_size, INT64_MAX); in alloc_refcount_block()
380 qcow2_signal_corruption(bs, true, -1, -1, "Preventing invalid " in alloc_refcount_block()
393 ret = qcow2_cache_get_empty(bs, s->refcount_block_cache, new_block, in alloc_refcount_block()
408 ret = update_refcount(bs, new_block, s->cluster_size, 1, false, in alloc_refcount_block()
414 ret = qcow2_cache_flush(bs, s->refcount_block_cache); in alloc_refcount_block()
421 ret = qcow2_cache_get_empty(bs, s->refcount_block_cache, new_block, in alloc_refcount_block()
431 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE); in alloc_refcount_block()
433 ret = qcow2_cache_flush(bs, s->refcount_block_cache); in alloc_refcount_block()
441 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_HOOKUP); in alloc_refcount_block()
442 ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset + in alloc_refcount_block()
473 BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_GROW); in alloc_refcount_block()
494 ret = qcow2_refcount_area(bs, meta_offset, 0, false, in alloc_refcount_block()
500 ret = load_refcount_block(bs, new_block, refcount_block); in alloc_refcount_block()
532 int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset, in qcow2_refcount_area() argument
537 BDRVQcow2State *s = bs->opaque; in qcow2_refcount_area()
622 ret = qcow2_cache_get(bs, s->refcount_block_cache, new_table[i], in qcow2_refcount_area()
628 ret = qcow2_cache_get_empty(bs, s->refcount_block_cache, in qcow2_refcount_area()
677 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS); in qcow2_refcount_area()
678 ret = qcow2_cache_flush(bs, s->refcount_block_cache); in qcow2_refcount_area()
688 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE); in qcow2_refcount_area()
689 ret = bdrv_pwrite_sync(bs->file, table_offset, in qcow2_refcount_area()
706 BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE); in qcow2_refcount_area()
707 ret = bdrv_pwrite_sync(bs->file, in qcow2_refcount_area()
725 qcow2_free_clusters(bs, old_table_offset, in qcow2_refcount_area()
736 void qcow2_process_discards(BlockDriverState *bs, int ret) in qcow2_process_discards() argument
738 BDRVQcow2State *s = bs->opaque; in qcow2_process_discards()
746 int r2 = bdrv_pdiscard(bs->file, d->offset, d->bytes); in qcow2_process_discards()
757 static void update_refcount_discard(BlockDriverState *bs, in update_refcount_discard() argument
760 BDRVQcow2State *s = bs->opaque; in update_refcount_discard()
780 .bs = bs, in update_refcount_discard()
811 update_refcount(BlockDriverState *bs, int64_t offset, int64_t length, in update_refcount() argument
814 BDRVQcow2State *s = bs->opaque; in update_refcount()
832 qcow2_cache_set_dependency(bs, s->refcount_block_cache, in update_refcount()
851 ret = alloc_refcount_block(bs, cluster_index, &refcount_block); in update_refcount()
905 update_refcount_discard(bs, cluster_offset, s->cluster_size); in update_refcount()
913 qcow2_process_discards(bs, ret); in update_refcount()
927 dummy = update_refcount(bs, offset, cluster_offset - offset, addend, in update_refcount()
943 int qcow2_update_cluster_refcount(BlockDriverState *bs, in qcow2_update_cluster_refcount() argument
948 BDRVQcow2State *s = bs->opaque; in qcow2_update_cluster_refcount()
951 ret = update_refcount(bs, cluster_index << s->cluster_bits, 1, addend, in qcow2_update_cluster_refcount()
969 alloc_clusters_noref(BlockDriverState *bs, uint64_t size, uint64_t max) in alloc_clusters_noref() argument
971 BDRVQcow2State *s = bs->opaque; in alloc_clusters_noref()
977 qcow2_process_discards(bs, 0); in alloc_clusters_noref()
984 ret = qcow2_get_refcount(bs, next_cluster_index, &refcount); in alloc_clusters_noref()
1009 int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size) in qcow2_alloc_clusters() argument
1014 BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC); in qcow2_alloc_clusters()
1016 offset = alloc_clusters_noref(bs, size, QCOW_MAX_CLUSTER_OFFSET); in qcow2_alloc_clusters()
1021 ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER); in qcow2_alloc_clusters()
1031 int64_t coroutine_fn qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, in qcow2_alloc_clusters_at() argument
1034 BDRVQcow2State *s = bs->opaque; in qcow2_alloc_clusters_at()
1048 ret = qcow2_get_refcount(bs, cluster_index++, &refcount); in qcow2_alloc_clusters_at()
1057 ret = update_refcount(bs, offset, i << s->cluster_bits, 1, false, in qcow2_alloc_clusters_at()
1070 int64_t coroutine_fn GRAPH_RDLOCK qcow2_alloc_bytes(BlockDriverState *bs, int size) in qcow2_alloc_bytes() argument
1072 BDRVQcow2State *s = bs->opaque; in qcow2_alloc_bytes()
1077 BLKDBG_CO_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_BYTES); in qcow2_alloc_bytes()
1085 ret = qcow2_get_refcount(bs, offset >> s->cluster_bits, &refcount); in qcow2_alloc_bytes()
1100 new_cluster = alloc_clusters_noref(bs, s->cluster_size, in qcow2_alloc_bytes()
1108 qcow2_signal_corruption(bs, true, -1, -1, "Preventing invalid " in qcow2_alloc_bytes()
1123 ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER); in qcow2_alloc_bytes()
1134 qcow2_cache_set_dependency(bs, s->l2_table_cache, s->refcount_block_cache); in qcow2_alloc_bytes()
1144 void qcow2_free_clusters(BlockDriverState *bs, in qcow2_free_clusters() argument
1150 BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_FREE); in qcow2_free_clusters()
1151 ret = update_refcount(bs, offset, size, 1, true, type); in qcow2_free_clusters()
1162 void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry, in qcow2_free_any_cluster() argument
1165 BDRVQcow2State *s = bs->opaque; in qcow2_free_any_cluster()
1166 QCow2ClusterType ctype = qcow2_get_cluster_type(bs, l2_entry); in qcow2_free_any_cluster()
1168 if (has_data_file(bs)) { in qcow2_free_any_cluster()
1185 qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize); in qcow2_free_any_cluster()
1186 qcow2_free_clusters(bs, coffset, csize, type); in qcow2_free_any_cluster()
1192 qcow2_signal_corruption(bs, false, -1, -1, in qcow2_free_any_cluster()
1196 qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK, in qcow2_free_any_cluster()
1208 int qcow2_write_caches(BlockDriverState *bs) in qcow2_write_caches() argument
1210 BDRVQcow2State *s = bs->opaque; in qcow2_write_caches()
1213 ret = qcow2_cache_write(bs, s->l2_table_cache); in qcow2_write_caches()
1219 ret = qcow2_cache_write(bs, s->refcount_block_cache); in qcow2_write_caches()
1228 int qcow2_flush_caches(BlockDriverState *bs) in qcow2_flush_caches() argument
1230 int ret = qcow2_write_caches(bs); in qcow2_flush_caches()
1235 return bdrv_flush(bs->file->bs); in qcow2_flush_caches()
1244 int qcow2_update_snapshot_refcount(BlockDriverState *bs, in qcow2_update_snapshot_refcount() argument
1247 BDRVQcow2State *s = bs->opaque; in qcow2_update_snapshot_refcount()
1276 ret = bdrv_pread(bs->file, l1_table_offset, l1_size2, l1_table, 0); in qcow2_update_snapshot_refcount()
1297 qcow2_signal_corruption(bs, true, -1, -1, "L2 table offset %#" in qcow2_update_snapshot_refcount()
1305 ret = qcow2_cache_get(bs, s->l2_table_cache, in qcow2_update_snapshot_refcount()
1321 switch (qcow2_get_cluster_type(bs, entry)) { in qcow2_update_snapshot_refcount()
1327 qcow2_parse_compressed_l2_entry(bs, entry, in qcow2_update_snapshot_refcount()
1330 bs, coffset, csize, in qcow2_update_snapshot_refcount()
1347 bs, true, -1, -1, "Cluster " in qcow2_update_snapshot_refcount()
1360 bs, cluster_index, abs(addend), addend < 0, in qcow2_update_snapshot_refcount()
1367 ret = qcow2_get_refcount(bs, cluster_index, &refcount); in qcow2_update_snapshot_refcount()
1387 qcow2_cache_set_dependency(bs, s->l2_table_cache, in qcow2_update_snapshot_refcount()
1400 ret = qcow2_update_cluster_refcount(bs, l2_offset >> in qcow2_update_snapshot_refcount()
1408 ret = qcow2_get_refcount(bs, l2_offset >> s->cluster_bits, in qcow2_update_snapshot_refcount()
1422 ret = bdrv_flush(bs); in qcow2_update_snapshot_refcount()
1429 qcow2_process_discards(bs, ret); in qcow2_update_snapshot_refcount()
1437 ret = bdrv_pwrite_sync(bs->file, l1_table_offset, l1_size2, l1_table, in qcow2_update_snapshot_refcount()
1526 qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res, in qcow2_inc_refcounts_imrt() argument
1531 BDRVQcow2State *s = bs->opaque; in qcow2_inc_refcounts_imrt()
1540 file_len = bdrv_co_getlength(bs->file->bs); in qcow2_inc_refcounts_imrt()
1603 fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res, in fix_l2_entry_by_zero() argument
1608 BDRVQcow2State *s = bs->opaque; in fix_l2_entry_by_zero()
1627 ret = qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_size(s), in fix_l2_entry_by_zero()
1637 ret = bdrv_co_pwrite_sync(bs->file, l2e_offset, l2_entry_size(s), in fix_l2_entry_by_zero()
1663 check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, in check_refcounts_l2() argument
1668 BDRVQcow2State *s = bs->opaque; in check_refcounts_l2()
1677 ret = bdrv_co_pread(bs->file, l2_offset, l2_size_bytes, l2_table, 0); in check_refcounts_l2()
1692 type = qcow2_get_cluster_type(bs, l2_entry); in check_refcounts_l2()
1714 if (has_data_file(bs)) { in check_refcounts_l2()
1730 qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize); in check_refcounts_l2()
1732 bs, res, refcount_table, refcount_table_size, coffset, csize); in check_refcounts_l2()
1781 ret = fix_l2_entry_by_zero(bs, res, l2_offset, in check_refcounts_l2()
1822 if (!has_data_file(bs)) { in check_refcounts_l2()
1823 ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, in check_refcounts_l2()
1863 check_refcounts_l1(BlockDriverState *bs, BdrvCheckResult *res, in check_refcounts_l1() argument
1868 BDRVQcow2State *s = bs->opaque; in check_refcounts_l1()
1879 ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_table_size, in check_refcounts_l1()
1892 ret = bdrv_co_pread(bs->file, l1_table_offset, l1_size_bytes, l1_table, 0); in check_refcounts_l1()
1918 ret = qcow2_inc_refcounts_imrt(bs, res, in check_refcounts_l1()
1933 ret = check_refcounts_l2(bs, res, refcount_table, in check_refcounts_l1()
1953 check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) in check_oflag_copied() argument
1955 BDRVQcow2State *s = bs->opaque; in check_oflag_copied()
1956 uint64_t *l2_table = qemu_blockalign(bs, s->cluster_size); in check_oflag_copied()
1983 ret = qcow2_get_refcount(bs, l2_offset >> s->cluster_bits, in check_oflag_copied()
1998 ret = qcow2_write_l1_entry(bs, i); in check_oflag_copied()
2008 ret = bdrv_co_pread(bs->file, l2_offset, s->l2_size * l2_entry_size(s), in check_oflag_copied()
2020 QCow2ClusterType cluster_type = qcow2_get_cluster_type(bs, l2_entry); in check_oflag_copied()
2024 if (has_data_file(bs)) { in check_oflag_copied()
2027 ret = qcow2_get_refcount(bs, in check_oflag_copied()
2052 ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_ACTIVE_L2, in check_oflag_copied()
2062 ret = bdrv_co_pwrite(bs->file, l2_offset, s->cluster_size, l2_table, 0); in check_oflag_copied()
2086 check_refblocks(BlockDriverState *bs, BdrvCheckResult *res, in check_refblocks() argument
2090 BDRVQcow2State *s = bs->opaque; in check_refblocks()
2130 ret = bdrv_co_truncate(bs->file, offset + s->cluster_size, false, in check_refblocks()
2136 size = bdrv_co_getlength(bs->file->bs); in check_refblocks()
2159 ret = qcow2_inc_refcounts_imrt(bs, res, in check_refblocks()
2179 ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, in check_refblocks()
2201 calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res, in calculate_refcounts() argument
2205 BDRVQcow2State *s = bs->opaque; in calculate_refcounts()
2221 ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, in calculate_refcounts()
2228 ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters, in calculate_refcounts()
2236 if (has_data_file(bs) && s->nb_snapshots) { in calculate_refcounts()
2258 ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters, in calculate_refcounts()
2265 ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, in calculate_refcounts()
2272 ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, in calculate_refcounts()
2282 ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, in calculate_refcounts()
2291 ret = qcow2_check_bitmaps_refcounts(bs, res, refcount_table, nb_clusters); in calculate_refcounts()
2296 return check_refblocks(bs, res, fix, rebuild, refcount_table, nb_clusters); in calculate_refcounts()
2304 compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res, in compare_refcounts() argument
2309 BDRVQcow2State *s = bs->opaque; in compare_refcounts()
2315 ret = qcow2_get_refcount(bs, i, &refcount1); in compare_refcounts()
2348 ret = update_refcount(bs, i << s->cluster_bits, 1, in compare_refcounts()
2380 static int64_t alloc_clusters_imrt(BlockDriverState *bs, in alloc_clusters_imrt() argument
2386 BDRVQcow2State *s = bs->opaque; in alloc_clusters_imrt()
2470 BlockDriverState *bs, void **refcount_table, int64_t *nb_clusters, in rebuild_refcounts_write_refblocks() argument
2476 BDRVQcow2State *s = bs->opaque; in rebuild_refcounts_write_refblocks()
2520 refblock_offset = alloc_clusters_imrt(bs, 1, refcount_table, in rebuild_refcounts_write_refblocks()
2568 ret = qcow2_pre_write_overlap_check(bs, 0, refblock_offset, in rebuild_refcounts_write_refblocks()
2584 ret = bdrv_co_pwrite(bs->file, refblock_offset, s->cluster_size, in rebuild_refcounts_write_refblocks()
2608 rebuild_refcount_structure(BlockDriverState *bs, BdrvCheckResult *res, in rebuild_refcount_structure() argument
2612 BDRVQcow2State *s = bs->opaque; in rebuild_refcount_structure()
2626 qcow2_cache_empty(bs, s->refcount_block_cache); in rebuild_refcount_structure()
2658 rebuild_refcounts_write_refblocks(bs, refcount_table, nb_clusters, in rebuild_refcount_structure()
2681 reftable_offset = alloc_clusters_imrt(bs, reftable_clusters, in rebuild_refcount_structure()
2700 rebuild_refcounts_write_refblocks(bs, refcount_table, nb_clusters, in rebuild_refcount_structure()
2731 ret = qcow2_pre_write_overlap_check(bs, 0, reftable_offset, reftable_length, in rebuild_refcount_structure()
2739 ret = bdrv_co_pwrite(bs->file, reftable_offset, reftable_length, in rebuild_refcount_structure()
2750 ret = bdrv_co_pwrite_sync(bs->file, in rebuild_refcount_structure()
2783 qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) in qcow2_check_refcounts() argument
2785 BDRVQcow2State *s = bs->opaque; in qcow2_check_refcounts()
2792 size = bdrv_co_getlength(bs->file->bs); in qcow2_check_refcounts()
2805 size_to_clusters(s, bs->total_sectors * BDRV_SECTOR_SIZE); in qcow2_check_refcounts()
2807 ret = calculate_refcounts(bs, res, fix, &rebuild, &refcount_table, in qcow2_check_refcounts()
2817 compare_refcounts(bs, res, 0, &rebuild, &highest_cluster, refcount_table, in qcow2_check_refcounts()
2826 ret = rebuild_refcount_structure(bs, res, &refcount_table, in qcow2_check_refcounts()
2840 ret = calculate_refcounts(bs, res, 0, &rebuild, &refcount_table, in qcow2_check_refcounts()
2853 compare_refcounts(bs, res, BDRV_FIX_LEAKS, &rebuild, in qcow2_check_refcounts()
2884 compare_refcounts(bs, res, fix, &rebuild, &highest_cluster, in qcow2_check_refcounts()
2890 ret = check_oflag_copied(bs, res, fix); in qcow2_check_refcounts()
2921 int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset, in qcow2_check_metadata_overlap() argument
2924 BDRVQcow2State *s = bs->opaque; in qcow2_check_metadata_overlap()
3003 ret = qcow2_validate_table(bs, l1_ofs, l1_sz, L1E_SIZE, in qcow2_check_metadata_overlap()
3015 ret = bdrv_pread(bs->file, l1_ofs, l1_sz2, l1, 0); in qcow2_check_metadata_overlap()
3069 int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset, in qcow2_pre_write_overlap_check() argument
3074 if (data_file && has_data_file(bs)) { in qcow2_pre_write_overlap_check()
3078 ret = qcow2_check_metadata_overlap(bs, ign, offset, size); in qcow2_pre_write_overlap_check()
3085 qcow2_signal_corruption(bs, true, offset, size, "Preventing invalid " in qcow2_pre_write_overlap_check()
3105 (RefblockFinishOp)(BlockDriverState *bs, uint64_t **reftable,
3116 alloc_refblock(BlockDriverState *bs, uint64_t **reftable, in alloc_refblock() argument
3121 BDRVQcow2State *s = bs->opaque; in alloc_refblock()
3152 offset = qcow2_alloc_clusters(bs, s->cluster_size); in alloc_refblock()
3170 flush_refblock(BlockDriverState *bs, uint64_t **reftable, in flush_refblock() argument
3175 BDRVQcow2State *s = bs->opaque; in flush_refblock()
3182 ret = qcow2_pre_write_overlap_check(bs, 0, offset, s->cluster_size, in flush_refblock()
3189 ret = bdrv_pwrite(bs->file, offset, s->cluster_size, refblock, 0); in flush_refblock()
3215 walk_over_reftable(BlockDriverState *bs, uint64_t **new_reftable, in walk_over_reftable() argument
3226 BDRVQcow2State *s = bs->opaque; in walk_over_reftable()
3239 status_cb(bs, (uint64_t)index * s->refcount_table_size + reftable_index, in walk_over_reftable()
3246 qcow2_signal_corruption(bs, true, -1, -1, "Refblock offset %#" in walk_over_reftable()
3255 ret = qcow2_cache_get(bs, s->refcount_block_cache, refblock_offset, in walk_over_reftable()
3269 ret = operation(bs, new_reftable, *new_reftable_index, in walk_over_reftable()
3315 ret = operation(bs, new_reftable, *new_reftable_index, in walk_over_reftable()
3346 ret = operation(bs, new_reftable, *new_reftable_index, in walk_over_reftable()
3356 status_cb(bs, (uint64_t)(index + 1) * s->refcount_table_size, in walk_over_reftable()
3362 int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, in qcow2_change_refcount_order() argument
3366 BDRVQcow2State *s = bs->opaque; in qcow2_change_refcount_order()
3369 void *new_refblock = qemu_blockalign(bs->file->bs, s->cluster_size); in qcow2_change_refcount_order()
3405 ret = walk_over_reftable(bs, &new_reftable, &new_reftable_index, in qcow2_change_refcount_order()
3419 bs, new_reftable_offset, in qcow2_change_refcount_order()
3424 new_reftable_offset = qcow2_alloc_clusters(bs, new_reftable_size * in qcow2_change_refcount_order()
3437 ret = walk_over_reftable(bs, &new_reftable, &new_reftable_index, in qcow2_change_refcount_order()
3450 ret = qcow2_pre_write_overlap_check(bs, 0, new_reftable_offset, in qcow2_change_refcount_order()
3462 ret = bdrv_pwrite(bs->file, new_reftable_offset, in qcow2_change_refcount_order()
3477 ret = qcow2_cache_flush(bs, s->refcount_block_cache); in qcow2_change_refcount_order()
3495 ret = qcow2_update_header(bs); in qcow2_change_refcount_order()
3533 qcow2_free_clusters(bs, offset, s->cluster_size, in qcow2_change_refcount_order()
3540 qcow2_free_clusters(bs, new_reftable_offset, in qcow2_change_refcount_order()
3551 get_refblock_offset(BlockDriverState *bs, uint64_t offset) in get_refblock_offset() argument
3553 BDRVQcow2State *s = bs->opaque; in get_refblock_offset()
3561 qcow2_signal_corruption(bs, true, -1, -1, "Refblock at %#" PRIx64 " is " in get_refblock_offset()
3571 qcow2_discard_refcount_block(BlockDriverState *bs, uint64_t discard_block_offs) in qcow2_discard_refcount_block() argument
3573 BDRVQcow2State *s = bs->opaque; in qcow2_discard_refcount_block()
3580 refblock_offs = get_refblock_offset(bs, discard_block_offs); in qcow2_discard_refcount_block()
3587 ret = qcow2_cache_get(bs, s->refcount_block_cache, refblock_offs, in qcow2_discard_refcount_block()
3594 qcow2_signal_corruption(bs, true, -1, -1, "Invalid refcount:" in qcow2_discard_refcount_block()
3622 update_refcount_discard(bs, discard_block_offs, s->cluster_size); in qcow2_discard_refcount_block()
3627 int coroutine_fn qcow2_shrink_reftable(BlockDriverState *bs) in qcow2_shrink_reftable() argument
3629 BDRVQcow2State *s = bs->opaque; in qcow2_shrink_reftable()
3643 ret = qcow2_cache_get(bs, s->refcount_block_cache, refblock_offs, in qcow2_shrink_reftable()
3668 ret = bdrv_co_pwrite_sync(bs->file, s->refcount_table_offset, in qcow2_shrink_reftable()
3679 ret = qcow2_discard_refcount_block(bs, s->refcount_table[i] & in qcow2_shrink_reftable()
3687 qcow2_process_discards(bs, ret); in qcow2_shrink_reftable()
3695 int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t size) in qcow2_get_last_cluster() argument
3697 BDRVQcow2State *s = bs->opaque; in qcow2_get_last_cluster()
3702 int ret = qcow2_get_refcount(bs, i, &refcount); in qcow2_get_last_cluster()
3712 qcow2_signal_corruption(bs, true, -1, -1, in qcow2_get_last_cluster()
3718 qcow2_detect_metadata_preallocation(BlockDriverState *bs) in qcow2_detect_metadata_preallocation() argument
3720 BDRVQcow2State *s = bs->opaque; in qcow2_detect_metadata_preallocation()
3726 file_length = bdrv_co_getlength(bs->file->bs); in qcow2_detect_metadata_preallocation()
3731 real_allocation = bdrv_co_get_allocated_file_size(bs->file->bs); in qcow2_detect_metadata_preallocation()
3742 int ret = qcow2_get_refcount(bs, i, &refcount); in qcow2_detect_metadata_preallocation()