Steve Sistare | b369886 | 2025-01-15 11:00:41 -0800 | [diff] [blame] | 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 | } |