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