qemu-e2k/include/migration/qemu-file-types.h
Fabiano Rosas 7f5b50a401 migration/qemu-file: add utility methods for working with seekable channels
Add utility methods that will be needed when implementing 'mapped-ram'
migration capability.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: "Daniel P. Berrangé" <berrange@redhat.com>
Link: https://lore.kernel.org/r/20240229153017.2221-7-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
2024-03-01 15:42:04 +08:00

183 lines
4.6 KiB
C

/*
* QEMU System Emulator
*
* Copyright (c) 2003-2008 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRATION_QEMU_FILE_TYPES_H
#define MIGRATION_QEMU_FILE_TYPES_H
int qemu_file_get_error(QEMUFile *f);
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size);
void qemu_put_byte(QEMUFile *f, int v);
#define qemu_put_sbyte qemu_put_byte
void qemu_put_be16(QEMUFile *f, unsigned int v);
void qemu_put_be32(QEMUFile *f, unsigned int v);
void qemu_put_be64(QEMUFile *f, uint64_t v);
size_t coroutine_mixed_fn qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size);
int qemu_get_byte(QEMUFile *f);
static inline unsigned int qemu_get_ubyte(QEMUFile *f)
{
return (unsigned int)qemu_get_byte(f);
}
#define qemu_get_sbyte qemu_get_byte
unsigned int qemu_get_be16(QEMUFile *f);
unsigned int qemu_get_be32(QEMUFile *f);
uint64_t qemu_get_be64(QEMUFile *f);
bool qemu_file_is_seekable(QEMUFile *f);
static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
{
qemu_put_be64(f, *pv);
}
static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
{
qemu_put_be32(f, *pv);
}
static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
{
qemu_put_be16(f, *pv);
}
static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
{
qemu_put_byte(f, *pv);
}
static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
{
*pv = qemu_get_be64(f);
}
static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
{
*pv = qemu_get_be32(f);
}
static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
{
*pv = qemu_get_be16(f);
}
static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
{
*pv = qemu_get_byte(f);
}
/* Signed versions for type safety */
static inline void qemu_put_sbe16(QEMUFile *f, int v)
{
qemu_put_be16(f, (unsigned int)v);
}
static inline void qemu_put_sbe32(QEMUFile *f, int v)
{
qemu_put_be32(f, (unsigned int)v);
}
static inline void qemu_put_sbe64(QEMUFile *f, int64_t v)
{
qemu_put_be64(f, (uint64_t)v);
}
static inline int qemu_get_sbe16(QEMUFile *f)
{
return (int)qemu_get_be16(f);
}
static inline int qemu_get_sbe32(QEMUFile *f)
{
return (int)qemu_get_be32(f);
}
static inline int64_t qemu_get_sbe64(QEMUFile *f)
{
return (int64_t)qemu_get_be64(f);
}
static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv)
{
qemu_put_8s(f, (const uint8_t *)pv);
}
static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv)
{
qemu_put_be16s(f, (const uint16_t *)pv);
}
static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv)
{
qemu_put_be32s(f, (const uint32_t *)pv);
}
static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv)
{
qemu_put_be64s(f, (const uint64_t *)pv);
}
static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv)
{
qemu_get_8s(f, (uint8_t *)pv);
}
static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv)
{
qemu_get_be16s(f, (uint16_t *)pv);
}
static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv)
{
qemu_get_be32s(f, (uint32_t *)pv);
}
static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
{
qemu_get_be64s(f, (uint64_t *)pv);
}
size_t coroutine_mixed_fn qemu_get_counted_string(QEMUFile *f, char buf[256]);
void qemu_put_counted_string(QEMUFile *f, const char *name);
/**
* migration_rate_exceeded: Check if we have exceeded rate for this interval
*
* Checks if we have already transferred more data that we are allowed
* in the current interval.
*
* @f: QEMUFile used for main migration channel
*
* Returns if we should stop sending data for this interval.
*/
bool migration_rate_exceeded(QEMUFile *f);
#endif