To support live migration, we override QEMUFile so that instead of writing to disk, the save/restore state happens over a network connection. This patch makes QEMUFile read/write operations function pointers so that we can override them for live migration. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5352 c046a42c-6fe2-441c-8c8c-71466251a162
		
			
				
	
	
		
			138 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			138 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* Declarations for use by hardware emulation.  */
 | 
						|
#ifndef QEMU_HW_H
 | 
						|
#define QEMU_HW_H
 | 
						|
 | 
						|
#include "qemu-common.h"
 | 
						|
#include "irq.h"
 | 
						|
 | 
						|
/* VM Load/Save */
 | 
						|
 | 
						|
/* This function writes a chunk of data to a file at the given position.
 | 
						|
 * The pos argument can be ignored if the file is only being used for
 | 
						|
 * streaming.  The handler should try to write all of the data it can.
 | 
						|
 */
 | 
						|
typedef void (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf,
 | 
						|
                                     int64_t pos, int size);
 | 
						|
 | 
						|
/* Read a chunk of data from a file at the given position.  The pos argument
 | 
						|
 * can be ignored if the file is only be used for streaming.  The number of
 | 
						|
 * bytes actually read should be returned.
 | 
						|
 */
 | 
						|
typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
 | 
						|
                                    int64_t pos, int size);
 | 
						|
 | 
						|
/* Close a file and return an error code */
 | 
						|
typedef int (QEMUFileCloseFunc)(void *opaque);
 | 
						|
 | 
						|
/* Called to determine if the file has exceeded it's bandwidth allocation.  The
 | 
						|
 * bandwidth capping is a soft limit, not a hard limit.
 | 
						|
 */
 | 
						|
typedef int (QEMUFileRateLimit)(void *opaque);
 | 
						|
 | 
						|
QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
 | 
						|
                         QEMUFileGetBufferFunc *get_buffer,
 | 
						|
                         QEMUFileCloseFunc *close,
 | 
						|
                         QEMUFileRateLimit *rate_limit);
 | 
						|
QEMUFile *qemu_fopen(const char *filename, const char *mode);
 | 
						|
QEMUFile *qemu_fopen_fd(int fd);
 | 
						|
void qemu_fflush(QEMUFile *f);
 | 
						|
int qemu_fclose(QEMUFile *f);
 | 
						|
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
 | 
						|
void qemu_put_byte(QEMUFile *f, int v);
 | 
						|
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);
 | 
						|
int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
 | 
						|
int qemu_get_byte(QEMUFile *f);
 | 
						|
unsigned int qemu_get_be16(QEMUFile *f);
 | 
						|
unsigned int qemu_get_be32(QEMUFile *f);
 | 
						|
uint64_t qemu_get_be64(QEMUFile *f);
 | 
						|
int qemu_file_rate_limit(QEMUFile *f);
 | 
						|
 | 
						|
/* Try to send any outstanding data.  This function is useful when output is
 | 
						|
 * halted due to rate limiting or EAGAIN errors occur as it can be used to
 | 
						|
 * resume output. */
 | 
						|
void qemu_file_put_notify(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);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef NEED_CPU_H
 | 
						|
#if TARGET_LONG_BITS == 64
 | 
						|
#define qemu_put_betl qemu_put_be64
 | 
						|
#define qemu_get_betl qemu_get_be64
 | 
						|
#define qemu_put_betls qemu_put_be64s
 | 
						|
#define qemu_get_betls qemu_get_be64s
 | 
						|
#else
 | 
						|
#define qemu_put_betl qemu_put_be32
 | 
						|
#define qemu_get_betl qemu_get_be32
 | 
						|
#define qemu_put_betls qemu_put_be32s
 | 
						|
#define qemu_get_betls qemu_get_be32s
 | 
						|
#endif
 | 
						|
#endif
 | 
						|
 | 
						|
int64_t qemu_ftell(QEMUFile *f);
 | 
						|
int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
 | 
						|
 | 
						|
typedef void SaveStateHandler(QEMUFile *f, void *opaque);
 | 
						|
typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
 | 
						|
 | 
						|
int register_savevm(const char *idstr,
 | 
						|
                    int instance_id,
 | 
						|
                    int version_id,
 | 
						|
                    SaveStateHandler *save_state,
 | 
						|
                    LoadStateHandler *load_state,
 | 
						|
                    void *opaque);
 | 
						|
 | 
						|
typedef void QEMUResetHandler(void *opaque);
 | 
						|
 | 
						|
void qemu_register_reset(QEMUResetHandler *func, void *opaque);
 | 
						|
 | 
						|
/* handler to set the boot_device for a specific type of QEMUMachine */
 | 
						|
/* return 0 if success */
 | 
						|
typedef int QEMUBootSetHandler(void *opaque, const char *boot_device);
 | 
						|
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
 | 
						|
 | 
						|
/* These should really be in isa.h, but are here to make pc.h happy.  */
 | 
						|
typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
 | 
						|
typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
 | 
						|
 | 
						|
#endif
 |