1*195e14d0SDaniel P. Berrange /* 2*195e14d0SDaniel P. Berrange * QEMU I/O channels external command driver 3*195e14d0SDaniel P. Berrange * 4*195e14d0SDaniel P. Berrange * Copyright (c) 2015 Red Hat, Inc. 5*195e14d0SDaniel P. Berrange * 6*195e14d0SDaniel P. Berrange * This library is free software; you can redistribute it and/or 7*195e14d0SDaniel P. Berrange * modify it under the terms of the GNU Lesser General Public 8*195e14d0SDaniel P. Berrange * License as published by the Free Software Foundation; either 9*195e14d0SDaniel P. Berrange * version 2 of the License, or (at your option) any later version. 10*195e14d0SDaniel P. Berrange * 11*195e14d0SDaniel P. Berrange * This library is distributed in the hope that it will be useful, 12*195e14d0SDaniel P. Berrange * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*195e14d0SDaniel P. Berrange * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14*195e14d0SDaniel P. Berrange * Lesser General Public License for more details. 15*195e14d0SDaniel P. Berrange * 16*195e14d0SDaniel P. Berrange * You should have received a copy of the GNU Lesser General Public 17*195e14d0SDaniel P. Berrange * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18*195e14d0SDaniel P. Berrange * 19*195e14d0SDaniel P. Berrange */ 20*195e14d0SDaniel P. Berrange 21*195e14d0SDaniel P. Berrange #ifndef QIO_CHANNEL_COMMAND_H__ 22*195e14d0SDaniel P. Berrange #define QIO_CHANNEL_COMMAND_H__ 23*195e14d0SDaniel P. Berrange 24*195e14d0SDaniel P. Berrange #include "io/channel.h" 25*195e14d0SDaniel P. Berrange 26*195e14d0SDaniel P. Berrange #define TYPE_QIO_CHANNEL_COMMAND "qio-channel-command" 27*195e14d0SDaniel P. Berrange #define QIO_CHANNEL_COMMAND(obj) \ 28*195e14d0SDaniel P. Berrange OBJECT_CHECK(QIOChannelCommand, (obj), TYPE_QIO_CHANNEL_COMMAND) 29*195e14d0SDaniel P. Berrange 30*195e14d0SDaniel P. Berrange typedef struct QIOChannelCommand QIOChannelCommand; 31*195e14d0SDaniel P. Berrange 32*195e14d0SDaniel P. Berrange 33*195e14d0SDaniel P. Berrange /** 34*195e14d0SDaniel P. Berrange * QIOChannelCommand: 35*195e14d0SDaniel P. Berrange * 36*195e14d0SDaniel P. Berrange * The QIOChannelCommand class provides a channel implementation 37*195e14d0SDaniel P. Berrange * that can transport data with an externally running command 38*195e14d0SDaniel P. Berrange * via its stdio streams. 39*195e14d0SDaniel P. Berrange */ 40*195e14d0SDaniel P. Berrange 41*195e14d0SDaniel P. Berrange struct QIOChannelCommand { 42*195e14d0SDaniel P. Berrange QIOChannel parent; 43*195e14d0SDaniel P. Berrange int writefd; 44*195e14d0SDaniel P. Berrange int readfd; 45*195e14d0SDaniel P. Berrange pid_t pid; 46*195e14d0SDaniel P. Berrange }; 47*195e14d0SDaniel P. Berrange 48*195e14d0SDaniel P. Berrange 49*195e14d0SDaniel P. Berrange /** 50*195e14d0SDaniel P. Berrange * qio_channel_command_new_pid: 51*195e14d0SDaniel P. Berrange * @writefd: the FD connected to the command's stdin 52*195e14d0SDaniel P. Berrange * @readfd: the FD connected to the command's stdout 53*195e14d0SDaniel P. Berrange * @pid: the PID of the running child command 54*195e14d0SDaniel P. Berrange * @errp: pointer to an uninitialized error object 55*195e14d0SDaniel P. Berrange * 56*195e14d0SDaniel P. Berrange * Create a channel for performing I/O with the 57*195e14d0SDaniel P. Berrange * previously spawned command identified by @pid. 58*195e14d0SDaniel P. Berrange * The two file descriptors provide the connection 59*195e14d0SDaniel P. Berrange * to command's stdio streams, either one or which 60*195e14d0SDaniel P. Berrange * may be -1 to indicate that stream is not open. 61*195e14d0SDaniel P. Berrange * 62*195e14d0SDaniel P. Berrange * The channel will take ownership of the process 63*195e14d0SDaniel P. Berrange * @pid and will kill it when closing the channel. 64*195e14d0SDaniel P. Berrange * Similarly it will take responsibility for 65*195e14d0SDaniel P. Berrange * closing the file descriptors @writefd and @readfd. 66*195e14d0SDaniel P. Berrange * 67*195e14d0SDaniel P. Berrange * Returns: the command channel object, or NULL on error 68*195e14d0SDaniel P. Berrange */ 69*195e14d0SDaniel P. Berrange QIOChannelCommand * 70*195e14d0SDaniel P. Berrange qio_channel_command_new_pid(int writefd, 71*195e14d0SDaniel P. Berrange int readfd, 72*195e14d0SDaniel P. Berrange pid_t pid); 73*195e14d0SDaniel P. Berrange 74*195e14d0SDaniel P. Berrange /** 75*195e14d0SDaniel P. Berrange * qio_channel_command_new_spawn: 76*195e14d0SDaniel P. Berrange * @argv: the NULL terminated list of command arguments 77*195e14d0SDaniel P. Berrange * @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR 78*195e14d0SDaniel P. Berrange * @errp: pointer to an uninitialized error object 79*195e14d0SDaniel P. Berrange * 80*195e14d0SDaniel P. Berrange * Create a channel for performing I/O with the 81*195e14d0SDaniel P. Berrange * command to be spawned with arguments @argv. 82*195e14d0SDaniel P. Berrange * 83*195e14d0SDaniel P. Berrange * Returns: the command channel object, or NULL on error 84*195e14d0SDaniel P. Berrange */ 85*195e14d0SDaniel P. Berrange QIOChannelCommand * 86*195e14d0SDaniel P. Berrange qio_channel_command_new_spawn(const char *const argv[], 87*195e14d0SDaniel P. Berrange int flags, 88*195e14d0SDaniel P. Berrange Error **errp); 89*195e14d0SDaniel P. Berrange 90*195e14d0SDaniel P. Berrange 91*195e14d0SDaniel P. Berrange #endif /* QIO_CHANNEL_COMMAND_H__ */ 92