]> git.proxmox.com Git - pve-qemu.git/blame - debian/patches/pve/0032-PVE-various-PBS-fixes.patch
add stable patches for 8.0.0
[pve-qemu.git] / debian / patches / pve / 0032-PVE-various-PBS-fixes.patch
CommitLineData
0c893fd8
SR
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Dietmar Maurer <dietmar@proxmox.com>
3Date: Thu, 9 Jul 2020 12:53:08 +0200
4Subject: [PATCH] PVE: various PBS fixes
5
6pbs: fix crypt and compress parameters
7Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
8
9PVE: handle PBS write callback with big blocks correctly
10Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
11
12PVE: add zero block handling to PBS dump callback
13Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
ddbf7a87 14Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
bf251437
FE
15[FE: adapt to QAPI change dropping redundant has_*]
16Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
0c893fd8
SR
17---
18 block/monitor/block-hmp-cmds.c | 4 ++-
bf251437 19 pve-backup.c | 54 +++++++++++++++++++++++++++-------
0c893fd8 20 qapi/block-core.json | 6 ++++
bf251437 21 3 files changed, 52 insertions(+), 12 deletions(-)
0c893fd8
SR
22
23diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
53b56ca7 24index cda5de792b..ecbebd39ac 100644
0c893fd8
SR
25--- a/block/monitor/block-hmp-cmds.c
26+++ b/block/monitor/block-hmp-cmds.c
53b56ca7 27@@ -1056,7 +1056,9 @@ void hmp_backup(Monitor *mon, const QDict *qdict)
bf251437
FE
28 NULL, // PBS fingerprint
29 NULL, // PBS backup-id
0c893fd8
SR
30 false, 0, // PBS backup-time
31- false, false, // PBS incremental
32+ false, false, // PBS use-dirty-bitmap
33+ false, false, // PBS compress
34+ false, false, // PBS encrypt
35 true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
bf251437 36 NULL, NULL,
0c893fd8
SR
37 devlist, qdict_haskey(qdict, "speed"), speed, &error);
38diff --git a/pve-backup.c b/pve-backup.c
53b56ca7 39index c4cbff7fb1..95f742e1d1 100644
0c893fd8
SR
40--- a/pve-backup.c
41+++ b/pve-backup.c
bf251437
FE
42@@ -10,6 +10,7 @@
43 #include "block/dirty-bitmap.h"
0c893fd8
SR
44 #include "qapi/qapi-commands-block.h"
45 #include "qapi/qmp/qerror.h"
46+#include "qemu/cutils.h"
47
48 /* PVE backup state and related function */
49
bf251437 50@@ -69,6 +70,7 @@ opts_init(pvebackup_init);
0c893fd8
SR
51 typedef struct PVEBackupDevInfo {
52 BlockDriverState *bs;
53 size_t size;
54+ uint64_t block_size;
55 uint8_t dev_id;
56 bool completed;
57 char targetfile[PATH_MAX];
bf251437 58@@ -139,10 +141,13 @@ pvebackup_co_dump_pbs_cb(
0c893fd8
SR
59 PVEBackupDevInfo *di = opaque;
60
61 assert(backup_state.pbs);
62+ assert(buf);
63
64 Error *local_err = NULL;
65 int pbs_res = -1;
66
67+ bool is_zero_block = size == di->block_size && buffer_is_zero(buf, size);
68+
69 qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
70
71 // avoid deadlock if job is cancelled
bf251437 72@@ -151,17 +156,29 @@ pvebackup_co_dump_pbs_cb(
0c893fd8
SR
73 return -1;
74 }
75
76- pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
4fd0fa7f 77- qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
0c893fd8
SR
78+ uint64_t transferred = 0;
79+ uint64_t reused = 0;
80+ while (transferred < size) {
81+ uint64_t left = size - transferred;
82+ uint64_t to_transfer = left < di->block_size ? left : di->block_size;
4fd0fa7f
TL
83
84- if (pbs_res < 0) {
85- pvebackup_propagate_error(local_err);
86- return pbs_res;
87- } else {
88- size_t reused = (pbs_res == 0) ? size : 0;
89- pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
0c893fd8
SR
90+ pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id,
91+ is_zero_block ? NULL : buf + transferred, start + transferred,
92+ to_transfer, &local_err);
93+ transferred += to_transfer;
94+
95+ if (pbs_res < 0) {
96+ pvebackup_propagate_error(local_err);
97+ qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
98+ return pbs_res;
99+ }
100+
101+ reused += pbs_res == 0 ? to_transfer : 0;
4fd0fa7f 102 }
ddbf7a87 103
4fd0fa7f
TL
104+ qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
105+ pvebackup_add_transfered_bytes(size, is_zero_block ? size : 0, reused);
106+
0c893fd8
SR
107 return size;
108 }
4fd0fa7f 109
bf251437 110@@ -182,6 +199,7 @@ pvebackup_co_dump_vma_cb(
0c893fd8
SR
111 int ret = -1;
112
113 assert(backup_state.vmaw);
114+ assert(buf);
115
116 uint64_t remaining = size;
117
bf251437 118@@ -208,9 +226,7 @@ pvebackup_co_dump_vma_cb(
0c893fd8
SR
119 qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
120
121 ++cluster_num;
122- if (buf) {
123- buf += VMA_CLUSTER_SIZE;
124- }
125+ buf += VMA_CLUSTER_SIZE;
126 if (ret < 0) {
127 Error *local_err = NULL;
128 vma_writer_error_propagate(backup_state.vmaw, &local_err);
bf251437
FE
129@@ -560,6 +576,10 @@ typedef struct QmpBackupTask {
130 const char *config_file;
0c893fd8 131 const char *firewall_file;
0c893fd8
SR
132 const char *devlist;
133+ bool has_compress;
134+ bool compress;
135+ bool has_encrypt;
136+ bool encrypt;
137 bool has_speed;
138 int64_t speed;
139 Error **errp;
bf251437 140@@ -683,6 +703,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
0c893fd8
SR
141
142 bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
143
144+
145 char *pbs_err = NULL;
146 pbs = proxmox_backup_new(
147 task->backup_file,
bf251437
FE
148@@ -692,6 +713,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
149 task->password,
150 task->keyfile,
151 task->key_password,
0c893fd8 152+ task->has_compress ? task->compress : true,
bf251437
FE
153+ task->has_encrypt ? task->encrypt : !!task->keyfile,
154 task->fingerprint,
155 &pbs_err);
156
157@@ -712,6 +735,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
0c893fd8
SR
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);
bf251437
FE
166@@ -932,6 +957,8 @@ UuidInfo *qmp_backup(
167 const char *backup_id,
0c893fd8
SR
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,
bf251437
FE
173 const char *config_file,
174 const char *firewall_file,
175@@ -941,6 +968,7 @@ UuidInfo *qmp_backup(
176 QmpBackupTask task = {
0c893fd8 177 .backup_file = backup_file,
0c893fd8 178 .password = password,
0c893fd8 179+ .keyfile = keyfile,
0c893fd8 180 .key_password = key_password,
bf251437
FE
181 .fingerprint = fingerprint,
182 .backup_id = backup_id,
183@@ -948,6 +976,10 @@ UuidInfo *qmp_backup(
0c893fd8
SR
184 .backup_time = backup_time,
185 .has_use_dirty_bitmap = has_use_dirty_bitmap,
186 .use_dirty_bitmap = use_dirty_bitmap,
187+ .has_compress = has_compress,
188+ .compress = compress,
189+ .has_encrypt = has_encrypt,
190+ .encrypt = encrypt,
191 .has_format = has_format,
192 .format = format,
bf251437 193 .config_file = config_file,
0c893fd8 194diff --git a/qapi/block-core.json b/qapi/block-core.json
bf251437 195index 92f90a898a..864b8ce97c 100644
0c893fd8
SR
196--- a/qapi/block-core.json
197+++ b/qapi/block-core.json
bf251437 198@@ -913,6 +913,10 @@
0c893fd8
SR
199 #
200 # @use-dirty-bitmap: use dirty bitmap to detect incremental changes since last job (optional for format 'pbs')
201 #
202+# @compress: use compression (optional for format 'pbs', defaults to true)
203+#
204+# @encrypt: use encryption ((optional for format 'pbs', defaults to true if there is a keyfile)
205+#
206 # Returns: the uuid of the backup job
207 #
208 ##
bf251437 209@@ -924,6 +928,8 @@
0c893fd8
SR
210 '*backup-id': 'str',
211 '*backup-time': 'int',
212 '*use-dirty-bitmap': 'bool',
213+ '*compress': 'bool',
214+ '*encrypt': 'bool',
215 '*format': 'BackupFormat',
216 '*config-file': 'str',
217 '*firewall-file': 'str',