Loading block.c +16 −0 Original line number Diff line number Diff line Loading @@ -1899,6 +1899,22 @@ int bdrv_snapshot_list(BlockDriverState *bs, return -ENOTSUP; } int bdrv_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name) { BlockDriver *drv = bs->drv; if (!drv) { return -ENOMEDIUM; } if (!bs->read_only) { return -EINVAL; } if (drv->bdrv_snapshot_load_tmp) { return drv->bdrv_snapshot_load_tmp(bs, snapshot_name); } return -ENOTSUP; } #define NB_SUFFIXES 4 char *get_human_readable_size(char *buf, int buf_size, int64_t size) Loading block.h +2 −0 Original line number Diff line number Diff line Loading @@ -211,6 +211,8 @@ int bdrv_snapshot_goto(BlockDriverState *bs, int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id); int bdrv_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_info); int bdrv_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name); char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn); char *get_human_readable_size(char *buf, int buf_size, int64_t size); Loading block/blkverify.c +3 −2 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ static AIOPool blkverify_aio_pool = { .cancel = blkverify_aio_cancel, }; static void blkverify_err(BlkverifyAIOCB *acb, const char *fmt, ...) static void GCC_FMT_ATTR(2, 3) blkverify_err(BlkverifyAIOCB *acb, const char *fmt, ...) { va_list ap; Loading Loading @@ -299,7 +300,7 @@ static void blkverify_verify_readv(BlkverifyAIOCB *acb) { ssize_t offset = blkverify_iovec_compare(acb->qiov, &acb->raw_qiov); if (offset != -1) { blkverify_err(acb, "contents mismatch in sector %ld", blkverify_err(acb, "contents mismatch in sector %lld", acb->sector_num + (offset / BDRV_SECTOR_SIZE)); } } Loading block/qcow2-cluster.c +16 −9 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ #include "block_int.h" #include "block/qcow2.h" int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size) { BDRVQcowState *s = bs->opaque; int new_l1_size, new_l1_size2, ret, i; Loading @@ -36,15 +36,22 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) int64_t new_l1_table_offset; uint8_t data[12]; new_l1_size = s->l1_size; if (min_size <= new_l1_size) if (min_size <= s->l1_size) return 0; if (exact_size) { new_l1_size = min_size; } else { /* Bump size up to reduce the number of times we have to grow */ new_l1_size = s->l1_size; if (new_l1_size == 0) { new_l1_size = 1; } while (min_size > new_l1_size) { new_l1_size = (new_l1_size * 3 + 1) / 2; } } #ifdef DEBUG_ALLOC2 printf("grow l1_table from %d to %d\n", s->l1_size, new_l1_size); #endif Loading Loading @@ -550,7 +557,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, l1_index = offset >> (s->l2_bits + s->cluster_bits); if (l1_index >= s->l1_size) { ret = qcow2_grow_l1_table(bs, l1_index + 1); ret = qcow2_grow_l1_table(bs, l1_index + 1, false); if (ret < 0) { return ret; } Loading block/qcow2-snapshot.c +32 −1 Original line number Diff line number Diff line Loading @@ -327,7 +327,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0) goto fail; if (qcow2_grow_l1_table(bs, sn->l1_size) < 0) if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0) goto fail; s->l1_size = sn->l1_size; Loading Loading @@ -418,3 +418,34 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) return s->nb_snapshots; } int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name) { int i, snapshot_index, l1_size2; BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_name); if (snapshot_index < 0) { return -ENOENT; } sn = &s->snapshots[snapshot_index]; s->l1_size = sn->l1_size; l1_size2 = s->l1_size * sizeof(uint64_t); if (s->l1_table != NULL) { qemu_free(s->l1_table); } s->l1_table_offset = sn->l1_table_offset; s->l1_table = qemu_mallocz(align_offset(l1_size2, 512)); if (bdrv_pread(bs->file, sn->l1_table_offset, s->l1_table, l1_size2) != l1_size2) { return -1; } for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); } return 0; } Loading
block.c +16 −0 Original line number Diff line number Diff line Loading @@ -1899,6 +1899,22 @@ int bdrv_snapshot_list(BlockDriverState *bs, return -ENOTSUP; } int bdrv_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name) { BlockDriver *drv = bs->drv; if (!drv) { return -ENOMEDIUM; } if (!bs->read_only) { return -EINVAL; } if (drv->bdrv_snapshot_load_tmp) { return drv->bdrv_snapshot_load_tmp(bs, snapshot_name); } return -ENOTSUP; } #define NB_SUFFIXES 4 char *get_human_readable_size(char *buf, int buf_size, int64_t size) Loading
block.h +2 −0 Original line number Diff line number Diff line Loading @@ -211,6 +211,8 @@ int bdrv_snapshot_goto(BlockDriverState *bs, int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id); int bdrv_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_info); int bdrv_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name); char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn); char *get_human_readable_size(char *buf, int buf_size, int64_t size); Loading
block/blkverify.c +3 −2 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ static AIOPool blkverify_aio_pool = { .cancel = blkverify_aio_cancel, }; static void blkverify_err(BlkverifyAIOCB *acb, const char *fmt, ...) static void GCC_FMT_ATTR(2, 3) blkverify_err(BlkverifyAIOCB *acb, const char *fmt, ...) { va_list ap; Loading Loading @@ -299,7 +300,7 @@ static void blkverify_verify_readv(BlkverifyAIOCB *acb) { ssize_t offset = blkverify_iovec_compare(acb->qiov, &acb->raw_qiov); if (offset != -1) { blkverify_err(acb, "contents mismatch in sector %ld", blkverify_err(acb, "contents mismatch in sector %lld", acb->sector_num + (offset / BDRV_SECTOR_SIZE)); } } Loading
block/qcow2-cluster.c +16 −9 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ #include "block_int.h" #include "block/qcow2.h" int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size) { BDRVQcowState *s = bs->opaque; int new_l1_size, new_l1_size2, ret, i; Loading @@ -36,15 +36,22 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) int64_t new_l1_table_offset; uint8_t data[12]; new_l1_size = s->l1_size; if (min_size <= new_l1_size) if (min_size <= s->l1_size) return 0; if (exact_size) { new_l1_size = min_size; } else { /* Bump size up to reduce the number of times we have to grow */ new_l1_size = s->l1_size; if (new_l1_size == 0) { new_l1_size = 1; } while (min_size > new_l1_size) { new_l1_size = (new_l1_size * 3 + 1) / 2; } } #ifdef DEBUG_ALLOC2 printf("grow l1_table from %d to %d\n", s->l1_size, new_l1_size); #endif Loading Loading @@ -550,7 +557,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, l1_index = offset >> (s->l2_bits + s->cluster_bits); if (l1_index >= s->l1_size) { ret = qcow2_grow_l1_table(bs, l1_index + 1); ret = qcow2_grow_l1_table(bs, l1_index + 1, false); if (ret < 0) { return ret; } Loading
block/qcow2-snapshot.c +32 −1 Original line number Diff line number Diff line Loading @@ -327,7 +327,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0) goto fail; if (qcow2_grow_l1_table(bs, sn->l1_size) < 0) if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0) goto fail; s->l1_size = sn->l1_size; Loading Loading @@ -418,3 +418,34 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) return s->nb_snapshots; } int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name) { int i, snapshot_index, l1_size2; BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_name); if (snapshot_index < 0) { return -ENOENT; } sn = &s->snapshots[snapshot_index]; s->l1_size = sn->l1_size; l1_size2 = s->l1_size * sizeof(uint64_t); if (s->l1_table != NULL) { qemu_free(s->l1_table); } s->l1_table_offset = sn->l1_table_offset; s->l1_table = qemu_mallocz(align_offset(l1_size2, 512)); if (bdrv_pread(bs->file, sn->l1_table_offset, s->l1_table, l1_size2) != l1_size2) { return -1; } for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); } return 0; }