]>
Commit | Line | Data |
---|---|---|
076b4026 | 1 | From 33ef64ee185389d97f7d4f695d68bc33054de671 Mon Sep 17 00:00:00 2001 |
95259824 WB |
2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> |
3 | Date: Wed, 9 Dec 2015 15:04:57 +0100 | |
45169293 | 4 | Subject: [PATCH 14/49] backup: modify job api |
95259824 WB |
5 | |
6 | Introduces a BackupDump function callback and a pause_count | |
7 | for backup_start. For a dump-backup the target parameter | |
8 | can now be NULL so access to target needs to be guarded now. | |
9 | --- | |
a544966d WB |
10 | block/backup.c | 118 +++++++++++++++++++++++++++++----------------- |
11 | block/replication.c | 3 +- | |
12 | blockdev.c | 4 +- | |
13 | include/block/block_int.h | 5 ++ | |
14 | 4 files changed, 83 insertions(+), 47 deletions(-) | |
95259824 WB |
15 | |
16 | diff --git a/block/backup.c b/block/backup.c | |
45169293 | 17 | index a4fb2884f9..fe4ce7f504 100644 |
95259824 WB |
18 | --- a/block/backup.c |
19 | +++ b/block/backup.c | |
a544966d | 20 | @@ -36,6 +36,7 @@ typedef struct BackupBlockJob { |
95259824 WB |
21 | BdrvDirtyBitmap *sync_bitmap; |
22 | MirrorSyncMode sync_mode; | |
23 | RateLimit limit; | |
24 | + BackupDumpFunc *dump_cb; | |
25 | BlockdevOnError on_source_error; | |
26 | BlockdevOnError on_target_error; | |
27 | CoRwlock flush_rwlock; | |
a544966d | 28 | @@ -145,13 +146,24 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, |
95259824 WB |
29 | goto out; |
30 | } | |
31 | ||
32 | + int64_t start_sec = start * sectors_per_cluster; | |
33 | if (buffer_is_zero(iov.iov_base, iov.iov_len)) { | |
34 | - ret = blk_co_pwrite_zeroes(job->target, start * job->cluster_size, | |
35 | - bounce_qiov.size, BDRV_REQ_MAY_UNMAP); | |
36 | + if (job->dump_cb) { | |
37 | + ret = job->dump_cb(job->common.opaque, job->target, start_sec, n, NULL); | |
38 | + } | |
39 | + if (job->target) { | |
40 | + ret = blk_co_pwrite_zeroes(job->target, start * job->cluster_size, | |
41 | + bounce_qiov.size, BDRV_REQ_MAY_UNMAP); | |
42 | + } | |
43 | } else { | |
44 | - ret = blk_co_pwritev(job->target, start * job->cluster_size, | |
a544966d WB |
45 | - bounce_qiov.size, &bounce_qiov, |
46 | - job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); | |
95259824 WB |
47 | + if (job->dump_cb) { |
48 | + ret = job->dump_cb(job->common.opaque, job->target, start_sec, n, bounce_buffer); | |
49 | + } | |
50 | + if (job->target) { | |
51 | + ret = blk_co_pwritev(job->target, start * job->cluster_size, | |
a544966d WB |
52 | + bounce_qiov.size, &bounce_qiov, |
53 | + job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); | |
95259824 WB |
54 | + } |
55 | } | |
56 | if (ret < 0) { | |
57 | trace_backup_do_cow_write_fail(job, start, ret); | |
a544966d WB |
58 | @@ -246,6 +258,8 @@ static void backup_abort(BlockJob *job) |
59 | static void backup_clean(BlockJob *job) | |
60 | { | |
61 | BackupBlockJob *s = container_of(job, BackupBlockJob, common); | |
62 | + if (!s->target) | |
63 | + return; | |
64 | assert(s->target); | |
65 | blk_unref(s->target); | |
66 | s->target = NULL; | |
67 | @@ -330,9 +344,11 @@ static BlockErrorAction backup_error_action(BackupBlockJob *job, | |
95259824 WB |
68 | if (read) { |
69 | return block_job_error_action(&job->common, job->on_source_error, | |
70 | true, error); | |
71 | - } else { | |
72 | + } else if (job->target) { | |
73 | return block_job_error_action(&job->common, job->on_target_error, | |
74 | false, error); | |
75 | + } else { | |
76 | + return BLOCK_ERROR_ACTION_REPORT; | |
77 | } | |
78 | } | |
79 | ||
a544966d | 80 | @@ -453,6 +469,7 @@ static void coroutine_fn backup_run(void *opaque) |
95259824 WB |
81 | |
82 | job->done_bitmap = bitmap_new(end); | |
83 | ||
84 | + | |
85 | job->before_write.notify = backup_before_write_notify; | |
86 | bdrv_add_before_write_notifier(bs, &job->before_write); | |
87 | ||
a544966d | 88 | @@ -557,7 +574,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, |
95259824 WB |
89 | BlockdevOnError on_source_error, |
90 | BlockdevOnError on_target_error, | |
a544966d | 91 | int creation_flags, |
95259824 WB |
92 | + BackupDumpFunc *dump_cb, |
93 | BlockCompletionFunc *cb, void *opaque, | |
94 | + int pause_count, | |
95 | BlockJobTxn *txn, Error **errp) | |
96 | { | |
97 | int64_t len; | |
a544966d | 98 | @@ -566,7 +585,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, |
95259824 WB |
99 | int ret; |
100 | ||
101 | assert(bs); | |
102 | - assert(target); | |
103 | + assert(target || dump_cb); | |
104 | ||
105 | if (bs == target) { | |
106 | error_setg(errp, "Source and target cannot be the same"); | |
a544966d WB |
107 | @@ -579,13 +598,13 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, |
108 | return NULL; | |
95259824 WB |
109 | } |
110 | ||
111 | - if (!bdrv_is_inserted(target)) { | |
112 | + if (target && !bdrv_is_inserted(target)) { | |
113 | error_setg(errp, "Device is not inserted: %s", | |
114 | bdrv_get_device_name(target)); | |
a544966d WB |
115 | return NULL; |
116 | } | |
117 | ||
118 | - if (compress && target->drv->bdrv_co_pwritev_compressed == NULL) { | |
119 | + if (target && compress && target->drv->bdrv_co_pwritev_compressed == NULL) { | |
120 | error_setg(errp, "Compression is not supported for this drive %s", | |
121 | bdrv_get_device_name(target)); | |
122 | return NULL; | |
123 | @@ -595,7 +614,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, | |
124 | return NULL; | |
95259824 WB |
125 | } |
126 | ||
127 | - if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) { | |
128 | + if (target && bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) { | |
a544966d | 129 | return NULL; |
95259824 WB |
130 | } |
131 | ||
a544966d | 132 | @@ -635,15 +654,18 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, |
95259824 WB |
133 | goto error; |
134 | } | |
135 | ||
a544966d WB |
136 | - /* The target must match the source in size, so no resize here either */ |
137 | - job->target = blk_new(BLK_PERM_WRITE, | |
138 | - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | | |
139 | - BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD); | |
140 | - ret = blk_insert_bs(job->target, target, errp); | |
141 | - if (ret < 0) { | |
142 | - goto error; | |
95259824 | 143 | + if (target) { |
a544966d WB |
144 | + /* The target must match the source in size, so no resize here either */ |
145 | + job->target = blk_new(BLK_PERM_WRITE, | |
146 | + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | | |
147 | + BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD); | |
148 | + ret = blk_insert_bs(job->target, target, errp); | |
149 | + if (ret < 0) { | |
150 | + goto error; | |
151 | + } | |
152 | } | |
95259824 WB |
153 | |
154 | + job->dump_cb = dump_cb; | |
155 | job->on_source_error = on_source_error; | |
156 | job->on_target_error = on_target_error; | |
157 | job->sync_mode = sync_mode; | |
a544966d | 158 | @@ -651,36 +673,44 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, |
95259824 | 159 | sync_bitmap : NULL; |
a544966d | 160 | job->compress = compress; |
95259824 WB |
161 | |
162 | - /* If there is no backing file on the target, we cannot rely on COW if our | |
163 | - * backup cluster size is smaller than the target cluster size. Even for | |
164 | - * targets with a backing file, try to avoid COW if possible. */ | |
165 | - ret = bdrv_get_info(target, &bdi); | |
a544966d WB |
166 | - if (ret == -ENOTSUP && !target->backing) { |
167 | - /* Cluster size is not defined */ | |
168 | - error_report("WARNING: The target block device doesn't provide " | |
169 | - "information about the block size and it doesn't have a " | |
170 | - "backing file. The default block size of %u bytes is " | |
171 | - "used. If the actual block size of the target exceeds " | |
172 | - "this default, the backup may be unusable", | |
173 | - BACKUP_CLUSTER_SIZE_DEFAULT); | |
174 | - job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; | |
175 | - } else if (ret < 0 && !target->backing) { | |
95259824 WB |
176 | - error_setg_errno(errp, -ret, |
177 | - "Couldn't determine the cluster size of the target image, " | |
178 | - "which has no backing file"); | |
179 | - error_append_hint(errp, | |
180 | - "Aborting, since this may create an unusable destination image\n"); | |
181 | - goto error; | |
182 | - } else if (ret < 0 && target->backing) { | |
183 | - /* Not fatal; just trudge on ahead. */ | |
184 | - job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; | |
185 | + if (target) { | |
186 | + /* If there is no backing file on the target, we cannot rely on COW if our | |
187 | + * backup cluster size is smaller than the target cluster size. Even for | |
188 | + * targets with a backing file, try to avoid COW if possible. */ | |
189 | + ret = bdrv_get_info(target, &bdi); | |
a544966d WB |
190 | + if (ret == -ENOTSUP && !target->backing) { |
191 | + /* Cluster size is not defined */ | |
192 | + error_report("WARNING: The target block device doesn't provide " | |
193 | + "information about the block size and it doesn't have a " | |
194 | + "backing file. The default block size of %u bytes is " | |
195 | + "used. If the actual block size of the target exceeds " | |
196 | + "this default, the backup may be unusable", | |
197 | + BACKUP_CLUSTER_SIZE_DEFAULT); | |
198 | + job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; | |
199 | + } else if (ret < 0 && !target->backing) { | |
95259824 WB |
200 | + error_setg_errno(errp, -ret, |
201 | + "Couldn't determine the cluster size of the target image, " | |
202 | + "which has no backing file"); | |
203 | + error_append_hint(errp, | |
204 | + "Aborting, since this may create an unusable destination image\n"); | |
205 | + goto error; | |
206 | + } else if (ret < 0 && target->backing) { | |
207 | + /* Not fatal; just trudge on ahead. */ | |
208 | + job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; | |
209 | + } else { | |
a544966d | 210 | + job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; |
95259824 | 211 | + } |
95259824 WB |
212 | } else { |
213 | - job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size); | |
214 | + job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; | |
215 | } | |
216 | ||
a544966d WB |
217 | - /* Required permissions are already taken with target's blk_new() */ |
218 | - block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, | |
219 | - &error_abort); | |
220 | + if (target) { | |
221 | + /* Required permissions are already taken with target's blk_new() */ | |
222 | + block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, | |
223 | + &error_abort); | |
224 | + } else { | |
225 | + job->common.pause_count = pause_count; | |
226 | + } | |
95259824 | 227 | job->common.len = len; |
95259824 | 228 | block_job_txn_add_job(txn, &job->common); |
a544966d WB |
229 | |
230 | diff --git a/block/replication.c b/block/replication.c | |
45169293 | 231 | index bf3c395eb4..60c6524417 100644 |
a544966d WB |
232 | --- a/block/replication.c |
233 | +++ b/block/replication.c | |
234 | @@ -531,7 +531,8 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, | |
235 | 0, MIRROR_SYNC_MODE_NONE, NULL, false, | |
236 | BLOCKDEV_ON_ERROR_REPORT, | |
237 | BLOCKDEV_ON_ERROR_REPORT, BLOCK_JOB_INTERNAL, | |
238 | - backup_job_completed, bs, NULL, &local_err); | |
239 | + NULL, | |
240 | + backup_job_completed, bs, 0, NULL, &local_err); | |
241 | if (local_err) { | |
242 | error_propagate(errp, local_err); | |
243 | backup_job_cleanup(bs); | |
95259824 | 244 | diff --git a/blockdev.c b/blockdev.c |
076b4026 | 245 | index 4927914ce3..5ddd363a33 100644 |
95259824 WB |
246 | --- a/blockdev.c |
247 | +++ b/blockdev.c | |
a544966d WB |
248 | @@ -3273,7 +3273,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn, |
249 | job = backup_job_create(backup->job_id, bs, target_bs, backup->speed, | |
250 | backup->sync, bmap, backup->compress, | |
251 | backup->on_source_error, backup->on_target_error, | |
252 | - BLOCK_JOB_DEFAULT, NULL, NULL, txn, &local_err); | |
253 | + BLOCK_JOB_DEFAULT, NULL, NULL, NULL, 0, txn, &local_err); | |
95259824 WB |
254 | bdrv_unref(target_bs); |
255 | if (local_err != NULL) { | |
256 | error_propagate(errp, local_err); | |
a544966d WB |
257 | @@ -3352,7 +3352,7 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, |
258 | job = backup_job_create(backup->job_id, bs, target_bs, backup->speed, | |
259 | backup->sync, NULL, backup->compress, | |
260 | backup->on_source_error, backup->on_target_error, | |
261 | - BLOCK_JOB_DEFAULT, NULL, NULL, txn, &local_err); | |
262 | + BLOCK_JOB_DEFAULT, NULL, NULL, NULL, 0, txn, &local_err); | |
95259824 WB |
263 | if (local_err != NULL) { |
264 | error_propagate(errp, local_err); | |
265 | } | |
266 | diff --git a/include/block/block_int.h b/include/block/block_int.h | |
45169293 | 267 | index 59400bd848..ec655815ca 100644 |
95259824 WB |
268 | --- a/include/block/block_int.h |
269 | +++ b/include/block/block_int.h | |
270 | @@ -59,6 +59,9 @@ | |
271 | ||
272 | #define BLOCK_PROBE_BUF_SIZE 512 | |
273 | ||
274 | +typedef int BackupDumpFunc(void *opaque, BlockDriverState *bs, | |
275 | + int64_t sector_num, int n_sectors, unsigned char *buf); | |
276 | + | |
277 | enum BdrvTrackedRequestType { | |
278 | BDRV_TRACKED_READ, | |
279 | BDRV_TRACKED_WRITE, | |
a544966d WB |
280 | @@ -877,7 +880,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, |
281 | BlockdevOnError on_source_error, | |
282 | BlockdevOnError on_target_error, | |
283 | int creation_flags, | |
284 | + BackupDumpFunc *dump_cb, | |
285 | BlockCompletionFunc *cb, void *opaque, | |
286 | + int pause_count, | |
287 | BlockJobTxn *txn, Error **errp); | |
95259824 WB |
288 | |
289 | void hmp_drive_add_node(Monitor *mon, const char *optstr); | |
290 | -- | |
45169293 | 291 | 2.11.0 |
95259824 | 292 |