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