]>
Commit | Line | Data |
---|---|---|
065e2813 AL |
1 | /* |
2 | * QEMU live migration | |
3 | * | |
4 | * Copyright IBM, Corp. 2008 | |
5 | * Copyright Dell MessageOne 2008 | |
527792fa | 6 | * Copyright Red Hat, Inc. 2015-2016 |
065e2813 AL |
7 | * |
8 | * Authors: | |
9 | * Anthony Liguori <aliguori@us.ibm.com> | |
10 | * Charles Duffy <charles_duffy@messageone.com> | |
527792fa | 11 | * Daniel P. Berrange <berrange@redhat.com> |
065e2813 AL |
12 | * |
13 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
14 | * the COPYING file in the top-level directory. | |
15 | * | |
6b620ca3 PB |
16 | * Contributions after 2012-01-13 are licensed under the terms of the |
17 | * GNU GPL, version 2 or (at your option) any later version. | |
065e2813 AL |
18 | */ |
19 | ||
1393a485 | 20 | #include "qemu/osdep.h" |
cc37d98b | 21 | #include "qemu/error-report.h" |
dd4339c5 | 22 | #include "channel.h" |
f4dbe1bf | 23 | #include "exec.h" |
0efc9142 | 24 | #include "migration.h" |
527792fa DB |
25 | #include "io/channel-command.h" |
26 | #include "trace.h" | |
c31772ad | 27 | #include "qemu/cutils.h" |
065e2813 | 28 | |
c31772ad | 29 | #ifdef WIN32 |
c31772ad JBJ |
30 | const char *exec_get_cmd_path(void) |
31 | { | |
32 | g_autofree char *detected_path = g_new(char, MAX_PATH); | |
33 | if (GetSystemDirectoryA(detected_path, MAX_PATH) == 0) { | |
34 | warn_report("Could not detect cmd.exe path, using default."); | |
35 | return "C:\\Windows\\System32\\cmd.exe"; | |
36 | } | |
37 | pstrcat(detected_path, MAX_PATH, "\\cmd.exe"); | |
38 | return g_steal_pointer(&detected_path); | |
39 | } | |
40 | #endif | |
065e2813 | 41 | |
cbab4fac HG |
42 | /* provides the length of strList */ |
43 | static int | |
44 | str_list_length(strList *list) | |
45 | { | |
46 | int len = 0; | |
47 | strList *elem; | |
48 | ||
49 | for (elem = list; elem != NULL; elem = elem->next) { | |
50 | len++; | |
51 | } | |
52 | ||
53 | return len; | |
54 | } | |
55 | ||
56 | static void | |
57 | init_exec_array(strList *command, char **argv, Error **errp) | |
58 | { | |
59 | int i = 0; | |
60 | strList *lst; | |
61 | ||
62 | for (lst = command; lst; lst = lst->next) { | |
63 | argv[i++] = lst->value; | |
64 | } | |
65 | ||
66 | argv[i] = NULL; | |
67 | return; | |
68 | } | |
69 | ||
70 | void exec_start_outgoing_migration(MigrationState *s, strList *command, | |
71 | Error **errp) | |
065e2813 | 72 | { |
527792fa | 73 | QIOChannel *ioc; |
c31772ad | 74 | |
cbab4fac HG |
75 | int length = str_list_length(command); |
76 | g_auto(GStrv) argv = (char **) g_new0(const char *, length + 1); | |
527792fa | 77 | |
cbab4fac HG |
78 | init_exec_array(command, argv, errp); |
79 | g_autofree char *new_command = g_strjoinv(" ", (char **)argv); | |
80 | ||
81 | trace_migration_exec_outgoing(new_command); | |
82 | ioc = QIO_CHANNEL( | |
83 | qio_channel_command_new_spawn( | |
84 | (const char * const *) g_steal_pointer(&argv), | |
85 | O_RDWR, | |
86 | errp)); | |
527792fa | 87 | if (!ioc) { |
f37afb5a | 88 | return; |
065e2813 AL |
89 | } |
90 | ||
6f01f136 | 91 | qio_channel_set_name(ioc, "migration-exec-outgoing"); |
688a3dcb | 92 | migration_channel_connect(s, ioc, NULL, NULL); |
527792fa | 93 | object_unref(OBJECT(ioc)); |
065e2813 AL |
94 | } |
95 | ||
527792fa DB |
96 | static gboolean exec_accept_incoming_migration(QIOChannel *ioc, |
97 | GIOCondition condition, | |
98 | gpointer opaque) | |
065e2813 | 99 | { |
54314711 | 100 | migration_channel_process_incoming(ioc); |
527792fa | 101 | object_unref(OBJECT(ioc)); |
2a543bfd | 102 | return G_SOURCE_REMOVE; |
8a43b1ea CL |
103 | } |
104 | ||
cbab4fac | 105 | void exec_start_incoming_migration(strList *command, Error **errp) |
8a43b1ea | 106 | { |
527792fa | 107 | QIOChannel *ioc; |
c31772ad | 108 | |
cbab4fac HG |
109 | int length = str_list_length(command); |
110 | g_auto(GStrv) argv = (char **) g_new0(const char *, length + 1); | |
111 | ||
112 | init_exec_array(command, argv, errp); | |
113 | g_autofree char *new_command = g_strjoinv(" ", (char **)argv); | |
8a43b1ea | 114 | |
cbab4fac HG |
115 | trace_migration_exec_incoming(new_command); |
116 | ioc = QIO_CHANNEL( | |
117 | qio_channel_command_new_spawn( | |
118 | (const char * const *) g_steal_pointer(&argv), | |
119 | O_RDWR, | |
120 | errp)); | |
527792fa | 121 | if (!ioc) { |
43eaae28 | 122 | return; |
8a43b1ea CL |
123 | } |
124 | ||
6f01f136 | 125 | qio_channel_set_name(ioc, "migration-exec-incoming"); |
e89f5ff2 PX |
126 | qio_channel_add_watch_full(ioc, G_IO_IN, |
127 | exec_accept_incoming_migration, | |
128 | NULL, NULL, | |
129 | g_main_context_get_thread_default()); | |
065e2813 | 130 | } |