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