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