Lines Matching refs:bs
34 static void qcow2_free_single_snapshot(BlockDriverState *bs, int i) in qcow2_free_single_snapshot() argument
36 BDRVQcow2State *s = bs->opaque; in qcow2_free_single_snapshot()
45 void qcow2_free_snapshots(BlockDriverState *bs) in qcow2_free_snapshots() argument
47 BDRVQcow2State *s = bs->opaque; in qcow2_free_snapshots()
51 qcow2_free_single_snapshot(bs, i); in qcow2_free_snapshots()
81 int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, in qcow2_do_read_snapshots() argument
86 BDRVQcow2State *s = bs->opaque; in qcow2_do_read_snapshots()
112 ret = bdrv_co_pread(bs->file, offset, sizeof(h), &h, 0); in qcow2_do_read_snapshots()
150 ret = bdrv_co_pread(bs->file, offset, in qcow2_do_read_snapshots()
166 sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE; in qcow2_do_read_snapshots()
188 ret = bdrv_co_pread(bs->file, offset, unknown_extra_data_size, in qcow2_do_read_snapshots()
200 ret = bdrv_co_pread(bs->file, offset, id_str_size, sn->id_str, 0); in qcow2_do_read_snapshots()
210 ret = bdrv_co_pread(bs->file, offset, name_size, sn->name, 0); in qcow2_do_read_snapshots()
243 qcow2_free_single_snapshot(bs, i); in qcow2_do_read_snapshots()
261 qcow2_free_snapshots(bs); in qcow2_do_read_snapshots()
265 int coroutine_fn qcow2_read_snapshots(BlockDriverState *bs, Error **errp) in qcow2_read_snapshots() argument
267 return qcow2_do_read_snapshots(bs, false, NULL, NULL, errp); in qcow2_read_snapshots()
271 int qcow2_write_snapshots(BlockDriverState *bs) in qcow2_write_snapshots() argument
273 BDRVQcow2State *s = bs->opaque; in qcow2_write_snapshots()
305 snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size); in qcow2_write_snapshots()
311 ret = bdrv_flush(bs); in qcow2_write_snapshots()
318 ret = qcow2_pre_write_overlap_check(bs, 0, offset, snapshots_size, false); in qcow2_write_snapshots()
353 ret = bdrv_pwrite(bs->file, offset, sizeof(h), &h, 0); in qcow2_write_snapshots()
359 ret = bdrv_pwrite(bs->file, offset, sizeof(extra), &extra, 0); in qcow2_write_snapshots()
373 ret = bdrv_pwrite(bs->file, offset, unknown_extra_data_size, in qcow2_write_snapshots()
381 ret = bdrv_pwrite(bs->file, offset, id_str_size, sn->id_str, 0); in qcow2_write_snapshots()
387 ret = bdrv_pwrite(bs->file, offset, name_size, sn->name, 0); in qcow2_write_snapshots()
398 ret = bdrv_flush(bs); in qcow2_write_snapshots()
409 ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), in qcow2_write_snapshots()
416 qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size, in qcow2_write_snapshots()
424 qcow2_free_clusters(bs, snapshots_offset, snapshots_size, in qcow2_write_snapshots()
430 int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, in qcow2_check_read_snapshot_table() argument
434 BDRVQcow2State *s = bs->opaque; in qcow2_check_read_snapshot_table()
445 ret = bdrv_co_pread(bs->file, offsetof(QCowHeader, nb_snapshots), in qcow2_check_read_snapshot_table()
466 ret = qcow2_validate_table(bs, s->snapshots_offset, s->nb_snapshots, in qcow2_check_read_snapshot_table()
488 ret = qcow2_do_read_snapshots(bs, fix & BDRV_FIX_ERRORS, in qcow2_check_read_snapshot_table()
516 ret = bdrv_co_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), in qcow2_check_read_snapshot_table()
551 int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs, in qcow2_check_fix_snapshot_table() argument
555 BDRVQcow2State *s = bs->opaque; in qcow2_check_fix_snapshot_table()
560 ret = qcow2_write_snapshots(bs); in qcow2_check_fix_snapshot_table()
576 static void find_new_snapshot_id(BlockDriverState *bs, in find_new_snapshot_id() argument
579 BDRVQcow2State *s = bs->opaque; in find_new_snapshot_id()
593 static int find_snapshot_by_id_and_name(BlockDriverState *bs, in find_snapshot_by_id_and_name() argument
597 BDRVQcow2State *s = bs->opaque; in find_snapshot_by_id_and_name()
624 static int find_snapshot_by_id_or_name(BlockDriverState *bs, in find_snapshot_by_id_or_name() argument
629 ret = find_snapshot_by_id_and_name(bs, id_or_name, NULL); in find_snapshot_by_id_or_name()
633 return find_snapshot_by_id_and_name(bs, NULL, id_or_name); in find_snapshot_by_id_or_name()
637 int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) in qcow2_snapshot_create() argument
639 BDRVQcow2State *s = bs->opaque; in qcow2_snapshot_create()
651 if (has_data_file(bs)) { in qcow2_snapshot_create()
658 find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str)); in qcow2_snapshot_create()
664 sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE; in qcow2_snapshot_create()
673 l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * L1E_SIZE); in qcow2_snapshot_create()
692 ret = qcow2_pre_write_overlap_check(bs, 0, sn->l1_table_offset, in qcow2_snapshot_create()
698 ret = bdrv_pwrite(bs->file, sn->l1_table_offset, s->l1_size * L1E_SIZE, in qcow2_snapshot_create()
712 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1); in qcow2_snapshot_create()
727 ret = qcow2_write_snapshots(bs); in qcow2_snapshot_create()
739 qcow2_cluster_discard(bs, qcow2_vm_state_offset(s), in qcow2_snapshot_create()
746 qcow2_check_refcounts(bs, &result, 0); in qcow2_snapshot_create()
760 int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) in qcow2_snapshot_goto() argument
762 BDRVQcow2State *s = bs->opaque; in qcow2_snapshot_goto()
770 if (has_data_file(bs)) { in qcow2_snapshot_goto()
775 snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id); in qcow2_snapshot_goto()
781 ret = qcow2_validate_table(bs, sn->l1_table_offset, sn->l1_size, in qcow2_snapshot_goto()
789 if (sn->disk_size != bs->total_sectors * BDRV_SECTOR_SIZE) { in qcow2_snapshot_goto()
790 BlockBackend *blk = blk_new_with_bs(bs, BLK_PERM_RESIZE, BLK_PERM_ALL, in qcow2_snapshot_goto()
812 ret = qcow2_grow_l1_table(bs, sn->l1_size, true); in qcow2_snapshot_goto()
834 ret = bdrv_pread(bs->file, sn->l1_table_offset, sn_l1_bytes, sn_l1_table, in qcow2_snapshot_goto()
840 ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset, in qcow2_snapshot_goto()
846 ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_ACTIVE_L1, in qcow2_snapshot_goto()
853 ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, cur_l1_bytes, in qcow2_snapshot_goto()
869 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, in qcow2_snapshot_goto()
891 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0); in qcow2_snapshot_goto()
899 qcow2_check_refcounts(bs, &result, 0); in qcow2_snapshot_goto()
909 int qcow2_snapshot_delete(BlockDriverState *bs, in qcow2_snapshot_delete() argument
914 BDRVQcow2State *s = bs->opaque; in qcow2_snapshot_delete()
918 if (has_data_file(bs)) { in qcow2_snapshot_delete()
923 snapshot_index = find_snapshot_by_id_and_name(bs, snapshot_id, name); in qcow2_snapshot_delete()
930 ret = qcow2_validate_table(bs, sn.l1_table_offset, sn.l1_size, in qcow2_snapshot_delete()
942 ret = qcow2_write_snapshots(bs); in qcow2_snapshot_delete()
961 ret = qcow2_update_snapshot_refcount(bs, sn.l1_table_offset, in qcow2_snapshot_delete()
967 qcow2_free_clusters(bs, sn.l1_table_offset, sn.l1_size * L1E_SIZE, in qcow2_snapshot_delete()
971 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0); in qcow2_snapshot_delete()
981 qcow2_check_refcounts(bs, &result, 0); in qcow2_snapshot_delete()
987 int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) in qcow2_snapshot_list() argument
989 BDRVQcow2State *s = bs->opaque; in qcow2_snapshot_list()
994 if (has_data_file(bs)) { in qcow2_snapshot_list()
1020 int qcow2_snapshot_load_tmp(BlockDriverState *bs, in qcow2_snapshot_load_tmp() argument
1026 BDRVQcow2State *s = bs->opaque; in qcow2_snapshot_load_tmp()
1032 assert(bdrv_is_read_only(bs)); in qcow2_snapshot_load_tmp()
1035 snapshot_index = find_snapshot_by_id_and_name(bs, snapshot_id, name); in qcow2_snapshot_load_tmp()
1044 ret = qcow2_validate_table(bs, sn->l1_table_offset, sn->l1_size, in qcow2_snapshot_load_tmp()
1051 new_l1_table = qemu_try_blockalign(bs->file->bs, new_l1_bytes); in qcow2_snapshot_load_tmp()
1056 ret = bdrv_pread(bs->file, sn->l1_table_offset, new_l1_bytes, in qcow2_snapshot_load_tmp()