]> git.proxmox.com Git - pve-qemu.git/blame - debian/patches/pve/0018-add-optional-buffer-size-to-QEMUFile.patch
fix #3084: fall back to open-iscsi initiatorname
[pve-qemu.git] / debian / patches / pve / 0018-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
4Subject: [PATCH] add optional buffer size to QEMUFile
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>
10---
11 migration/qemu-file.c | 36 ++++++++++++++++++++++++------------
12 migration/qemu-file.h | 1 +
13 savevm-async.c | 4 ++--
14 3 files changed, 27 insertions(+), 14 deletions(-)
15
16diff --git a/migration/qemu-file.c b/migration/qemu-file.c
60ae3775 17index be21518c57..a4d2e2c8ff 100644
abc9e57f
WB
18--- a/migration/qemu-file.c
19+++ b/migration/qemu-file.c
20@@ -30,7 +30,7 @@
21 #include "trace.h"
22 #include "qapi/error.h"
23
24-#define IO_BUF_SIZE 32768
25+#define DEFAULT_IO_BUF_SIZE 32768
60ae3775 26 #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
abc9e57f
WB
27
28 struct QEMUFile {
29@@ -45,7 +45,8 @@ struct QEMUFile {
30 when reading */
31 int buf_index;
32 int buf_size; /* 0 when writing */
33- uint8_t buf[IO_BUF_SIZE];
34+ size_t buf_allocated_size;
35+ uint8_t *buf;
36
37 DECLARE_BITMAP(may_free, MAX_IOV_SIZE);
38 struct iovec iov[MAX_IOV_SIZE];
39@@ -101,7 +102,7 @@ bool qemu_file_mode_is_not_valid(const char *mode)
40 return false;
41 }
42
43-QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops)
44+QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, size_t buffer_size)
45 {
46 QEMUFile *f;
47
48@@ -109,9 +110,17 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops)
49
50 f->opaque = opaque;
51 f->ops = ops;
52+ f->buf_allocated_size = buffer_size;
53+ f->buf = malloc(buffer_size);
54+
55 return f;
56 }
57
58+QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops)
59+{
60+ return qemu_fopen_ops_sized(opaque, ops, DEFAULT_IO_BUF_SIZE);
61+}
62+
63
64 void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks)
65 {
66@@ -346,7 +355,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)
67 }
68
69 len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos,
70- IO_BUF_SIZE - pending, &local_error);
71+ f->buf_allocated_size - pending, &local_error);
72 if (len > 0) {
73 f->buf_size += len;
74 f->pos += len;
75@@ -386,6 +395,9 @@ int qemu_fclose(QEMUFile *f)
76 ret = ret2;
77 }
78 }
79+
80+ free(f->buf);
81+
82 /* If any error was spotted before closing, we should report it
83 * instead of the close() return value.
84 */
85@@ -435,7 +447,7 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len)
86 {
87 if (!add_to_iovec(f, f->buf + f->buf_index, len, false)) {
88 f->buf_index += len;
89- if (f->buf_index == IO_BUF_SIZE) {
90+ if (f->buf_index == f->buf_allocated_size) {
91 qemu_fflush(f);
92 }
93 }
94@@ -461,7 +473,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size)
95 }
96
97 while (size > 0) {
98- l = IO_BUF_SIZE - f->buf_index;
99+ l = f->buf_allocated_size - f->buf_index;
100 if (l > size) {
101 l = size;
102 }
103@@ -508,8 +520,8 @@ size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset)
104 size_t index;
105
106 assert(!qemu_file_is_writable(f));
107- assert(offset < IO_BUF_SIZE);
108- assert(size <= IO_BUF_SIZE - offset);
109+ assert(offset < f->buf_allocated_size);
110+ assert(size <= f->buf_allocated_size - offset);
111
112 /* The 1st byte to read from */
113 index = f->buf_index + offset;
114@@ -559,7 +571,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size)
115 size_t res;
116 uint8_t *src;
117
118- res = qemu_peek_buffer(f, &src, MIN(pending, IO_BUF_SIZE), 0);
119+ res = qemu_peek_buffer(f, &src, MIN(pending, f->buf_allocated_size), 0);
120 if (res == 0) {
121 return done;
122 }
123@@ -593,7 +605,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size)
124 */
125 size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
126 {
127- if (size < IO_BUF_SIZE) {
128+ if (size < f->buf_allocated_size) {
129 size_t res;
130 uint8_t *src;
131
132@@ -618,7 +630,7 @@ int qemu_peek_byte(QEMUFile *f, int offset)
133 int index = f->buf_index + offset;
134
135 assert(!qemu_file_is_writable(f));
136- assert(offset < IO_BUF_SIZE);
137+ assert(offset < f->buf_allocated_size);
138
139 if (index >= f->buf_size) {
140 qemu_fill_buffer(f);
141@@ -770,7 +782,7 @@ static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest_len,
142 ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
143 const uint8_t *p, size_t size)
144 {
145- ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);
146+ ssize_t blen = f->buf_allocated_size - f->buf_index - sizeof(int32_t);
147
148 if (blen < compressBound(size)) {
149 return -1;
150diff --git a/migration/qemu-file.h b/migration/qemu-file.h
151index a9b6d6ccb7..8752d27c74 100644
152--- a/migration/qemu-file.h
153+++ b/migration/qemu-file.h
154@@ -120,6 +120,7 @@ typedef struct QEMUFileHooks {
155 } QEMUFileHooks;
156
157 QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
158+QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, size_t buffer_size);
159 void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
160 int qemu_get_fd(QEMUFile *f);
161 int qemu_fclose(QEMUFile *f);
162diff --git a/savevm-async.c b/savevm-async.c
60ae3775 163index f918e18dce..156b7a030e 100644
abc9e57f
WB
164--- a/savevm-async.c
165+++ b/savevm-async.c
d7f4e01a 166@@ -392,7 +392,7 @@ void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp)
abc9e57f
WB
167 goto restart;
168 }
169
170- snap_state.file = qemu_fopen_ops(&snap_state, &block_file_ops);
171+ snap_state.file = qemu_fopen_ops_sized(&snap_state, &block_file_ops, 4 * 1024 * 1024);
172
173 if (!snap_state.file) {
174 error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile);
d7f4e01a 175@@ -514,7 +514,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp)
abc9e57f
WB
176 blk_op_block_all(be, blocker);
177
178 /* restore the VM state */
179- f = qemu_fopen_ops(be, &loadstate_file_ops);
180+ f = qemu_fopen_ops_sized(be, &loadstate_file_ops, 4 * 1024 * 1024);
181 if (!f) {
182 error_setg(errp, "Could not open VM state file");
183 goto the_end;