]> git.proxmox.com Git - pve-qemu.git/blame - debian/patches/pve/0017-PVE-add-optional-buffer-size-to-QEMUFile.patch
savevm-async: set SAVE_STATE_DONE when closing state file was successful
[pve-qemu.git] / debian / patches / pve / 0017-PVE-add-optional-buffer-size-to-QEMUFile.patch
CommitLineData
abc9e57f
WB
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3Date: Mon, 4 May 2020 11:05:08 +0200
817b7667 4Subject: [PATCH] PVE: add optional buffer size to QEMUFile
abc9e57f
WB
5
6So we can use a 4M buffer for savevm-async which should
7increase performance storing the state onto ceph.
8
9Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
817b7667
SR
10[increase max IOV count in QEMUFile to actually write more data]
11Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
ddbf7a87 12Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
abc9e57f 13---
817b7667
SR
14 migration/qemu-file.c | 38 +++++++++++++++++++++++++-------------
15 migration/qemu-file.h | 1 +
16 migration/savevm-async.c | 4 ++--
17 3 files changed, 28 insertions(+), 15 deletions(-)
abc9e57f
WB
18
19diff --git a/migration/qemu-file.c b/migration/qemu-file.c
dc9827a6 20index 1479cddad9..21a3355ae2 100644
abc9e57f
WB
21--- a/migration/qemu-file.c
22+++ b/migration/qemu-file.c
dc9827a6 23@@ -31,8 +31,8 @@
abc9e57f
WB
24 #include "trace.h"
25 #include "qapi/error.h"
26
27-#define IO_BUF_SIZE 32768
817b7667 28-#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
abc9e57f 29+#define DEFAULT_IO_BUF_SIZE 32768
817b7667 30+#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 256)
abc9e57f
WB
31
32 struct QEMUFile {
817b7667 33 const QEMUFileOps *ops;
dc9827a6 34@@ -46,7 +46,8 @@ struct QEMUFile {
abc9e57f
WB
35 when reading */
36 int buf_index;
37 int buf_size; /* 0 when writing */
38- uint8_t buf[IO_BUF_SIZE];
39+ size_t buf_allocated_size;
40+ uint8_t *buf;
41
42 DECLARE_BITMAP(may_free, MAX_IOV_SIZE);
43 struct iovec iov[MAX_IOV_SIZE];
dc9827a6 44@@ -104,7 +105,7 @@ bool qemu_file_mode_is_not_valid(const char *mode)
abc9e57f
WB
45 return false;
46 }
47
f376b2b9
SR
48-QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc)
49+QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, bool has_ioc, size_t buffer_size)
abc9e57f
WB
50 {
51 QEMUFile *f;
52
dc9827a6 53@@ -113,9 +114,17 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc)
abc9e57f
WB
54 f->opaque = opaque;
55 f->ops = ops;
f376b2b9 56 f->has_ioc = has_ioc;
abc9e57f
WB
57+ f->buf_allocated_size = buffer_size;
58+ f->buf = malloc(buffer_size);
59+
60 return f;
61 }
62
f376b2b9 63+QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc)
abc9e57f 64+{
f376b2b9 65+ return qemu_fopen_ops_sized(opaque, ops, has_ioc, DEFAULT_IO_BUF_SIZE);
abc9e57f
WB
66+}
67+
68
69 void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks)
70 {
dc9827a6 71@@ -350,7 +359,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)
abc9e57f
WB
72 }
73
74 len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos,
75- IO_BUF_SIZE - pending, &local_error);
76+ f->buf_allocated_size - pending, &local_error);
77 if (len > 0) {
78 f->buf_size += len;
79 f->pos += len;
dc9827a6 80@@ -390,6 +399,9 @@ int qemu_fclose(QEMUFile *f)
abc9e57f
WB
81 ret = ret2;
82 }
83 }
84+
85+ free(f->buf);
86+
87 /* If any error was spotted before closing, we should report it
88 * instead of the close() return value.
89 */
dc9827a6 90@@ -444,7 +456,7 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len)
abc9e57f
WB
91 {
92 if (!add_to_iovec(f, f->buf + f->buf_index, len, false)) {
93 f->buf_index += len;
94- if (f->buf_index == IO_BUF_SIZE) {
95+ if (f->buf_index == f->buf_allocated_size) {
96 qemu_fflush(f);
97 }
98 }
dc9827a6 99@@ -470,7 +482,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size)
abc9e57f
WB
100 }
101
102 while (size > 0) {
103- l = IO_BUF_SIZE - f->buf_index;
104+ l = f->buf_allocated_size - f->buf_index;
105 if (l > size) {
106 l = size;
107 }
dc9827a6 108@@ -517,8 +529,8 @@ size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset)
abc9e57f
WB
109 size_t index;
110
111 assert(!qemu_file_is_writable(f));
112- assert(offset < IO_BUF_SIZE);
113- assert(size <= IO_BUF_SIZE - offset);
114+ assert(offset < f->buf_allocated_size);
115+ assert(size <= f->buf_allocated_size - offset);
116
117 /* The 1st byte to read from */
118 index = f->buf_index + offset;
dc9827a6 119@@ -568,7 +580,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size)
abc9e57f
WB
120 size_t res;
121 uint8_t *src;
122
123- res = qemu_peek_buffer(f, &src, MIN(pending, IO_BUF_SIZE), 0);
124+ res = qemu_peek_buffer(f, &src, MIN(pending, f->buf_allocated_size), 0);
125 if (res == 0) {
126 return done;
127 }
dc9827a6 128@@ -602,7 +614,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size)
abc9e57f
WB
129 */
130 size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
131 {
132- if (size < IO_BUF_SIZE) {
133+ if (size < f->buf_allocated_size) {
134 size_t res;
8dca018b 135 uint8_t *src = NULL;
abc9e57f 136
dc9827a6 137@@ -627,7 +639,7 @@ int qemu_peek_byte(QEMUFile *f, int offset)
abc9e57f
WB
138 int index = f->buf_index + offset;
139
140 assert(!qemu_file_is_writable(f));
141- assert(offset < IO_BUF_SIZE);
142+ assert(offset < f->buf_allocated_size);
143
144 if (index >= f->buf_size) {
145 qemu_fill_buffer(f);
dc9827a6 146@@ -779,7 +791,7 @@ static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest_len,
abc9e57f
WB
147 ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
148 const uint8_t *p, size_t size)
149 {
150- ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);
151+ ssize_t blen = f->buf_allocated_size - f->buf_index - sizeof(int32_t);
152
153 if (blen < compressBound(size)) {
154 return -1;
155diff --git a/migration/qemu-file.h b/migration/qemu-file.h
f376b2b9 156index 3f36d4dc8c..67501fd9cf 100644
abc9e57f
WB
157--- a/migration/qemu-file.h
158+++ b/migration/qemu-file.h
f376b2b9 159@@ -121,6 +121,7 @@ typedef struct QEMUFileHooks {
abc9e57f
WB
160 } QEMUFileHooks;
161
f376b2b9
SR
162 QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc);
163+QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, bool has_ioc, size_t buffer_size);
abc9e57f
WB
164 void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
165 int qemu_get_fd(QEMUFile *f);
166 int qemu_fclose(QEMUFile *f);
817b7667 167diff --git a/migration/savevm-async.c b/migration/savevm-async.c
1976ca46 168index b9a43c56bc..0bc5799cf8 100644
817b7667
SR
169--- a/migration/savevm-async.c
170+++ b/migration/savevm-async.c
1976ca46 171@@ -420,7 +420,7 @@ void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp)
abc9e57f
WB
172 goto restart;
173 }
174
175- snap_state.file = qemu_fopen_ops(&snap_state, &block_file_ops);
f376b2b9 176+ snap_state.file = qemu_fopen_ops_sized(&snap_state, &block_file_ops, false, 4 * 1024 * 1024);
abc9e57f
WB
177
178 if (!snap_state.file) {
179 error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile);
1976ca46 180@@ -573,7 +573,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp)
abc9e57f
WB
181 blk_op_block_all(be, blocker);
182
183 /* restore the VM state */
184- f = qemu_fopen_ops(be, &loadstate_file_ops);
f376b2b9 185+ f = qemu_fopen_ops_sized(be, &loadstate_file_ops, false, 4 * 1024 * 1024);
abc9e57f
WB
186 if (!f) {
187 error_setg(errp, "Could not open VM state file");
188 goto the_end;