Imported Upstream version 0.6.4
[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
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 #ifdef __cpluscplus
24 extern "C" {
25 #endif
26
27 #define DEFAULT_SOCKET          "/org/kernel/linux/storage/multipathd"
28 #define DEFAULT_REPLY_TIMEOUT   1000
29 #define MAX_REPLY_LEN           65536
30
31
32 /*
33  * DESCRIPTION:
34  *      Connect to the running multipathd daemon. On systems with the
35  *      multipathd.socket systemd unit file installed, this command will
36  *      start multipathd if it is not already running. This function
37  *      must be run before any of the others in this library
38  *
39  * RETURNS:
40  *      A file descriptor on success. -1 on failure (with errno set).
41  */
42 int mpath_connect(void);
43
44
45 /*
46  * DESCRIPTION:
47  *      Disconnect from the multipathd daemon. This function must be
48  *      run after after processing all the multipath commands.
49  *
50  * RETURNS:
51  *      0 on success. -1 on failure (with errno set).
52  */
53 int mpath_disconnect(int fd);
54
55
56 /*
57  * DESCRIPTION
58  *      Send multipathd a command and return the reply. This function
59  *      does the same as calling mpath_send_cmd() and then
60  *      mpath_recv_reply()
61  *
62  * RETURNS:
63  *      0 on successs, and reply will either be NULL (if there was no
64  *      reply data), or point to the reply string, which must be freed by
65  *      the caller. -1 on failure (with errno set).
66  */
67 int mpath_process_cmd(int fd, const char *cmd, char **reply,
68                       unsigned int timeout);
69
70
71 /*
72  * DESCRIPTION:
73  *      Send a command to multipathd
74  *
75  * RETURNS:
76  *      0 on success. -1 on failure (with errno set)
77  */
78 int mpath_send_cmd(int fd, const char *cmd);
79
80
81 /*
82  * DESCRIPTION:
83  *      Return a reply from multipathd for a previously sent command.
84  *      This is equivalent to calling mpath_recv_reply_len(), allocating
85  *      a buffer of the appropriate size, and then calling
86  *      mpath_recv_reply_data() with that buffer.
87  *
88  * RETURNS:
89  *      0 on success, and reply will either be NULL (if there was no
90  *      reply data), or point to the reply string, which must be freed by
91  *      the caller, -1 on failure (with errno set).
92  */
93 int mpath_recv_reply(int fd, char **reply, unsigned int timeout);
94
95
96 /*
97  * DESCRIPTION:
98  *      Return the size of the upcoming reply data from the sent multipath
99  *      command. This must be called before calling mpath_recv_reply_data().
100  *
101  * RETURNS:
102  *      The required size of the reply data buffer on success. -1 on
103  *      failure (with errno set).
104  */
105 ssize_t mpath_recv_reply_len(int fd, unsigned int timeout);
106
107
108 /*
109  * DESCRIPTION:
110  *      Return the reply data from the sent multipath command.
111  *      mpath_recv_reply_len must be called first. reply must point to a
112  *      buffer of len size.
113  *
114  * RETURNS:
115  *      0 on success, and reply will contain the reply data string. -1
116  *      on failure (with errno set).
117  */
118 int mpath_recv_reply_data(int fd, char *reply, size_t len,
119                           unsigned int timeout);
120
121 #ifdef __cplusplus
122 }
123 #endif
124 #endif /* LIB_MPATH_CMD_H */