]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0031-PVE-various-PBS-fixes.patch
backup: add patch to initialize bcs bitmap early enough for PBS
[pve-qemu.git] / debian / patches / pve / 0031-PVE-various-PBS-fixes.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Dietmar Maurer <dietmar@proxmox.com>
3 Date: Thu, 9 Jul 2020 12:53:08 +0200
4 Subject: [PATCH] PVE: various PBS fixes
5
6 pbs: fix crypt and compress parameters
7 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
8
9 PVE: handle PBS write callback with big blocks correctly
10 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
11
12 PVE: add zero block handling to PBS dump callback
13 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
14 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
15 ---
16 block/monitor/block-hmp-cmds.c | 4 ++-
17 pve-backup.c | 59 ++++++++++++++++++++++++++--------
18 qapi/block-core.json | 6 ++++
19 3 files changed, 55 insertions(+), 14 deletions(-)
20
21 diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
22 index 3c06734e6d..4481b60a5c 100644
23 --- a/block/monitor/block-hmp-cmds.c
24 +++ b/block/monitor/block-hmp-cmds.c
25 @@ -1042,7 +1042,9 @@ void hmp_backup(Monitor *mon, const QDict *qdict)
26 false, NULL, // PBS fingerprint
27 false, NULL, // PBS backup-id
28 false, 0, // PBS backup-time
29 - false, false, // PBS incremental
30 + false, false, // PBS use-dirty-bitmap
31 + false, false, // PBS compress
32 + false, false, // PBS encrypt
33 true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
34 false, NULL, false, NULL, !!devlist,
35 devlist, qdict_haskey(qdict, "speed"), speed, &error);
36 diff --git a/pve-backup.c b/pve-backup.c
37 index 1c49cd178d..c15abefdda 100644
38 --- a/pve-backup.c
39 +++ b/pve-backup.c
40 @@ -8,6 +8,7 @@
41 #include "block/blockjob.h"
42 #include "qapi/qapi-commands-block.h"
43 #include "qapi/qmp/qerror.h"
44 +#include "qemu/cutils.h"
45
46 /* PVE backup state and related function */
47
48 @@ -67,6 +68,7 @@ opts_init(pvebackup_init);
49 typedef struct PVEBackupDevInfo {
50 BlockDriverState *bs;
51 size_t size;
52 + uint64_t block_size;
53 uint8_t dev_id;
54 bool completed;
55 char targetfile[PATH_MAX];
56 @@ -135,10 +137,13 @@ pvebackup_co_dump_pbs_cb(
57 PVEBackupDevInfo *di = opaque;
58
59 assert(backup_state.pbs);
60 + assert(buf);
61
62 Error *local_err = NULL;
63 int pbs_res = -1;
64
65 + bool is_zero_block = size == di->block_size && buffer_is_zero(buf, size);
66 +
67 qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
68
69 // avoid deadlock if job is cancelled
70 @@ -147,16 +152,28 @@ pvebackup_co_dump_pbs_cb(
71 return -1;
72 }
73
74 - pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
75 + uint64_t transferred = 0;
76 + uint64_t reused = 0;
77 + while (transferred < size) {
78 + uint64_t left = size - transferred;
79 + uint64_t to_transfer = left < di->block_size ? left : di->block_size;
80 +
81 + pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id,
82 + is_zero_block ? NULL : buf + transferred, start + transferred,
83 + to_transfer, &local_err);
84 + transferred += to_transfer;
85 +
86 + if (pbs_res < 0) {
87 + pvebackup_propagate_error(local_err);
88 + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
89 + return pbs_res;
90 + }
91 +
92 + reused += pbs_res == 0 ? to_transfer : 0;
93 + }
94 +
95 qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
96 -
97 - if (pbs_res < 0) {
98 - pvebackup_propagate_error(local_err);
99 - return pbs_res;
100 - } else {
101 - size_t reused = (pbs_res == 0) ? size : 0;
102 - pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
103 - }
104 + pvebackup_add_transfered_bytes(size, is_zero_block ? size : 0, reused);
105
106 return size;
107 }
108 @@ -178,6 +195,7 @@ pvebackup_co_dump_vma_cb(
109 int ret = -1;
110
111 assert(backup_state.vmaw);
112 + assert(buf);
113
114 uint64_t remaining = size;
115
116 @@ -204,9 +222,7 @@ pvebackup_co_dump_vma_cb(
117 qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
118
119 ++cluster_num;
120 - if (buf) {
121 - buf += VMA_CLUSTER_SIZE;
122 - }
123 + buf += VMA_CLUSTER_SIZE;
124 if (ret < 0) {
125 Error *local_err = NULL;
126 vma_writer_error_propagate(backup_state.vmaw, &local_err);
127 @@ -569,6 +585,10 @@ typedef struct QmpBackupTask {
128 const char *firewall_file;
129 bool has_devlist;
130 const char *devlist;
131 + bool has_compress;
132 + bool compress;
133 + bool has_encrypt;
134 + bool encrypt;
135 bool has_speed;
136 int64_t speed;
137 Error **errp;
138 @@ -692,6 +712,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
139
140 bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
141
142 +
143 char *pbs_err = NULL;
144 pbs = proxmox_backup_new(
145 task->backup_file,
146 @@ -701,8 +722,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
147 task->has_password ? task->password : NULL,
148 task->has_keyfile ? task->keyfile : NULL,
149 task->has_key_password ? task->key_password : NULL,
150 + task->has_compress ? task->compress : true,
151 + task->has_encrypt ? task->encrypt : task->has_keyfile,
152 task->has_fingerprint ? task->fingerprint : NULL,
153 - &pbs_err);
154 + &pbs_err);
155
156 if (!pbs) {
157 error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
158 @@ -721,6 +744,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
159 PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
160 l = g_list_next(l);
161
162 + di->block_size = dump_cb_block_size;
163 +
164 const char *devname = bdrv_get_device_name(di->bs);
165
166 BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
167 @@ -941,6 +966,8 @@ UuidInfo *qmp_backup(
168 bool has_backup_id, const char *backup_id,
169 bool has_backup_time, int64_t backup_time,
170 bool has_use_dirty_bitmap, bool use_dirty_bitmap,
171 + bool has_compress, bool compress,
172 + bool has_encrypt, bool encrypt,
173 bool has_format, BackupFormat format,
174 bool has_config_file, const char *config_file,
175 bool has_firewall_file, const char *firewall_file,
176 @@ -951,6 +978,8 @@ UuidInfo *qmp_backup(
177 .backup_file = backup_file,
178 .has_password = has_password,
179 .password = password,
180 + .has_keyfile = has_keyfile,
181 + .keyfile = keyfile,
182 .has_key_password = has_key_password,
183 .key_password = key_password,
184 .has_fingerprint = has_fingerprint,
185 @@ -961,6 +990,10 @@ UuidInfo *qmp_backup(
186 .backup_time = backup_time,
187 .has_use_dirty_bitmap = has_use_dirty_bitmap,
188 .use_dirty_bitmap = use_dirty_bitmap,
189 + .has_compress = has_compress,
190 + .compress = compress,
191 + .has_encrypt = has_encrypt,
192 + .encrypt = encrypt,
193 .has_format = has_format,
194 .format = format,
195 .has_config_file = has_config_file,
196 diff --git a/qapi/block-core.json b/qapi/block-core.json
197 index 379a8dd147..88835ebcf6 100644
198 --- a/qapi/block-core.json
199 +++ b/qapi/block-core.json
200 @@ -822,6 +822,10 @@
201 #
202 # @use-dirty-bitmap: use dirty bitmap to detect incremental changes since last job (optional for format 'pbs')
203 #
204 +# @compress: use compression (optional for format 'pbs', defaults to true)
205 +#
206 +# @encrypt: use encryption ((optional for format 'pbs', defaults to true if there is a keyfile)
207 +#
208 # Returns: the uuid of the backup job
209 #
210 ##
211 @@ -833,6 +837,8 @@
212 '*backup-id': 'str',
213 '*backup-time': 'int',
214 '*use-dirty-bitmap': 'bool',
215 + '*compress': 'bool',
216 + '*encrypt': 'bool',
217 '*format': 'BackupFormat',
218 '*config-file': 'str',
219 '*firewall-file': 'str',