2 * Copyright (C) 2015 Red Hat, Inc.
4 * This file is part of the device-mapper multipath userspace tools.
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
22 #ifndef LIB_MPATH_CMD_H
23 #define LIB_MPATH_CMD_H
29 #define DEFAULT_SOCKET "/org/kernel/linux/storage/multipathd"
30 #define DEFAULT_REPLY_TIMEOUT 1000
31 #define MAX_REPLY_LEN 65536
36 * Connect to the running multipathd daemon. On systems with the
37 * multipathd.socket systemd unit file installed, this command will
38 * start multipathd if it is not already running. This function
39 * must be run before any of the others in this library
42 * A file descriptor on success. -1 on failure (with errno set).
44 int mpath_connect(void);
49 * Disconnect from the multipathd daemon. This function must be
50 * run after after processing all the multipath commands.
53 * 0 on success. -1 on failure (with errno set).
55 int mpath_disconnect(int fd);
60 * Send multipathd a command and return the reply. This function
61 * does the same as calling mpath_send_cmd() and then
65 * 0 on successs, and reply will either be NULL (if there was no
66 * reply data), or point to the reply string, which must be freed by
67 * the caller. -1 on failure (with errno set).
69 int mpath_process_cmd(int fd, const char *cmd, char **reply,
70 unsigned int timeout);
75 * Send a command to multipathd
78 * 0 on success. -1 on failure (with errno set)
80 int mpath_send_cmd(int fd, const char *cmd);
85 * Return a reply from multipathd for a previously sent command.
86 * This is equivalent to calling mpath_recv_reply_len(), allocating
87 * a buffer of the appropriate size, and then calling
88 * mpath_recv_reply_data() with that buffer.
91 * 0 on success, and reply will either be NULL (if there was no
92 * reply data), or point to the reply string, which must be freed by
93 * the caller, -1 on failure (with errno set).
95 int mpath_recv_reply(int fd, char **reply, unsigned int timeout);
100 * Return the size of the upcoming reply data from the sent multipath
101 * command. This must be called before calling mpath_recv_reply_data().
104 * The required size of the reply data buffer on success. -1 on
105 * failure (with errno set).
107 ssize_t mpath_recv_reply_len(int fd, unsigned int timeout);
112 * Return the reply data from the sent multipath command.
113 * mpath_recv_reply_len must be called first. reply must point to a
114 * buffer of len size.
117 * 0 on success, and reply will contain the reply data string. -1
118 * on failure (with errno set).
120 int mpath_recv_reply_data(int fd, char *reply, size_t len,
121 unsigned int timeout);
126 #endif /* LIB_MPATH_CMD_H */