]>
Commit | Line | Data |
---|---|---|
0c893fd8 SR |
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> | |
ddbf7a87 | 14 | Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> |
0c893fd8 SR |
15 | --- |
16 | block/monitor/block-hmp-cmds.c | 4 ++- | |
4fd0fa7f | 17 | pve-backup.c | 57 +++++++++++++++++++++++++++------- |
0c893fd8 | 18 | qapi/block-core.json | 6 ++++ |
4fd0fa7f | 19 | 3 files changed, 54 insertions(+), 13 deletions(-) |
0c893fd8 SR |
20 | |
21 | diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c | |
dc9827a6 | 22 | index 45da74d7a0..ea7b665aa2 100644 |
0c893fd8 SR |
23 | --- a/block/monitor/block-hmp-cmds.c |
24 | +++ b/block/monitor/block-hmp-cmds.c | |
f376b2b9 | 25 | @@ -1042,7 +1042,9 @@ void hmp_backup(Monitor *mon, const QDict *qdict) |
0c893fd8 SR |
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 | |
4567474e | 37 | index 1c49cd178d..c15abefdda 100644 |
0c893fd8 SR |
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 | |
4fd0fa7f | 70 | @@ -147,17 +152,29 @@ pvebackup_co_dump_pbs_cb( |
0c893fd8 SR |
71 | return -1; |
72 | } | |
73 | ||
74 | - pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err); | |
4fd0fa7f | 75 | - qemu_co_mutex_unlock(&backup_state.dump_callback_mutex); |
0c893fd8 SR |
76 | + uint64_t transferred = 0; |
77 | + uint64_t reused = 0; | |
78 | + while (transferred < size) { | |
79 | + uint64_t left = size - transferred; | |
80 | + uint64_t to_transfer = left < di->block_size ? left : di->block_size; | |
4fd0fa7f TL |
81 | |
82 | - if (pbs_res < 0) { | |
83 | - pvebackup_propagate_error(local_err); | |
84 | - return pbs_res; | |
85 | - } else { | |
86 | - size_t reused = (pbs_res == 0) ? size : 0; | |
87 | - pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused); | |
0c893fd8 SR |
88 | + pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, |
89 | + is_zero_block ? NULL : buf + transferred, start + transferred, | |
90 | + to_transfer, &local_err); | |
91 | + transferred += to_transfer; | |
92 | + | |
93 | + if (pbs_res < 0) { | |
94 | + pvebackup_propagate_error(local_err); | |
95 | + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex); | |
96 | + return pbs_res; | |
97 | + } | |
98 | + | |
99 | + reused += pbs_res == 0 ? to_transfer : 0; | |
4fd0fa7f | 100 | } |
ddbf7a87 | 101 | |
4fd0fa7f TL |
102 | + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex); |
103 | + pvebackup_add_transfered_bytes(size, is_zero_block ? size : 0, reused); | |
104 | + | |
0c893fd8 SR |
105 | return size; |
106 | } | |
4fd0fa7f | 107 | |
0c893fd8 SR |
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); | |
8dca018b | 127 | @@ -569,6 +585,10 @@ typedef struct QmpBackupTask { |
0c893fd8 SR |
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; | |
8dca018b | 138 | @@ -692,6 +712,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque) |
0c893fd8 SR |
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, | |
8dca018b | 146 | @@ -701,8 +722,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque) |
0c893fd8 SR |
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, | |
8dca018b | 158 | @@ -721,6 +744,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque) |
0c893fd8 SR |
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); | |
8dca018b | 167 | @@ -941,6 +966,8 @@ UuidInfo *qmp_backup( |
0c893fd8 SR |
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, | |
8dca018b | 176 | @@ -951,6 +978,8 @@ UuidInfo *qmp_backup( |
0c893fd8 SR |
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, | |
8dca018b | 185 | @@ -961,6 +990,10 @@ UuidInfo *qmp_backup( |
0c893fd8 SR |
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 | |
5b15e2ec | 197 | index 3ad9eb5d1a..4120052690 100644 |
0c893fd8 SR |
198 | --- a/qapi/block-core.json |
199 | +++ b/qapi/block-core.json | |
5b15e2ec | 200 | @@ -818,6 +818,10 @@ |
0c893fd8 SR |
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 | ## | |
5b15e2ec | 211 | @@ -829,6 +833,8 @@ |
0c893fd8 SR |
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', |