mpath_cmd.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #ifndef LIB_MPATH_CMD_H
  20. #define LIB_MPATH_CMD_H
  21. /*
  22. * This should be sufficient for json output for >10000 maps,
  23. * and >60000 paths.
  24. */
  25. #define MAX_REPLY_LEN (32 * 1024 * 1024)
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define DEFAULT_SOCKET "/org/kernel/linux/storage/multipathd"
  30. #define DEFAULT_REPLY_TIMEOUT 4000
  31. /*
  32. * DESCRIPTION:
  33. * Same as mpath_connect() (see below) except for the "nonblocking"
  34. * parameter.
  35. * If "nonblocking" is set, connects in non-blocking mode. This is
  36. * useful to avoid blocking if the listening socket's backlog is
  37. * exceeded. In this case, errno will be set to EAGAIN.
  38. * In case of success, the returned file descriptor is in in blocking
  39. * mode, even if "nonblocking" was true.
  40. *
  41. * RETURNS:
  42. * A file descriptor on success. -1 on failure (with errno set).
  43. */
  44. int __mpath_connect(int nonblocking);
  45. /*
  46. * DESCRIPTION:
  47. * Connect to the running multipathd daemon. On systems with the
  48. * multipathd.socket systemd unit file installed, this command will
  49. * start multipathd if it is not already running. This function
  50. * must be run before any of the others in this library
  51. *
  52. * RETURNS:
  53. * A file descriptor on success. -1 on failure (with errno set).
  54. */
  55. int mpath_connect(void);
  56. /*
  57. * DESCRIPTION:
  58. * Disconnect from the multipathd daemon. This function must be
  59. * run after after processing all the multipath commands.
  60. *
  61. * RETURNS:
  62. * 0 on success. -1 on failure (with errno set).
  63. */
  64. int mpath_disconnect(int fd);
  65. /*
  66. * DESCRIPTION
  67. * Send multipathd a command and return the reply. This function
  68. * does the same as calling mpath_send_cmd() and then
  69. * mpath_recv_reply()
  70. *
  71. * RETURNS:
  72. * 0 on successs, and reply will either be NULL (if there was no
  73. * reply data), or point to the reply string, which must be freed by
  74. * the caller. -1 on failure (with errno set).
  75. */
  76. int mpath_process_cmd(int fd, const char *cmd, char **reply,
  77. unsigned int timeout);
  78. /*
  79. * DESCRIPTION:
  80. * Send a command to multipathd
  81. *
  82. * RETURNS:
  83. * 0 on success. -1 on failure (with errno set)
  84. */
  85. int mpath_send_cmd(int fd, const char *cmd);
  86. /*
  87. * DESCRIPTION:
  88. * Return a reply from multipathd for a previously sent command.
  89. * This is equivalent to calling mpath_recv_reply_len(), allocating
  90. * a buffer of the appropriate size, and then calling
  91. * mpath_recv_reply_data() with that buffer.
  92. *
  93. * RETURNS:
  94. * 0 on success, and reply will either be NULL (if there was no
  95. * reply data), or point to the reply string, which must be freed by
  96. * the caller, -1 on failure (with errno set).
  97. */
  98. int mpath_recv_reply(int fd, char **reply, unsigned int timeout);
  99. /*
  100. * DESCRIPTION:
  101. * Return the size of the upcoming reply data from the sent multipath
  102. * command. This must be called before calling mpath_recv_reply_data().
  103. *
  104. * RETURNS:
  105. * The required size of the reply data buffer on success. -1 on
  106. * failure (with errno set).
  107. */
  108. ssize_t mpath_recv_reply_len(int fd, unsigned int timeout);
  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. #ifdef __cplusplus
  122. }
  123. #endif
  124. #endif /* LIB_MPATH_CMD_H */