]> git.proxmox.com Git - mirror_qemu.git/blob - migration/qemu-file.h
migration: remove the QEMUFileOps 'writev_buffer' callback
[mirror_qemu.git] / migration / qemu-file.h
1 /*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #ifndef MIGRATION_QEMU_FILE_H
26 #define MIGRATION_QEMU_FILE_H
27
28 #include <zlib.h>
29 #include "exec/cpu-common.h"
30 #include "io/channel.h"
31
32 /*
33 * This function provides hooks around different
34 * stages of RAM migration.
35 * 'data' is call specific data associated with the 'flags' value
36 */
37 typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data);
38
39 /*
40 * Constants used by ram_control_* hooks
41 */
42 #define RAM_CONTROL_SETUP 0
43 #define RAM_CONTROL_ROUND 1
44 #define RAM_CONTROL_HOOK 2
45 #define RAM_CONTROL_FINISH 3
46 #define RAM_CONTROL_BLOCK_REG 4
47
48 /*
49 * This function allows override of where the RAM page
50 * is saved (such as RDMA, for example.)
51 */
52 typedef size_t (QEMURamSaveFunc)(QEMUFile *f,
53 ram_addr_t block_offset,
54 ram_addr_t offset,
55 size_t size,
56 uint64_t *bytes_sent);
57
58 /*
59 * Return a QEMUFile for comms in the opposite direction
60 */
61 typedef QEMUFile *(QEMURetPathFunc)(void *opaque);
62
63 typedef struct QEMUFileOps {
64 QEMURetPathFunc *get_return_path;
65 } QEMUFileOps;
66
67 typedef struct QEMUFileHooks {
68 QEMURamHookFunc *before_ram_iterate;
69 QEMURamHookFunc *after_ram_iterate;
70 QEMURamHookFunc *hook_ram_load;
71 QEMURamSaveFunc *save_page;
72 } QEMUFileHooks;
73
74 QEMUFile *qemu_file_new_input(QIOChannel *ioc, const QEMUFileOps *ops);
75 QEMUFile *qemu_file_new_output(QIOChannel *ioc, const QEMUFileOps *ops);
76 void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
77 int qemu_fclose(QEMUFile *f);
78
79 /*
80 * qemu_file_total_transferred:
81 *
82 * Report the total number of bytes transferred with
83 * this file.
84 *
85 * For writable files, any pending buffers will be
86 * flushed, so the reported value will be equal to
87 * the number of bytes transferred on the wire.
88 *
89 * For readable files, the reported value will be
90 * equal to the number of bytes transferred on the
91 * wire.
92 *
93 * Returns: the total bytes transferred
94 */
95 int64_t qemu_file_total_transferred(QEMUFile *f);
96
97 /*
98 * qemu_file_total_transferred_fast:
99 *
100 * As qemu_file_total_transferred except for writable
101 * files, where no flush is performed and the reported
102 * amount will include the size of any queued buffers,
103 * on top of the amount actually transferred.
104 *
105 * Returns: the total bytes transferred and queued
106 */
107 int64_t qemu_file_total_transferred_fast(QEMUFile *f);
108
109 /*
110 * put_buffer without copying the buffer.
111 * The buffer should be available till it is sent asynchronously.
112 */
113 void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size,
114 bool may_free);
115 bool qemu_file_mode_is_not_valid(const char *mode);
116 bool qemu_file_is_writable(QEMUFile *f);
117
118 #include "migration/qemu-file-types.h"
119
120 size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset);
121 size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size);
122 ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
123 const uint8_t *p, size_t size);
124 int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src);
125
126 /*
127 * Note that you can only peek continuous bytes from where the current pointer
128 * is; you aren't guaranteed to be able to peak to +n bytes unless you've
129 * previously peeked +n-1.
130 */
131 int qemu_peek_byte(QEMUFile *f, int offset);
132 void qemu_file_skip(QEMUFile *f, int size);
133 /*
134 * qemu_file_credit_transfer:
135 *
136 * Report on a number of bytes that have been transferred
137 * out of band from the main file object I/O methods. This
138 * accounting information tracks the total migration traffic.
139 */
140 void qemu_file_credit_transfer(QEMUFile *f, size_t size);
141 void qemu_file_reset_rate_limit(QEMUFile *f);
142 /*
143 * qemu_file_acct_rate_limit:
144 *
145 * Report on a number of bytes the have been transferred
146 * out of band from the main file object I/O methods, and
147 * need to be applied to the rate limiting calcuations
148 */
149 void qemu_file_acct_rate_limit(QEMUFile *f, int64_t len);
150 void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
151 int64_t qemu_file_get_rate_limit(QEMUFile *f);
152 int qemu_file_get_error_obj(QEMUFile *f, Error **errp);
153 void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err);
154 void qemu_file_set_error(QEMUFile *f, int ret);
155 int qemu_file_shutdown(QEMUFile *f);
156 QEMUFile *qemu_file_get_return_path(QEMUFile *f);
157 void qemu_fflush(QEMUFile *f);
158 void qemu_file_set_blocking(QEMUFile *f, bool block);
159
160 void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
161 void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
162 void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data);
163
164 /* Whenever this is found in the data stream, the flags
165 * will be passed to ram_control_load_hook in the incoming-migration
166 * side. This lets before_ram_iterate/after_ram_iterate add
167 * transport-specific sections to the RAM migration data.
168 */
169 #define RAM_SAVE_FLAG_HOOK 0x80
170
171 #define RAM_SAVE_CONTROL_NOT_SUPP -1000
172 #define RAM_SAVE_CONTROL_DELAYED -2000
173
174 size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
175 ram_addr_t offset, size_t size,
176 uint64_t *bytes_sent);
177 QIOChannel *qemu_file_get_ioc(QEMUFile *file);
178
179 #endif