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 62*ec5b6c9cSMarc-André Lureau trace_qio_channel_command_new_pid(ioc, writefd, readfd, 63*ec5b6c9cSMarc-André Lureau #ifdef WIN32 64*ec5b6c9cSMarc-André Lureau GetProcessId(pid) 65*ec5b6c9cSMarc-André Lureau #else 66*ec5b6c9cSMarc-André Lureau pid 67*ec5b6c9cSMarc-André Lureau #endif 68*ec5b6c9cSMarc-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 } 139*ec5b6c9cSMarc-André Lureau #else 140*ec5b6c9cSMarc-André Lureau static int qio_channel_command_abort(QIOChannelCommand *ioc, 141*ec5b6c9cSMarc-André Lureau Error **errp) 142*ec5b6c9cSMarc-André Lureau { 143*ec5b6c9cSMarc-André Lureau DWORD ret; 144*ec5b6c9cSMarc-André Lureau 145*ec5b6c9cSMarc-André Lureau TerminateProcess(ioc->pid, 0); 146*ec5b6c9cSMarc-André Lureau ret = WaitForSingleObject(ioc->pid, 1000); 147*ec5b6c9cSMarc-André Lureau if (ret != WAIT_OBJECT_0) { 148*ec5b6c9cSMarc-André Lureau error_setg(errp, 149*ec5b6c9cSMarc-André Lureau "Process %llu refused to die", 150*ec5b6c9cSMarc-André Lureau (unsigned long long)GetProcessId(ioc->pid)); 151*ec5b6c9cSMarc-André Lureau return -1; 152*ec5b6c9cSMarc-André Lureau } 153*ec5b6c9cSMarc-André Lureau 154*ec5b6c9cSMarc-André Lureau return 0; 155*ec5b6c9cSMarc-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 184*ec5b6c9cSMarc-André Lureau #ifdef WIN32 185*ec5b6c9cSMarc-André Lureau static bool win32_fd_poll(int fd, gushort events) 186*ec5b6c9cSMarc-André Lureau { 187*ec5b6c9cSMarc-André Lureau GPollFD pfd = { .fd = _get_osfhandle(fd), .events = events }; 188*ec5b6c9cSMarc-André Lureau int res; 189*ec5b6c9cSMarc-André Lureau 190*ec5b6c9cSMarc-André Lureau do { 191*ec5b6c9cSMarc-André Lureau res = g_poll(&pfd, 1, 0); 192*ec5b6c9cSMarc-André Lureau } while (res < 0 && errno == EINTR); 193*ec5b6c9cSMarc-André Lureau if (res == 0) { 194*ec5b6c9cSMarc-André Lureau return false; 195*ec5b6c9cSMarc-André Lureau } 196*ec5b6c9cSMarc-André Lureau 197*ec5b6c9cSMarc-André Lureau return true; 198*ec5b6c9cSMarc-André Lureau } 199*ec5b6c9cSMarc-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, 206195e14d0SDaniel P. Berrange Error **errp) 207195e14d0SDaniel P. Berrange { 208195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 209195e14d0SDaniel P. Berrange ssize_t ret; 210195e14d0SDaniel P. Berrange 211*ec5b6c9cSMarc-André Lureau #ifdef WIN32 212*ec5b6c9cSMarc-André Lureau if (!cioc->blocking && !win32_fd_poll(cioc->readfd, G_IO_IN)) { 213*ec5b6c9cSMarc-André Lureau return QIO_CHANNEL_ERR_BLOCK; 214*ec5b6c9cSMarc-André Lureau } 215*ec5b6c9cSMarc-André Lureau #endif 216*ec5b6c9cSMarc-André Lureau 217195e14d0SDaniel P. Berrange retry: 218195e14d0SDaniel P. Berrange ret = readv(cioc->readfd, iov, niov); 219195e14d0SDaniel P. Berrange if (ret < 0) { 22030fd3e27SDaniel P. Berrange if (errno == EAGAIN) { 221195e14d0SDaniel P. Berrange return QIO_CHANNEL_ERR_BLOCK; 222195e14d0SDaniel P. Berrange } 223195e14d0SDaniel P. Berrange if (errno == EINTR) { 224195e14d0SDaniel P. Berrange goto retry; 225195e14d0SDaniel P. Berrange } 226195e14d0SDaniel P. Berrange 227195e14d0SDaniel P. Berrange error_setg_errno(errp, errno, 228195e14d0SDaniel P. Berrange "Unable to read from command"); 229195e14d0SDaniel P. Berrange return -1; 230195e14d0SDaniel P. Berrange } 231195e14d0SDaniel P. Berrange 232195e14d0SDaniel P. Berrange return ret; 233195e14d0SDaniel P. Berrange } 234195e14d0SDaniel P. Berrange 235195e14d0SDaniel P. Berrange static ssize_t qio_channel_command_writev(QIOChannel *ioc, 236195e14d0SDaniel P. Berrange const struct iovec *iov, 237195e14d0SDaniel P. Berrange size_t niov, 238195e14d0SDaniel P. Berrange int *fds, 239195e14d0SDaniel P. Berrange size_t nfds, 240b88651cbSLeonardo Bras int flags, 241195e14d0SDaniel P. Berrange Error **errp) 242195e14d0SDaniel P. Berrange { 243195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 244195e14d0SDaniel P. Berrange ssize_t ret; 245195e14d0SDaniel P. Berrange 246*ec5b6c9cSMarc-André Lureau #ifdef WIN32 247*ec5b6c9cSMarc-André Lureau if (!cioc->blocking && !win32_fd_poll(cioc->writefd, G_IO_OUT)) { 248*ec5b6c9cSMarc-André Lureau return QIO_CHANNEL_ERR_BLOCK; 249*ec5b6c9cSMarc-André Lureau } 250*ec5b6c9cSMarc-André Lureau #endif 251*ec5b6c9cSMarc-André Lureau 252195e14d0SDaniel P. Berrange retry: 253195e14d0SDaniel P. Berrange ret = writev(cioc->writefd, iov, niov); 254195e14d0SDaniel P. Berrange if (ret <= 0) { 25530fd3e27SDaniel P. Berrange if (errno == EAGAIN) { 256195e14d0SDaniel P. Berrange return QIO_CHANNEL_ERR_BLOCK; 257195e14d0SDaniel P. Berrange } 258195e14d0SDaniel P. Berrange if (errno == EINTR) { 259195e14d0SDaniel P. Berrange goto retry; 260195e14d0SDaniel P. Berrange } 261195e14d0SDaniel P. Berrange error_setg_errno(errp, errno, "%s", 262195e14d0SDaniel P. Berrange "Unable to write to command"); 263195e14d0SDaniel P. Berrange return -1; 264195e14d0SDaniel P. Berrange } 265195e14d0SDaniel P. Berrange return ret; 266195e14d0SDaniel P. Berrange } 267195e14d0SDaniel P. Berrange 268195e14d0SDaniel P. Berrange static int qio_channel_command_set_blocking(QIOChannel *ioc, 269195e14d0SDaniel P. Berrange bool enabled, 270195e14d0SDaniel P. Berrange Error **errp) 271195e14d0SDaniel P. Berrange { 272195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 273195e14d0SDaniel P. Berrange 274*ec5b6c9cSMarc-André Lureau #ifdef WIN32 275*ec5b6c9cSMarc-André Lureau cioc->blocking = enabled; 276*ec5b6c9cSMarc-André Lureau #else 277*ec5b6c9cSMarc-André Lureau 278*ec5b6c9cSMarc-André Lureau if ((cioc->writefd >= 0 && !g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL)) || 279*ec5b6c9cSMarc-André Lureau (cioc->readfd >= 0 && !g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL))) { 28017fc1245SMarc-André Lureau error_setg_errno(errp, errno, "Failed to set FD nonblocking"); 28117fc1245SMarc-André Lureau return -1; 282195e14d0SDaniel P. Berrange } 28317fc1245SMarc-André Lureau #endif 284195e14d0SDaniel P. Berrange return 0; 285195e14d0SDaniel P. Berrange } 286195e14d0SDaniel P. Berrange 287195e14d0SDaniel P. Berrange 288195e14d0SDaniel P. Berrange static int qio_channel_command_close(QIOChannel *ioc, 289195e14d0SDaniel P. Berrange Error **errp) 290195e14d0SDaniel P. Berrange { 291195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 292195e14d0SDaniel P. Berrange int rv = 0; 293fe823b6fSThomas Huth #ifndef WIN32 294fe823b6fSThomas Huth pid_t wp; 295fe823b6fSThomas Huth #endif 296195e14d0SDaniel P. Berrange 297195e14d0SDaniel P. Berrange /* We close FDs before killing, because that 298195e14d0SDaniel P. Berrange * gives a better chance of clean shutdown 299195e14d0SDaniel P. Berrange */ 300e155494cSDaniel P. Berrange if (cioc->readfd != -1 && 301e155494cSDaniel P. Berrange close(cioc->readfd) < 0) { 302195e14d0SDaniel P. Berrange rv = -1; 303195e14d0SDaniel P. Berrange } 304e155494cSDaniel P. Berrange if (cioc->writefd != -1 && 305e155494cSDaniel P. Berrange cioc->writefd != cioc->readfd && 306e155494cSDaniel P. Berrange close(cioc->writefd) < 0) { 307195e14d0SDaniel P. Berrange rv = -1; 308195e14d0SDaniel P. Berrange } 309e155494cSDaniel P. Berrange cioc->writefd = cioc->readfd = -1; 310fe823b6fSThomas Huth 311195e14d0SDaniel P. Berrange #ifndef WIN32 312fe823b6fSThomas Huth do { 313fe823b6fSThomas Huth wp = waitpid(cioc->pid, NULL, 0); 314fe823b6fSThomas Huth } while (wp == (pid_t)-1 && errno == EINTR); 315fe823b6fSThomas Huth if (wp == (pid_t)-1) { 316fe823b6fSThomas Huth error_setg_errno(errp, errno, "Failed to wait for pid %llu", 317fe823b6fSThomas Huth (unsigned long long)cioc->pid); 318195e14d0SDaniel P. Berrange return -1; 319195e14d0SDaniel P. Berrange } 320*ec5b6c9cSMarc-André Lureau #else 321*ec5b6c9cSMarc-André Lureau WaitForSingleObject(cioc->pid, INFINITE); 322195e14d0SDaniel P. Berrange #endif 323fe823b6fSThomas Huth 324195e14d0SDaniel P. Berrange if (rv < 0) { 325195e14d0SDaniel P. Berrange error_setg_errno(errp, errno, "%s", 326195e14d0SDaniel P. Berrange "Unable to close command"); 327195e14d0SDaniel P. Berrange } 328195e14d0SDaniel P. Berrange return rv; 329195e14d0SDaniel P. Berrange } 330195e14d0SDaniel P. Berrange 331195e14d0SDaniel P. Berrange 332bf88c124SPaolo Bonzini static void qio_channel_command_set_aio_fd_handler(QIOChannel *ioc, 333bf88c124SPaolo Bonzini AioContext *ctx, 334bf88c124SPaolo Bonzini IOHandler *io_read, 335bf88c124SPaolo Bonzini IOHandler *io_write, 336bf88c124SPaolo Bonzini void *opaque) 337bf88c124SPaolo Bonzini { 338bf88c124SPaolo Bonzini QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 339826cc324SStefan Hajnoczi aio_set_fd_handler(ctx, cioc->readfd, false, 340826cc324SStefan Hajnoczi io_read, NULL, NULL, NULL, opaque); 341826cc324SStefan Hajnoczi aio_set_fd_handler(ctx, cioc->writefd, false, 342826cc324SStefan Hajnoczi NULL, io_write, NULL, NULL, opaque); 343bf88c124SPaolo Bonzini } 344bf88c124SPaolo Bonzini 345bf88c124SPaolo Bonzini 346195e14d0SDaniel P. Berrange static GSource *qio_channel_command_create_watch(QIOChannel *ioc, 347195e14d0SDaniel P. Berrange GIOCondition condition) 348195e14d0SDaniel P. Berrange { 349195e14d0SDaniel P. Berrange QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); 350195e14d0SDaniel P. Berrange return qio_channel_create_fd_pair_watch(ioc, 351195e14d0SDaniel P. Berrange cioc->readfd, 352195e14d0SDaniel P. Berrange cioc->writefd, 353195e14d0SDaniel P. Berrange condition); 354195e14d0SDaniel P. Berrange } 355195e14d0SDaniel P. Berrange 356195e14d0SDaniel P. Berrange 357195e14d0SDaniel P. Berrange static void qio_channel_command_class_init(ObjectClass *klass, 358195e14d0SDaniel P. Berrange void *class_data G_GNUC_UNUSED) 359195e14d0SDaniel P. Berrange { 360195e14d0SDaniel P. Berrange QIOChannelClass *ioc_klass = QIO_CHANNEL_CLASS(klass); 361195e14d0SDaniel P. Berrange 362195e14d0SDaniel P. Berrange ioc_klass->io_writev = qio_channel_command_writev; 363195e14d0SDaniel P. Berrange ioc_klass->io_readv = qio_channel_command_readv; 364195e14d0SDaniel P. Berrange ioc_klass->io_set_blocking = qio_channel_command_set_blocking; 365195e14d0SDaniel P. Berrange ioc_klass->io_close = qio_channel_command_close; 366195e14d0SDaniel P. Berrange ioc_klass->io_create_watch = qio_channel_command_create_watch; 367bf88c124SPaolo Bonzini ioc_klass->io_set_aio_fd_handler = qio_channel_command_set_aio_fd_handler; 368195e14d0SDaniel P. Berrange } 369195e14d0SDaniel P. Berrange 370195e14d0SDaniel P. Berrange static const TypeInfo qio_channel_command_info = { 371195e14d0SDaniel P. Berrange .parent = TYPE_QIO_CHANNEL, 372195e14d0SDaniel P. Berrange .name = TYPE_QIO_CHANNEL_COMMAND, 373195e14d0SDaniel P. Berrange .instance_size = sizeof(QIOChannelCommand), 374195e14d0SDaniel P. Berrange .instance_init = qio_channel_command_init, 375195e14d0SDaniel P. Berrange .instance_finalize = qio_channel_command_finalize, 376195e14d0SDaniel P. Berrange .class_init = qio_channel_command_class_init, 377195e14d0SDaniel P. Berrange }; 378195e14d0SDaniel P. Berrange 379195e14d0SDaniel P. Berrange static void qio_channel_command_register_types(void) 380195e14d0SDaniel P. Berrange { 381195e14d0SDaniel P. Berrange type_register_static(&qio_channel_command_info); 382195e14d0SDaniel P. Berrange } 383195e14d0SDaniel P. Berrange 384195e14d0SDaniel P. Berrange type_init(qio_channel_command_register_types); 385