1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include "qemu/osdep.h"
24
25#include "sysemu/block-backend.h"
26#include "qemu/cutils.h"
27#include "block/block_int.h"
28
29static coroutine_fn int
30snapshot_access_co_preadv_part(BlockDriverState *bs,
31 int64_t offset, int64_t bytes,
32 QEMUIOVector *qiov, size_t qiov_offset,
33 BdrvRequestFlags flags)
34{
35 if (flags) {
36 return -ENOTSUP;
37 }
38
39 return bdrv_co_preadv_snapshot(bs->file, offset, bytes, qiov, qiov_offset);
40}
41
42static int coroutine_fn
43snapshot_access_co_block_status(BlockDriverState *bs,
44 bool want_zero, int64_t offset,
45 int64_t bytes, int64_t *pnum,
46 int64_t *map, BlockDriverState **file)
47{
48 return bdrv_co_snapshot_block_status(bs->file->bs, want_zero, offset,
49 bytes, pnum, map, file);
50}
51
52static int coroutine_fn snapshot_access_co_pdiscard(BlockDriverState *bs,
53 int64_t offset, int64_t bytes)
54{
55 return bdrv_co_pdiscard_snapshot(bs->file->bs, offset, bytes);
56}
57
58static int coroutine_fn
59snapshot_access_co_pwrite_zeroes(BlockDriverState *bs,
60 int64_t offset, int64_t bytes,
61 BdrvRequestFlags flags)
62{
63 return -ENOTSUP;
64}
65
66static coroutine_fn int
67snapshot_access_co_pwritev_part(BlockDriverState *bs,
68 int64_t offset, int64_t bytes,
69 QEMUIOVector *qiov, size_t qiov_offset,
70 BdrvRequestFlags flags)
71{
72 return -ENOTSUP;
73}
74
75
76static void snapshot_access_refresh_filename(BlockDriverState *bs)
77{
78 pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
79 bs->file->bs->filename);
80}
81
82static int snapshot_access_open(BlockDriverState *bs, QDict *options, int flags,
83 Error **errp)
84{
85 bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
86 BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY,
87 false, errp);
88 if (!bs->file) {
89 return -EINVAL;
90 }
91
92 bs->total_sectors = bs->file->bs->total_sectors;
93
94 return 0;
95}
96
97static void snapshot_access_child_perm(BlockDriverState *bs, BdrvChild *c,
98 BdrvChildRole role,
99 BlockReopenQueue *reopen_queue,
100 uint64_t perm, uint64_t shared,
101 uint64_t *nperm, uint64_t *nshared)
102{
103
104
105
106
107 *nperm = 0;
108 *nshared = BLK_PERM_ALL;
109}
110
111BlockDriver bdrv_snapshot_access_drv = {
112 .format_name = "snapshot-access",
113
114 .bdrv_open = snapshot_access_open,
115
116 .bdrv_co_preadv_part = snapshot_access_co_preadv_part,
117 .bdrv_co_pwritev_part = snapshot_access_co_pwritev_part,
118 .bdrv_co_pwrite_zeroes = snapshot_access_co_pwrite_zeroes,
119 .bdrv_co_pdiscard = snapshot_access_co_pdiscard,
120 .bdrv_co_block_status = snapshot_access_co_block_status,
121
122 .bdrv_refresh_filename = snapshot_access_refresh_filename,
123
124 .bdrv_child_perm = snapshot_access_child_perm,
125};
126
127static void snapshot_access_init(void)
128{
129 bdrv_register(&bdrv_snapshot_access_drv);
130}
131
132block_init(snapshot_access_init);
133