Imported Upstream version 0.8.9
[platform/upstream/multipath-tools.git] / libmpathcmd / mpath_cmd.h
1 /*
2  * Copyright (C) 2015 Red Hat, Inc.
3  *
4  * This file is part of the device-mapper multipath userspace tools.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef LIB_MPATH_CMD_H
21 #define LIB_MPATH_CMD_H
22
23 /*
24  * This should be sufficient for json output for >10000 maps,
25  * and >60000 paths.
26  */
27 #define MAX_REPLY_LEN (32 * 1024 * 1024)
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define DEFAULT_SOCKET          "/org/kernel/linux/storage/multipathd"
34 #define DEFAULT_REPLY_TIMEOUT   4000
35
36
37 /*
38  * DESCRIPTION:
39  *      Same as mpath_connect() (see below) except for the "nonblocking"
40  *      parameter.
41  *      If "nonblocking" is set, connects in non-blocking mode. This is
42  *      useful to avoid blocking if the listening socket's backlog is
43  *      exceeded. In this case, errno will be set to EAGAIN.
44  *      In case of success, the returned file descriptor is in in blocking
45  *      mode, even if "nonblocking" was true.
46  *
47  * RETURNS:
48  *      A file descriptor on success. -1 on failure (with errno set).
49  */
50 int __mpath_connect(int nonblocking);
51
52 /*
53  * DESCRIPTION:
54  *      Connect to the running multipathd daemon. On systems with the
55  *      multipathd.socket systemd unit file installed, this command will
56  *      start multipathd if it is not already running. This function
57  *      must be run before any of the others in this library
58  *
59  * RETURNS:
60  *      A file descriptor on success. -1 on failure (with errno set).
61  */
62 int mpath_connect(void);
63
64
65 /*
66  * DESCRIPTION:
67  *      Disconnect from the multipathd daemon. This function must be
68  *      run after after processing all the multipath commands.
69  *
70  * RETURNS:
71  *      0 on success. -1 on failure (with errno set).
72  */
73 int mpath_disconnect(int fd);
74
75
76 /*
77  * DESCRIPTION
78  *      Send multipathd a command and return the reply. This function
79  *      does the same as calling mpath_send_cmd() and then
80  *      mpath_recv_reply()
81  *
82  * RETURNS:
83  *      0 on success, and reply will either be NULL (if there was no
84  *      reply data), or point to the reply string, which must be freed by
85  *      the caller. -1 on failure (with errno set).
86  */
87 int mpath_process_cmd(int fd, const char *cmd, char **reply,
88                       unsigned int timeout);
89
90
91 /*
92  * DESCRIPTION:
93  *      Send a command to multipathd
94  *
95  * RETURNS:
96  *      0 on success. -1 on failure (with errno set)
97  */
98 int mpath_send_cmd(int fd, const char *cmd);
99
100
101 /*
102  * DESCRIPTION:
103  *      Return a reply from multipathd for a previously sent command.
104  *      This is equivalent to calling mpath_recv_reply_len(), allocating
105  *      a buffer of the appropriate size, and then calling
106  *      mpath_recv_reply_data() with that buffer.
107  *
108  * RETURNS:
109  *      0 on success, and reply will either be NULL (if there was no
110  *      reply data), or point to the reply string, which must be freed by
111  *      the caller, -1 on failure (with errno set).
112  */
113 int mpath_recv_reply(int fd, char **reply, unsigned int timeout);
114
115
116 /*
117  * DESCRIPTION:
118  *      Return the size of the upcoming reply data from the sent multipath
119  *      command. This must be called before calling mpath_recv_reply_data().
120  *
121  * RETURNS:
122  *      The required size of the reply data buffer on success. -1 on
123  *      failure (with errno set).
124  */
125 ssize_t mpath_recv_reply_len(int fd, unsigned int timeout);
126
127
128 /*
129  * DESCRIPTION:
130  *      Return the reply data from the sent multipath command.
131  *      mpath_recv_reply_len must be called first. reply must point to a
132  *      buffer of len size.
133  *
134  * RETURNS:
135  *      0 on success, and reply will contain the reply data string. -1
136  *      on failure (with errno set).
137  */
138 int mpath_recv_reply_data(int fd, char *reply, size_t len,
139                           unsigned int timeout);
140
141 #ifdef __cplusplus
142 }
143 #endif
144 #endif /* LIB_MPATH_CMD_H */