mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
slirp: use libslirp migration code
slirp migration code uses QEMU vmstate so far, when building WITH_QEMU. Introduce slirp_state_{load,save,version}() functions to move the state saving handling to libslirp side. So far, the bitstream compatibility should remain equal with current QEMU, as this is effectively using the same code, with the same format etc. When libslirp is made standalone, we will need some mechanism to ensure bitstream compatibility regardless of the libslirp version installed. See the FIXME note in the code. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20190212162524.31504-3-marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
This commit is contained in:
parent
b92a1ff497
commit
d890344166
7 changed files with 88 additions and 48 deletions
55
net/slirp.c
55
net/slirp.c
|
@ -44,6 +44,8 @@
|
|||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "util.h"
|
||||
#include "migration/register.h"
|
||||
#include "migration/qemu-file-types.h"
|
||||
|
||||
static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
|
||||
{
|
||||
|
@ -146,6 +148,7 @@ static void net_slirp_cleanup(NetClientState *nc)
|
|||
|
||||
g_slist_free_full(s->fwd, slirp_free_fwd);
|
||||
main_loop_poll_remove_notifier(&s->poll_notifier);
|
||||
unregister_savevm(NULL, "slirp", s->slirp);
|
||||
slirp_cleanup(s->slirp);
|
||||
if (s->exit_notifier.notify) {
|
||||
qemu_remove_exit_notifier(&s->exit_notifier);
|
||||
|
@ -303,6 +306,46 @@ static void net_slirp_poll_notify(Notifier *notifier, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
net_slirp_stream_read(void *buf, size_t size, void *opaque)
|
||||
{
|
||||
QEMUFile *f = opaque;
|
||||
|
||||
return qemu_get_buffer(f, buf, size);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
net_slirp_stream_write(const void *buf, size_t size, void *opaque)
|
||||
{
|
||||
QEMUFile *f = opaque;
|
||||
|
||||
qemu_put_buffer(f, buf, size);
|
||||
if (qemu_file_get_error(f)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static int net_slirp_state_load(QEMUFile *f, void *opaque, int version_id)
|
||||
{
|
||||
Slirp *slirp = opaque;
|
||||
|
||||
return slirp_state_load(slirp, version_id, net_slirp_stream_read, f);
|
||||
}
|
||||
|
||||
static void net_slirp_state_save(QEMUFile *f, void *opaque)
|
||||
{
|
||||
Slirp *slirp = opaque;
|
||||
|
||||
slirp_state_save(slirp, net_slirp_stream_write, f);
|
||||
}
|
||||
|
||||
static SaveVMHandlers savevm_slirp_state = {
|
||||
.save_state = net_slirp_state_save,
|
||||
.load_state = net_slirp_state_load,
|
||||
};
|
||||
|
||||
static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
const char *name, int restricted,
|
||||
bool ipv4, const char *vnetwork, const char *vhost,
|
||||
|
@ -523,6 +566,18 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
|||
&slirp_cb, s);
|
||||
QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
|
||||
|
||||
/*
|
||||
* Make sure the current bitstream version of slirp is 4, to avoid
|
||||
* QEMU migration incompatibilities, if upstream slirp bumped the
|
||||
* version.
|
||||
*
|
||||
* FIXME: use bitfields of features? teach libslirp to save with
|
||||
* specific version?
|
||||
*/
|
||||
g_assert(slirp_state_version() == 4);
|
||||
register_savevm_live(NULL, "slirp", 0, slirp_state_version(),
|
||||
&savevm_slirp_state, s->slirp);
|
||||
|
||||
s->poll_notifier.notify = net_slirp_poll_notify;
|
||||
main_loop_poll_add_notifier(&s->poll_notifier);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue