Skip to content

Commit b369886

Browse files
Steve SistareFabiano Rosas
authored andcommitted
migration: cpr-transfer save and load
Add functions to create a QEMUFile based on a unix URI, for saving or loading, for use by cpr-transfer mode to preserve CPR state. Signed-off-by: Steve Sistare <[email protected]> Reviewed-by: Peter Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Fabiano Rosas <[email protected]>
1 parent e3965dc commit b369886

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

include/migration/cpr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ int cpr_state_load(MigrationChannel *channel, Error **errp);
2222
void cpr_state_close(void);
2323
struct QIOChannel *cpr_state_ioc(void);
2424

25+
QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp);
26+
QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp);
27+
2528
#endif

migration/cpr-transfer.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
3+
*
4+
* This work is licensed under the terms of the GNU GPL, version 2 or later.
5+
* See the COPYING file in the top-level directory.
6+
*/
7+
8+
#include "qemu/osdep.h"
9+
#include "qapi/error.h"
10+
#include "io/channel-file.h"
11+
#include "io/channel-socket.h"
12+
#include "io/net-listener.h"
13+
#include "migration/cpr.h"
14+
#include "migration/migration.h"
15+
#include "migration/savevm.h"
16+
#include "migration/qemu-file.h"
17+
#include "migration/vmstate.h"
18+
#include "trace.h"
19+
20+
QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp)
21+
{
22+
MigrationAddress *addr = channel->addr;
23+
24+
if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET &&
25+
addr->u.socket.type == SOCKET_ADDRESS_TYPE_UNIX) {
26+
27+
g_autoptr(QIOChannelSocket) sioc = qio_channel_socket_new();
28+
QIOChannel *ioc = QIO_CHANNEL(sioc);
29+
SocketAddress *saddr = &addr->u.socket;
30+
31+
if (qio_channel_socket_connect_sync(sioc, saddr, errp) < 0) {
32+
return NULL;
33+
}
34+
trace_cpr_transfer_output(addr->u.socket.u.q_unix.path);
35+
qio_channel_set_name(ioc, "cpr-out");
36+
return qemu_file_new_output(ioc);
37+
38+
} else {
39+
error_setg(errp, "bad cpr channel address; must be unix");
40+
return NULL;
41+
}
42+
}
43+
44+
QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp)
45+
{
46+
MigrationAddress *addr = channel->addr;
47+
48+
if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET &&
49+
addr->u.socket.type == SOCKET_ADDRESS_TYPE_UNIX) {
50+
51+
g_autoptr(QIOChannelSocket) sioc = NULL;
52+
SocketAddress *saddr = &addr->u.socket;
53+
g_autoptr(QIONetListener) listener = qio_net_listener_new();
54+
QIOChannel *ioc;
55+
56+
qio_net_listener_set_name(listener, "cpr-socket-listener");
57+
if (qio_net_listener_open_sync(listener, saddr, 1, errp) < 0) {
58+
return NULL;
59+
}
60+
61+
sioc = qio_net_listener_wait_client(listener);
62+
ioc = QIO_CHANNEL(sioc);
63+
trace_cpr_transfer_input(addr->u.socket.u.q_unix.path);
64+
qio_channel_set_name(ioc, "cpr-in");
65+
return qemu_file_new_input(ioc);
66+
67+
} else {
68+
error_setg(errp, "bad cpr channel socket type; must be unix");
69+
return NULL;
70+
}
71+
}

migration/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ system_ss.add(files(
1515
'channel.c',
1616
'channel-block.c',
1717
'cpr.c',
18+
'cpr-transfer.c',
1819
'cpu-throttle.c',
1920
'dirtyrate.c',
2021
'exec.c',

migration/trace-events

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ cpr_delete_fd(const char *name, int id) "%s, id %d"
350350
cpr_find_fd(const char *name, int id, int fd) "%s, id %d returns %d"
351351
cpr_state_save(const char *mode) "%s mode"
352352
cpr_state_load(const char *mode) "%s mode"
353+
cpr_transfer_input(const char *path) "%s"
354+
cpr_transfer_output(const char *path) "%s"
353355

354356
# block-dirty-bitmap.c
355357
send_bitmap_header_enter(void) ""

0 commit comments

Comments
 (0)