xref: /openbmc/qemu/include/io/channel-command.h (revision db1015e92e04835c9eb50c29625fe566d1202dbd)
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
9195e14d0SDaniel P. Berrange  * version 2 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 
212a6a4076SMarkus Armbruster #ifndef QIO_CHANNEL_COMMAND_H
222a6a4076SMarkus Armbruster #define QIO_CHANNEL_COMMAND_H
23195e14d0SDaniel P. Berrange 
24195e14d0SDaniel P. Berrange #include "io/channel.h"
25*db1015e9SEduardo Habkost #include "qom/object.h"
26195e14d0SDaniel P. Berrange 
27195e14d0SDaniel P. Berrange #define TYPE_QIO_CHANNEL_COMMAND "qio-channel-command"
28*db1015e9SEduardo Habkost typedef struct QIOChannelCommand QIOChannelCommand;
29195e14d0SDaniel P. Berrange #define QIO_CHANNEL_COMMAND(obj)                                     \
30195e14d0SDaniel P. Berrange     OBJECT_CHECK(QIOChannelCommand, (obj), TYPE_QIO_CHANNEL_COMMAND)
31195e14d0SDaniel P. Berrange 
32195e14d0SDaniel P. Berrange 
33195e14d0SDaniel P. Berrange 
34195e14d0SDaniel P. Berrange /**
35195e14d0SDaniel P. Berrange  * QIOChannelCommand:
36195e14d0SDaniel P. Berrange  *
37195e14d0SDaniel P. Berrange  * The QIOChannelCommand class provides a channel implementation
38195e14d0SDaniel P. Berrange  * that can transport data with an externally running command
39195e14d0SDaniel P. Berrange  * via its stdio streams.
40195e14d0SDaniel P. Berrange  */
41195e14d0SDaniel P. Berrange 
42195e14d0SDaniel P. Berrange struct QIOChannelCommand {
43195e14d0SDaniel P. Berrange     QIOChannel parent;
44195e14d0SDaniel P. Berrange     int writefd;
45195e14d0SDaniel P. Berrange     int readfd;
46195e14d0SDaniel P. Berrange     pid_t pid;
47195e14d0SDaniel P. Berrange };
48195e14d0SDaniel P. Berrange 
49195e14d0SDaniel P. Berrange 
50195e14d0SDaniel P. Berrange /**
51195e14d0SDaniel P. Berrange  * qio_channel_command_new_pid:
52195e14d0SDaniel P. Berrange  * @writefd: the FD connected to the command's stdin
53195e14d0SDaniel P. Berrange  * @readfd: the FD connected to the command's stdout
54195e14d0SDaniel P. Berrange  * @pid: the PID of the running child command
55821791b5SDaniel P. Berrange  * @errp: pointer to a NULL-initialized error object
56195e14d0SDaniel P. Berrange  *
57195e14d0SDaniel P. Berrange  * Create a channel for performing I/O with the
58195e14d0SDaniel P. Berrange  * previously spawned command identified by @pid.
59195e14d0SDaniel P. Berrange  * The two file descriptors provide the connection
60195e14d0SDaniel P. Berrange  * to command's stdio streams, either one or which
61195e14d0SDaniel P. Berrange  * may be -1 to indicate that stream is not open.
62195e14d0SDaniel P. Berrange  *
63195e14d0SDaniel P. Berrange  * The channel will take ownership of the process
64195e14d0SDaniel P. Berrange  * @pid and will kill it when closing the channel.
65195e14d0SDaniel P. Berrange  * Similarly it will take responsibility for
66195e14d0SDaniel P. Berrange  * closing the file descriptors @writefd and @readfd.
67195e14d0SDaniel P. Berrange  *
68195e14d0SDaniel P. Berrange  * Returns: the command channel object, or NULL on error
69195e14d0SDaniel P. Berrange  */
70195e14d0SDaniel P. Berrange QIOChannelCommand *
71195e14d0SDaniel P. Berrange qio_channel_command_new_pid(int writefd,
72195e14d0SDaniel P. Berrange                             int readfd,
73195e14d0SDaniel P. Berrange                             pid_t pid);
74195e14d0SDaniel P. Berrange 
75195e14d0SDaniel P. Berrange /**
76195e14d0SDaniel P. Berrange  * qio_channel_command_new_spawn:
77195e14d0SDaniel P. Berrange  * @argv: the NULL terminated list of command arguments
78195e14d0SDaniel P. Berrange  * @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR
79821791b5SDaniel P. Berrange  * @errp: pointer to a NULL-initialized error object
80195e14d0SDaniel P. Berrange  *
81195e14d0SDaniel P. Berrange  * Create a channel for performing I/O with the
82195e14d0SDaniel P. Berrange  * command to be spawned with arguments @argv.
83195e14d0SDaniel P. Berrange  *
84195e14d0SDaniel P. Berrange  * Returns: the command channel object, or NULL on error
85195e14d0SDaniel P. Berrange  */
86195e14d0SDaniel P. Berrange QIOChannelCommand *
87195e14d0SDaniel P. Berrange qio_channel_command_new_spawn(const char *const argv[],
88195e14d0SDaniel P. Berrange                               int flags,
89195e14d0SDaniel P. Berrange                               Error **errp);
90195e14d0SDaniel P. Berrange 
91195e14d0SDaniel P. Berrange 
922a6a4076SMarkus Armbruster #endif /* QIO_CHANNEL_COMMAND_H */
93