1195e14d0SDaniel P. Berrange /* 2195e14d0SDaniel P. Berrange * QEMU I/O channels external command driver 3195e14d0SDaniel P. Berrange * 4195e14d0SDaniel P. Berrange * Copyright (c) 2015 Red Hat, Inc. 5195e14d0SDaniel P. Berrange * 6195e14d0SDaniel P. Berrange * This library is free software; you can redistribute it and/or 7195e14d0SDaniel P. Berrange * modify it under the terms of the GNU Lesser General Public 8195e14d0SDaniel P. Berrange * License as published by the Free Software Foundation; either 9c8198bd5SChetan Pant * version 2.1 of the License, or (at your option) any later version. 10195e14d0SDaniel P. Berrange * 11195e14d0SDaniel P. Berrange * This library is distributed in the hope that it will be useful, 12195e14d0SDaniel P. Berrange * but WITHOUT ANY WARRANTY; without even the implied warranty of 13195e14d0SDaniel P. Berrange * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14195e14d0SDaniel P. Berrange * Lesser General Public License for more details. 15195e14d0SDaniel P. Berrange * 16195e14d0SDaniel P. Berrange * You should have received a copy of the GNU Lesser General Public 17195e14d0SDaniel P. Berrange * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18195e14d0SDaniel P. Berrange * 19195e14d0SDaniel P. Berrange */ 20195e14d0SDaniel P. Berrange 21cae9fc56SPeter Maydell #include "qemu/osdep.h" 22195e14d0SDaniel P. Berrange #include "io/channel-command.h" 23195e14d0SDaniel P. Berrange #include "io/channel-watch.h" 24da34e65cSMarkus Armbruster #include "qapi/error.h" 250b8fa32fSMarkus Armbruster #include "qemu/module.h" 26195e14d0SDaniel P. Berrange #include "qemu/sockets.h" 27195e14d0SDaniel P. Berrange #include "trace.h" 28195e14d0SDaniel P. Berrange 2905e50e8fSMarc-André Lureau /** 3005e50e8fSMarc-André Lureau * qio_channel_command_new_pid: 3105e50e8fSMarc-André Lureau * @writefd: the FD connected to the command's stdin 3205e50e8fSMarc-André Lureau * @readfd: the FD connected to the command's stdout 33a95570e3SMarc-André Lureau * @pid: the PID/HANDLE of the running child command 3405e50e8fSMarc-André Lureau * @errp: pointer to a NULL-initialized error object 3505e50e8fSMarc-André Lureau * 3605e50e8fSMarc-André Lureau * Create a channel for performing I/O with the 3705e50e8fSMarc-André Lureau * previously spawned command identified by @pid. 3805e50e8fSMarc-André Lureau * The two file descriptors provide the connection 3905e50e8fSMarc-André Lureau * to command's stdio streams, either one or which 4005e50e8fSMarc-André Lureau * may be -1 to indicate that stream is not open. 4105e50e8fSMarc-André Lureau * 4205e50e8fSMarc-André Lureau * The channel will take ownership of the process 4305e50e8fSMarc-André Lureau * @pid and will kill it when closing the channel. 4405e50e8fSMarc-André Lureau * Similarly it will take responsibility for 4505e50e8fSMarc-André Lureau * closing the file descriptors @writefd and @readfd. 4605e50e8fSMarc-André Lureau * 4705e50e8fSMarc-André Lureau * Returns: the command channel object, or NULL on error 4805e50e8fSMarc-André Lureau */ 4905e50e8fSMarc-André Lureau static QIOChannelCommand * 50195e14d0SDaniel P. Berrange qio_channel_command_new_pid(int writefd, 51195e14d0SDaniel P. Berrange int readfd, 52a95570e3SMarc-André Lureau GPid pid) 53195e14d0SDaniel P. Berrange { 54195e14d0SDaniel P. Berrange QIOChannelCommand *ioc; 55195e14d0SDaniel P. Berrange 56195e14d0SDaniel P. Berrange ioc = QIO_CHANNEL_COMMAND(object_new(TYPE_QIO_CHANNEL_COMMAND)); 57195e14d0SDaniel P. Berrange 58195e14d0SDaniel P. Berrange ioc->readfd = readfd; 59195e14d0SDaniel P. Berrange ioc->writefd = writefd; 60195e14d0SDaniel P. Berrange ioc->pid = pid; 61195e14d0SDaniel P. Berrange 62ec5b6c9cSMarc-André Lureau trace_qio_channel_command_new_pid(ioc, writefd, readfd, 63ec5b6c9cSMarc-André Lureau #ifdef WIN32 64ec5b6c9cSMarc-André Lureau GetProcessId(pid) 65ec5b6c9cSMarc-André Lureau #else 66ec5b6c9cSMarc-André Lureau pid 67ec5b6c9cSMarc-André Lureau #endif 68ec5b6c9cSMarc-André Lureau ); 69195e14d0SDaniel P. Berrange return ioc; 70195e14d0SDaniel P. Berrange } 71195e14d0SDaniel P. Berrange 72195e14d0SDaniel P. Berrange QIOChannelCommand * 73195e14d0SDaniel P. Berrange qio_channel_command_new_spawn(const char *const argv[], 74195e14d0SDaniel P. Berrange int flags, 75195e14d0SDaniel P. Berrange Error **errp) 76195e14d0SDaniel P. Berrange { 77a95570e3SMarc-André Lureau g_autoptr(GError) err = NULL; 78a95570e3SMarc-André Lureau GPid pid = 0; 79a95570e3SMarc-André Lureau GSpawnFlags gflags = G_SPAWN_CLOEXEC_PIPES | G_SPAWN_DO_NOT_REAP_CHILD; 80a95570e3SMarc-André Lureau int stdinfd = -1, stdoutfd = -1; 81195e14d0SDaniel P. Berrange 82195e14d0SDaniel P. Berrange flags = flags & O_ACCMODE; 83a95570e3SMarc-André Lureau gflags |= flags == O_WRONLY ? G_SPAWN_STDOUT_TO_DEV_NULL : 0; 84195e14d0SDaniel P. Berrange 85a95570e3SMarc-André Lureau if (!g_spawn_async_with_pipes(NULL, (char **)argv, NULL, gflags, NULL, NULL, 86a95570e3SMarc-André Lureau &pid, 87a95570e3SMarc-André Lureau flags == O_RDONLY ? NULL : &stdinfd, 88a95570e3SMarc-André Lureau flags == O_WRONLY ? NULL : &stdoutfd, 89a95570e3SMarc-André Lureau NULL, &err)) { 90a95570e3SMarc-André Lureau error_setg(errp, "%s", err->message); 91195e14d0SDaniel P. Berrange return NULL; 92195e14d0SDaniel P. Berrange } 93195e14d0SDaniel P. Berrange 94a95570e3SMarc-André Lureau return qio_channel_command_new_pid(stdinfd, stdoutfd, pid); 95a95570e3SMarc-André Lureau } 96a95570e3SMarc-André Lureau 97195e14d0SDaniel P. Berrange #ifndef WIN32 98195e14d0SDaniel P. Berrange static int qio_channel_command_abort(QIOChannelCommand *ioc, 99195e14d0SDaniel P. Berrange Error **errp) 100195e14d0SDaniel P. Berrange { 101195e14d0SDaniel P. Berrange pid_t ret; 102195e14d0SDaniel P. Berrange int status; 103195e14d0SDaniel P. Berrange int step = 0; 104195e14d0SDaniel P. Berrange 105195e14d0SDaniel P. Berrange /* See if intermediate process has exited; if not, try a nice 106195e14d0SDaniel P. Berrange * SIGTERM followed by a more severe SIGKILL. 107195e14d0SDaniel P. Berrange */ 108195e14d0SDaniel P. Berrange rewait: 109195e14d0SDaniel P. Berrange trace_qio_channel_command_abort(ioc, ioc->pid); 110195e14d0SDaniel P. Berrange ret = waitpid(ioc->pid, &status, WNOHANG); 111195e14d0SDaniel P. Berrange trace_qio_channel_command_wait(ioc, ioc->pid, ret, status); 112195e14d0SDaniel P. Berrange if (ret == (pid_t)-1) { 113195e14d0SDaniel P. Berrange if (errno == EINTR) { 114195e14d0SDaniel P. Berrange goto rewait; 115195e14d0SDaniel P. Berrange } else { 116195e14d0SDaniel P. Berrange error_setg_errno(errp, errno, 117195e14d0SDaniel P. Berrange "Cannot wait on pid %llu", 118195e14d0SDaniel P. Berrange (unsigned long long)ioc->pid); 119195e14d0SDaniel P. Berrange return -1; 120195e14d0SDaniel P. Berrange } 121195e14d0SDaniel P. Berrange } else if (ret == 0) { 122195e14d0SDaniel P. Berrange if (step == 0) { 123195e14d0SDaniel P. Berrange kill(ioc->pid, SIGTERM); 124195e14d0SDaniel P. Berrange } else if (step == 1) { 125195e14d0SDaniel P. Berrange kill(ioc->pid, SIGKILL); 126195e14d0SDaniel P. Berrange } else { 127195e14d0SDaniel P. Berrange error_setg(errp, 128195e14d0SDaniel P. Berrange "Process %llu refused to die", 129195e14d0SDaniel P. Berrange (unsigned long long)ioc->pid); 130195e14d0SDaniel P. Berrange return -1; 131195e14d0SDaniel P. Berrange } 1320c0a55b2SDaniel P. Berrange step++; 133195e14d0SDaniel P. Berrange usleep(10 * 1000); 134195e14d0SDaniel P. Berrange goto rewait; 135195e14d0SDaniel P. Berrange } 136195e14d0SDaniel P. Berrange 137195e14d0SDaniel P. Berrange return 0; 138195e14d0SDaniel P. Berrange } 139ec5b6c9cSMarc-André Lureau #else 140ec5b6c9cSMarc-André Lureau static int qio_channel_command_abort(QIOChannelCommand *ioc, 141ec5b6c9cSMarc-André Lureau Error **errp) 142ec5b6c9cSMarc-André Lureau { 143ec5b6c9cSMarc-André Lureau DWORD ret; 144ec5b6c9cSMarc-André Lureau 145ec5b6c9cSMarc-André Lureau TerminateProcess(ioc->pid, 0); 146ec5b6c9cSMarc-André Lureau ret = WaitForSingleObject(ioc->pid, 1000); 147ec5b6c9cSMarc-André Lureau if (ret != WAIT_OBJECT_0) { 148ec5b6c9cSMarc-André Lureau error_setg(errp, 149ec5b6c9cSMarc-André Lureau "Process %llu refused to die", 150ec5b6c9cSMarc-André Lureau (unsigned long long)GetProcessId(ioc->pid)); 151ec5b6c9cSMarc-André Lureau return -1; 152ec5b6c9cSMarc-André Lureau } 153ec5b6c9cSMarc-André Lureau 154ec5b6c9cSMarc-André Lureau return 0; 155ec5b6c9cSMarc-André Lureau } 156195e14d0SDaniel P. Berrange #endif /* ! WIN32 */ 157195e14d0SDaniel P. Berrange 158195e14d0SDaniel P. Berrange 159195e14d0SDaniel P. Berrange static void qio_channel_command_init(Object *obj) 160195e14d0SDaniel P. Berrange { 161195e14d0SDaniel P. Berrange QIOChannelCommand *ioc = QIO_CHANNEL_COMMAND(obj); 162195e14d0SDaniel P. Berrange ioc->readfd = -1; 163195e14d0SDaniel P. Berrange ioc->writefd = -1; 164a95570e3SMarc-André Lureau ioc->pid = 0; 165195e14d0SDaniel P. Berrange } 166195e14d0SDaniel P. Berrange 167195e14d0SDaniel P. Berrange static void qio_channel_command_finalize(Object *obj) 168195e14d0SDaniel P. Berrange { 169195e14d0SDaniel P. Berrange QIOChannelCommand *ioc = QIO_CHANNEL_COMMAND(obj); 170195e14d0SDaniel P. Berrange if (ioc->readfd != -1) { 171195e14d0SDaniel P. Berrange close(ioc->readfd); 172195e14d0SDaniel P. Berrange } 173e155494cSDaniel P. Berrange if (ioc->writefd != -1 && 174e155494cSDaniel P. Berrange ioc->writefd != ioc->readfd) { 175195e14d0SDaniel P. Berrange close(ioc->writefd); 176195e14d0SDaniel P. Berrange } 177e155494cSDaniel P. Berrange ioc->writefd = ioc->readfd = -1; 178195e14d0SDaniel P. Berrange if (ioc->pid > 0) { 179195e14d0SDaniel P. Berrange qio_channel_command_abort(ioc, NULL); 180a95570e3SMarc-André Lureau g_spawn_close_pid(ioc->pid); 181195e14d0SDaniel P. Berrange } 182195e14d0SDaniel P. Berrange } 183195e14d0SDaniel P. Berrange 184ec5b6c9cSMarc-André Lureau #ifdef WIN32 185ec5b6c9cSMarc-André Lureau static bool win32_fd_poll(int fd, gushort events) 186ec5b6c9cSMarc-André Lureau { 187ec5b6c9cSMarc-André Lureau GPollFD pfd = { .fd = _get_osfhandle(fd), .events = events }; 188ec5b6c9cSMarc-André Lureau int res; 189ec5b6c9cSMarc-André Lureau 190ec5b6c9cSMarc-André Lureau do { 191ec5b6c9cSMarc-André Lureau res = g_poll(&pfd, 1, 0); 192ec5b6c9cSMarc-André Lureau } while (res < 0 && errno == EINTR); 193ec5b6c9cSMarc-André Lureau if (res == 0) { 194ec5b6c9cSMarc-André Lureau return false; 195ec5b6c9cSMarc-André Lureau } 196ec5b6c9cSMarc-André Lureau 197ec5b6c9cSMarc-André Lureau return true; 198ec5b6c9cSMarc-André Lureau } 199ec5b6c9cSMarc-André Lureau #endif 200195e14d0SDaniel P. Berrange 201195e14d0SDaniel P. Berrange static ssize_t qio_channel_command_readv(QIOChannel *ioc, 202195e14d0SDaniel P. Berrange const struct iovec *iov, 203195e14d0SDaniel P. Berrange size_t niov, 204195e14d0SDaniel P. Berrange int **fds, 205195e14d0SDaniel P. Berrange size_t *nfds, 206*84615a19Smanish.mishra int flags, 207195e14d0SDaniel P. Berrange Error **errp) 208195e14d0SDaniel P. Berrange { 209195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 210195e14d0SDaniel P. Berrange ssize_t ret; 211195e14d0SDaniel P. Berrange 212ec5b6c9cSMarc-André Lureau #ifdef WIN32 213ec5b6c9cSMarc-André Lureau if (!cioc->blocking && !win32_fd_poll(cioc->readfd, G_IO_IN)) { 214ec5b6c9cSMarc-André Lureau return QIO_CHANNEL_ERR_BLOCK; 215ec5b6c9cSMarc-André Lureau } 216ec5b6c9cSMarc-André Lureau #endif 217ec5b6c9cSMarc-André Lureau 218195e14d0SDaniel P. Berrange retry: 219195e14d0SDaniel P. Berrange ret = readv(cioc->readfd, iov, niov); 220195e14d0SDaniel P. Berrange if (ret < 0) { 22130fd3e27SDaniel P. Berrange if (errno == EAGAIN) { 222195e14d0SDaniel P. Berrange return QIO_CHANNEL_ERR_BLOCK; 223195e14d0SDaniel P. Berrange } 224195e14d0SDaniel P. Berrange if (errno == EINTR) { 225195e14d0SDaniel P. Berrange goto retry; 226195e14d0SDaniel P. Berrange } 227195e14d0SDaniel P. Berrange 228195e14d0SDaniel P. Berrange error_setg_errno(errp, errno, 229195e14d0SDaniel P. Berrange "Unable to read from command"); 230195e14d0SDaniel P. Berrange return -1; 231195e14d0SDaniel P. Berrange } 232195e14d0SDaniel P. Berrange 233195e14d0SDaniel P. Berrange return ret; 234195e14d0SDaniel P. Berrange } 235195e14d0SDaniel P. Berrange 236195e14d0SDaniel P. Berrange static ssize_t qio_channel_command_writev(QIOChannel *ioc, 237195e14d0SDaniel P. Berrange const struct iovec *iov, 238195e14d0SDaniel P. Berrange size_t niov, 239195e14d0SDaniel P. Berrange int *fds, 240195e14d0SDaniel P. Berrange size_t nfds, 241b88651cbSLeonardo Bras int flags, 242195e14d0SDaniel P. Berrange Error **errp) 243195e14d0SDaniel P. Berrange { 244195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 245195e14d0SDaniel P. Berrange ssize_t ret; 246195e14d0SDaniel P. Berrange 247ec5b6c9cSMarc-André Lureau #ifdef WIN32 248ec5b6c9cSMarc-André Lureau if (!cioc->blocking && !win32_fd_poll(cioc->writefd, G_IO_OUT)) { 249ec5b6c9cSMarc-André Lureau return QIO_CHANNEL_ERR_BLOCK; 250ec5b6c9cSMarc-André Lureau } 251ec5b6c9cSMarc-André Lureau #endif 252ec5b6c9cSMarc-André Lureau 253195e14d0SDaniel P. Berrange retry: 254195e14d0SDaniel P. Berrange ret = writev(cioc->writefd, iov, niov); 255195e14d0SDaniel P. Berrange if (ret <= 0) { 25630fd3e27SDaniel P. Berrange if (errno == EAGAIN) { 257195e14d0SDaniel P. Berrange return QIO_CHANNEL_ERR_BLOCK; 258195e14d0SDaniel P. Berrange } 259195e14d0SDaniel P. Berrange if (errno == EINTR) { 260195e14d0SDaniel P. Berrange goto retry; 261195e14d0SDaniel P. Berrange } 262195e14d0SDaniel P. Berrange error_setg_errno(errp, errno, "%s", 263195e14d0SDaniel P. Berrange "Unable to write to command"); 264195e14d0SDaniel P. Berrange return -1; 265195e14d0SDaniel P. Berrange } 266195e14d0SDaniel P. Berrange return ret; 267195e14d0SDaniel P. Berrange } 268195e14d0SDaniel P. Berrange 269195e14d0SDaniel P. Berrange static int qio_channel_command_set_blocking(QIOChannel *ioc, 270195e14d0SDaniel P. Berrange bool enabled, 271195e14d0SDaniel P. Berrange Error **errp) 272195e14d0SDaniel P. Berrange { 273195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 274195e14d0SDaniel P. Berrange 275ec5b6c9cSMarc-André Lureau #ifdef WIN32 276ec5b6c9cSMarc-André Lureau cioc->blocking = enabled; 277ec5b6c9cSMarc-André Lureau #else 278ec5b6c9cSMarc-André Lureau 279ec5b6c9cSMarc-André Lureau if ((cioc->writefd >= 0 && !g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL)) || 280ec5b6c9cSMarc-André Lureau (cioc->readfd >= 0 && !g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL))) { 28117fc1245SMarc-André Lureau error_setg_errno(errp, errno, "Failed to set FD nonblocking"); 28217fc1245SMarc-André Lureau return -1; 283195e14d0SDaniel P. Berrange } 28417fc1245SMarc-André Lureau #endif 285195e14d0SDaniel P. Berrange return 0; 286195e14d0SDaniel P. Berrange } 287195e14d0SDaniel P. Berrange 288195e14d0SDaniel P. Berrange 289195e14d0SDaniel P. Berrange static int qio_channel_command_close(QIOChannel *ioc, 290195e14d0SDaniel P. Berrange Error **errp) 291195e14d0SDaniel P. Berrange { 292195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 293195e14d0SDaniel P. Berrange int rv = 0; 294fe823b6fSThomas Huth #ifndef WIN32 295fe823b6fSThomas Huth pid_t wp; 296fe823b6fSThomas Huth #endif 297195e14d0SDaniel P. Berrange 298195e14d0SDaniel P. Berrange /* We close FDs before killing, because that 299195e14d0SDaniel P. Berrange * gives a better chance of clean shutdown 300195e14d0SDaniel P. Berrange */ 301e155494cSDaniel P. Berrange if (cioc->readfd != -1 && 302e155494cSDaniel P. Berrange close(cioc->readfd) < 0) { 303195e14d0SDaniel P. Berrange rv = -1; 304195e14d0SDaniel P. Berrange } 305e155494cSDaniel P. Berrange if (cioc->writefd != -1 && 306e155494cSDaniel P. Berrange cioc->writefd != cioc->readfd && 307e155494cSDaniel P. Berrange close(cioc->writefd) < 0) { 308195e14d0SDaniel P. Berrange rv = -1; 309195e14d0SDaniel P. Berrange } 310e155494cSDaniel P. Berrange cioc->writefd = cioc->readfd = -1; 311fe823b6fSThomas Huth 312195e14d0SDaniel P. Berrange #ifndef WIN32 313fe823b6fSThomas Huth do { 314fe823b6fSThomas Huth wp = waitpid(cioc->pid, NULL, 0); 315fe823b6fSThomas Huth } while (wp == (pid_t)-1 && errno == EINTR); 316fe823b6fSThomas Huth if (wp == (pid_t)-1) { 317fe823b6fSThomas Huth error_setg_errno(errp, errno, "Failed to wait for pid %llu", 318fe823b6fSThomas Huth (unsigned long long)cioc->pid); 319195e14d0SDaniel P. Berrange return -1; 320195e14d0SDaniel P. Berrange } 321ec5b6c9cSMarc-André Lureau #else 322ec5b6c9cSMarc-André Lureau WaitForSingleObject(cioc->pid, INFINITE); 323195e14d0SDaniel P. Berrange #endif 324fe823b6fSThomas Huth 325195e14d0SDaniel P. Berrange if (rv < 0) { 326195e14d0SDaniel P. Berrange error_setg_errno(errp, errno, "%s", 327195e14d0SDaniel P. Berrange "Unable to close command"); 328195e14d0SDaniel P. Berrange } 329195e14d0SDaniel P. Berrange return rv; 330195e14d0SDaniel P. Berrange } 331195e14d0SDaniel P. Berrange 332195e14d0SDaniel P. Berrange 333bf88c124SPaolo Bonzini static void qio_channel_command_set_aio_fd_handler(QIOChannel *ioc, 334bf88c124SPaolo Bonzini AioContext *ctx, 335bf88c124SPaolo Bonzini IOHandler *io_read, 336bf88c124SPaolo Bonzini IOHandler *io_write, 337bf88c124SPaolo Bonzini void *opaque) 338bf88c124SPaolo Bonzini { 339bf88c124SPaolo Bonzini QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 340826cc324SStefan Hajnoczi aio_set_fd_handler(ctx, cioc->readfd, false, 341826cc324SStefan Hajnoczi io_read, NULL, NULL, NULL, opaque); 342826cc324SStefan Hajnoczi aio_set_fd_handler(ctx, cioc->writefd, false, 343826cc324SStefan Hajnoczi NULL, io_write, NULL, NULL, opaque); 344bf88c124SPaolo Bonzini } 345bf88c124SPaolo Bonzini 346bf88c124SPaolo Bonzini 347195e14d0SDaniel P. Berrange static GSource *qio_channel_command_create_watch(QIOChannel *ioc, 348195e14d0SDaniel P. Berrange GIOCondition condition) 349195e14d0SDaniel P. Berrange { 350195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 351195e14d0SDaniel P. Berrange return qio_channel_create_fd_pair_watch(ioc, 352195e14d0SDaniel P. Berrange cioc->readfd, 353195e14d0SDaniel P. Berrange cioc->writefd, 354195e14d0SDaniel P. Berrange condition); 355195e14d0SDaniel P. Berrange } 356195e14d0SDaniel P. Berrange 357195e14d0SDaniel P. Berrange 358195e14d0SDaniel P. Berrange static void qio_channel_command_class_init(ObjectClass *klass, 359195e14d0SDaniel P. Berrange void *class_data G_GNUC_UNUSED) 360195e14d0SDaniel P. Berrange { 361195e14d0SDaniel P. Berrange QIOChannelClass *ioc_klass = QIO_CHANNEL_CLASS(klass); 362195e14d0SDaniel P. Berrange 363195e14d0SDaniel P. Berrange ioc_klass->io_writev = qio_channel_command_writev; 364195e14d0SDaniel P. Berrange ioc_klass->io_readv = qio_channel_command_readv; 365195e14d0SDaniel P. Berrange ioc_klass->io_set_blocking = qio_channel_command_set_blocking; 366195e14d0SDaniel P. Berrange ioc_klass->io_close = qio_channel_command_close; 367195e14d0SDaniel P. Berrange ioc_klass->io_create_watch = qio_channel_command_create_watch; 368bf88c124SPaolo Bonzini ioc_klass->io_set_aio_fd_handler = qio_channel_command_set_aio_fd_handler; 369195e14d0SDaniel P. Berrange } 370195e14d0SDaniel P. Berrange 371195e14d0SDaniel P. Berrange static const TypeInfo qio_channel_command_info = { 372195e14d0SDaniel P. Berrange .parent = TYPE_QIO_CHANNEL, 373195e14d0SDaniel P. Berrange .name = TYPE_QIO_CHANNEL_COMMAND, 374195e14d0SDaniel P. Berrange .instance_size = sizeof(QIOChannelCommand), 375195e14d0SDaniel P. Berrange .instance_init = qio_channel_command_init, 376195e14d0SDaniel P. Berrange .instance_finalize = qio_channel_command_finalize, 377195e14d0SDaniel P. Berrange .class_init = qio_channel_command_class_init, 378195e14d0SDaniel P. Berrange }; 379195e14d0SDaniel P. Berrange 380195e14d0SDaniel P. Berrange static void qio_channel_command_register_types(void) 381195e14d0SDaniel P. Berrange { 382195e14d0SDaniel P. Berrange type_register_static(&qio_channel_command_info); 383195e14d0SDaniel P. Berrange } 384195e14d0SDaniel P. Berrange 385195e14d0SDaniel P. Berrange type_init(qio_channel_command_register_types); 386