]> git.proxmox.com Git - mirror_qemu.git/blame - migration/qemu-file.h
tcg/sparc64: Disable TCG_TARGET_HAS_extr_i64_i32
[mirror_qemu.git] / migration / qemu-file.h
CommitLineData
701a8f76
PB
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 */
175de524 24
08a0aee1
JQ
25#ifndef MIGRATION_QEMU_FILE_H
26#define MIGRATION_QEMU_FILE_H
deb22f9a 27
dcaf446e 28#include <zlib.h>
6a0acfff 29#include "exec/cpu-common.h"
c6ad5be7 30#include "io/channel.h"
dcaf446e 31
43487c67
MH
32/*
33 * This function provides hooks around different
34 * stages of RAM migration.
632e3a5c 35 * 'data' is call specific data associated with the 'flags' value
43487c67 36 */
365c0463 37typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data);
43487c67
MH
38
39/*
40 * Constants used by ram_control_* hooks
41 */
632e3a5c
DDAG
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
43487c67
MH
47
48/*
49 * This function allows override of where the RAM page
50 * is saved (such as RDMA, for example.)
51 */
365c0463
DB
52typedef 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);
43487c67 57
0436e09f 58typedef struct QEMUFileHooks {
43487c67
MH
59 QEMURamHookFunc *before_ram_iterate;
60 QEMURamHookFunc *after_ram_iterate;
61 QEMURamHookFunc *hook_ram_load;
62 QEMURamSaveFunc *save_page;
0436e09f 63} QEMUFileHooks;
9229bf3c 64
77ef2dc1
DB
65QEMUFile *qemu_file_new_input(QIOChannel *ioc);
66QEMUFile *qemu_file_new_output(QIOChannel *ioc);
0436e09f 67void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
701a8f76 68int qemu_fclose(QEMUFile *f);
fbfa6404
DB
69
70/*
6da835d4 71 * qemu_file_transferred:
fbfa6404
DB
72 *
73 * Report the total number of bytes transferred with
74 * this file.
75 *
76 * For writable files, any pending buffers will be
77 * flushed, so the reported value will be equal to
78 * the number of bytes transferred on the wire.
79 *
80 * For readable files, the reported value will be
81 * equal to the number of bytes transferred on the
82 * wire.
83 *
84 * Returns: the total bytes transferred
85 */
6da835d4 86uint64_t qemu_file_transferred(QEMUFile *f);
fbfa6404
DB
87
88/*
fc95c63b 89 * qemu_file_transferred_noflush:
fbfa6404 90 *
fc95c63b
JQ
91 * As qemu_file_transferred except for writable files, where no flush
92 * is performed and the reported amount will include the size of any
93 * queued buffers, on top of the amount actually transferred.
fbfa6404
DB
94 *
95 * Returns: the total bytes transferred and queued
96 */
fc95c63b 97uint64_t qemu_file_transferred_noflush(QEMUFile *f);
fbfa6404 98
6181ec24
OW
99/*
100 * put_buffer without copying the buffer.
101 * The buffer should be available till it is sent asynchronously.
102 */
53f09a10
PB
103void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size,
104 bool may_free);
701a8f76 105
08a0aee1 106#include "migration/qemu-file-types.h"
deb22f9a 107
394b9407
PB
108size_t coroutine_mixed_fn qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset);
109size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size);
dcaf446e
XG
110ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
111 const uint8_t *p, size_t size);
44f0eadc 112int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src);
4024cc85 113bool qemu_file_buffer_empty(QEMUFile *file);
9504fb51 114
548f52ea
DDAG
115/*
116 * Note that you can only peek continuous bytes from where the current pointer
117 * is; you aren't guaranteed to be able to peak to +n bytes unless you've
118 * previously peeked +n-1.
119 */
394b9407 120int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset);
c961514f 121void qemu_file_skip(QEMUFile *f, int size);
1a93bd2f
DB
122/*
123 * qemu_file_credit_transfer:
124 *
125 * Report on a number of bytes that have been transferred
126 * out of band from the main file object I/O methods. This
127 * accounting information tracks the total migration traffic.
128 */
129void qemu_file_credit_transfer(QEMUFile *f, size_t size);
60bb3c58 130int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp);
3d661c8a 131void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err);
c961514f 132void qemu_file_set_error(QEMUFile *f, int ret);
e1a8c9b6 133int qemu_file_shutdown(QEMUFile *f);
adc468e9 134QEMUFile *qemu_file_get_return_path(QEMUFile *f);
be903b2a 135void qemu_fflush(QEMUFile *f);
a800cd5c 136void qemu_file_set_blocking(QEMUFile *f, bool block);
c7a7db4b 137int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
701a8f76 138
2ce3bf1a
JQ
139void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
140void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
141void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data);
142
143/* Whenever this is found in the data stream, the flags
144 * will be passed to ram_control_load_hook in the incoming-migration
145 * side. This lets before_ram_iterate/after_ram_iterate add
146 * transport-specific sections to the RAM migration data.
147 */
148#define RAM_SAVE_FLAG_HOOK 0x80
149
150#define RAM_SAVE_CONTROL_NOT_SUPP -1000
151#define RAM_SAVE_CONTROL_DELAYED -2000
152
153size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
154 ram_addr_t offset, size_t size,
155 uint64_t *bytes_sent);
c6ad5be7 156QIOChannel *qemu_file_get_ioc(QEMUFile *file);
08a0aee1 157
701a8f76 158#endif