mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-28 05:50:37 +00:00
b7acd65707
To: <quintela@redhat.com>, <dgilbert@redhat.com>, <qemu-devel@nongnu.org> CC: Li Zhijian <lizhijian@cn.fujitsu.com> Date: Sat, 31 Jul 2021 22:05:51 +0800 (5 weeks, 4 days, 17 hours ago) multifd with unsupported protocol will cause a segment fault. (gdb) bt #0 0x0000563b4a93faf8 in socket_connect (addr=0x0, errp=0x7f7f02675410) at ../util/qemu-sockets.c:1190 #1 0x0000563b4a797a03 in qio_channel_socket_connect_sync (ioc=0x563b4d16e8c0, addr=0x0, errp=0x7f7f02675410) at ../io/channel-socket.c:145 #2 0x0000563b4a797abf in qio_channel_socket_connect_worker (task=0x563b4cd86c30, opaque=0x0) at ../io/channel-socket.c:168 #3 0x0000563b4a792631 in qio_task_thread_worker (opaque=0x563b4cd86c30) at ../io/task.c:124 #4 0x0000563b4a91da69 in qemu_thread_start (args=0x563b4c44bb80) at ../util/qemu-thread-posix.c:541 #5 0x00007f7fe9b5b3f9 in ?? () #6 0x0000000000000000 in ?? () It's enough to check migrate_multifd_is_allowed() in multifd cleanup() and multifd setup() though there are so many other places using migrate_use_multifd(). Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
177 lines
5.3 KiB
C
177 lines
5.3 KiB
C
/*
|
|
* Multifd common functions
|
|
*
|
|
* Copyright (c) 2019-2020 Red Hat Inc
|
|
*
|
|
* Authors:
|
|
* Juan Quintela <quintela@redhat.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#ifndef QEMU_MIGRATION_MULTIFD_H
|
|
#define QEMU_MIGRATION_MULTIFD_H
|
|
|
|
bool migrate_multifd_is_allowed(void);
|
|
void migrate_protocol_allow_multifd(bool allow);
|
|
int multifd_save_setup(Error **errp);
|
|
void multifd_save_cleanup(void);
|
|
int multifd_load_setup(Error **errp);
|
|
int multifd_load_cleanup(Error **errp);
|
|
bool multifd_recv_all_channels_created(void);
|
|
bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp);
|
|
void multifd_recv_sync_main(void);
|
|
void multifd_send_sync_main(QEMUFile *f);
|
|
int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);
|
|
|
|
/* Multifd Compression flags */
|
|
#define MULTIFD_FLAG_SYNC (1 << 0)
|
|
|
|
/* We reserve 3 bits for compression methods */
|
|
#define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
|
|
/* we need to be compatible. Before compression value was 0 */
|
|
#define MULTIFD_FLAG_NOCOMP (0 << 1)
|
|
#define MULTIFD_FLAG_ZLIB (1 << 1)
|
|
#define MULTIFD_FLAG_ZSTD (2 << 1)
|
|
|
|
/* This value needs to be a multiple of qemu_target_page_size() */
|
|
#define MULTIFD_PACKET_SIZE (512 * 1024)
|
|
|
|
typedef struct {
|
|
uint32_t magic;
|
|
uint32_t version;
|
|
uint32_t flags;
|
|
/* maximum number of allocated pages */
|
|
uint32_t pages_alloc;
|
|
uint32_t pages_used;
|
|
/* size of the next packet that contains pages */
|
|
uint32_t next_packet_size;
|
|
uint64_t packet_num;
|
|
uint64_t unused[4]; /* Reserved for future use */
|
|
char ramblock[256];
|
|
uint64_t offset[];
|
|
} __attribute__((packed)) MultiFDPacket_t;
|
|
|
|
typedef struct {
|
|
/* number of used pages */
|
|
uint32_t used;
|
|
/* number of allocated pages */
|
|
uint32_t allocated;
|
|
/* global number of generated multifd packets */
|
|
uint64_t packet_num;
|
|
/* offset of each page */
|
|
ram_addr_t *offset;
|
|
/* pointer to each page */
|
|
struct iovec *iov;
|
|
RAMBlock *block;
|
|
} MultiFDPages_t;
|
|
|
|
typedef struct {
|
|
/* this fields are not changed once the thread is created */
|
|
/* channel number */
|
|
uint8_t id;
|
|
/* channel thread name */
|
|
char *name;
|
|
/* tls hostname */
|
|
char *tls_hostname;
|
|
/* channel thread id */
|
|
QemuThread thread;
|
|
/* communication channel */
|
|
QIOChannel *c;
|
|
/* sem where to wait for more work */
|
|
QemuSemaphore sem;
|
|
/* this mutex protects the following parameters */
|
|
QemuMutex mutex;
|
|
/* is this channel thread running */
|
|
bool running;
|
|
/* should this thread finish */
|
|
bool quit;
|
|
/* is the yank function registered */
|
|
bool registered_yank;
|
|
/* thread has work to do */
|
|
int pending_job;
|
|
/* array of pages to sent */
|
|
MultiFDPages_t *pages;
|
|
/* packet allocated len */
|
|
uint32_t packet_len;
|
|
/* pointer to the packet */
|
|
MultiFDPacket_t *packet;
|
|
/* multifd flags for each packet */
|
|
uint32_t flags;
|
|
/* size of the next packet that contains pages */
|
|
uint32_t next_packet_size;
|
|
/* global number of generated multifd packets */
|
|
uint64_t packet_num;
|
|
/* thread local variables */
|
|
/* packets sent through this channel */
|
|
uint64_t num_packets;
|
|
/* pages sent through this channel */
|
|
uint64_t num_pages;
|
|
/* syncs main thread and channels */
|
|
QemuSemaphore sem_sync;
|
|
/* used for compression methods */
|
|
void *data;
|
|
} MultiFDSendParams;
|
|
|
|
typedef struct {
|
|
/* this fields are not changed once the thread is created */
|
|
/* channel number */
|
|
uint8_t id;
|
|
/* channel thread name */
|
|
char *name;
|
|
/* channel thread id */
|
|
QemuThread thread;
|
|
/* communication channel */
|
|
QIOChannel *c;
|
|
/* this mutex protects the following parameters */
|
|
QemuMutex mutex;
|
|
/* is this channel thread running */
|
|
bool running;
|
|
/* should this thread finish */
|
|
bool quit;
|
|
/* array of pages to receive */
|
|
MultiFDPages_t *pages;
|
|
/* packet allocated len */
|
|
uint32_t packet_len;
|
|
/* pointer to the packet */
|
|
MultiFDPacket_t *packet;
|
|
/* multifd flags for each packet */
|
|
uint32_t flags;
|
|
/* global number of generated multifd packets */
|
|
uint64_t packet_num;
|
|
/* thread local variables */
|
|
/* size of the next packet that contains pages */
|
|
uint32_t next_packet_size;
|
|
/* packets sent through this channel */
|
|
uint64_t num_packets;
|
|
/* pages sent through this channel */
|
|
uint64_t num_pages;
|
|
/* syncs main thread and channels */
|
|
QemuSemaphore sem_sync;
|
|
/* used for de-compression methods */
|
|
void *data;
|
|
} MultiFDRecvParams;
|
|
|
|
typedef struct {
|
|
/* Setup for sending side */
|
|
int (*send_setup)(MultiFDSendParams *p, Error **errp);
|
|
/* Cleanup for sending side */
|
|
void (*send_cleanup)(MultiFDSendParams *p, Error **errp);
|
|
/* Prepare the send packet */
|
|
int (*send_prepare)(MultiFDSendParams *p, uint32_t used, Error **errp);
|
|
/* Write the send packet */
|
|
int (*send_write)(MultiFDSendParams *p, uint32_t used, Error **errp);
|
|
/* Setup for receiving side */
|
|
int (*recv_setup)(MultiFDRecvParams *p, Error **errp);
|
|
/* Cleanup for receiving side */
|
|
void (*recv_cleanup)(MultiFDRecvParams *p);
|
|
/* Read all pages */
|
|
int (*recv_pages)(MultiFDRecvParams *p, uint32_t used, Error **errp);
|
|
} MultiFDMethods;
|
|
|
|
void multifd_register_ops(int method, MultiFDMethods *ops);
|
|
|
|
#endif
|
|
|