qdevice-advanced-settings.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * Copyright (c) 2015-2017 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Jan Friesse (jfriesse@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the Red Hat, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdlib.h>
  35. #include <errno.h>
  36. #include <limits.h>
  37. #include <string.h>
  38. #include "dynar.h"
  39. #include "dynar-getopt-lex.h"
  40. #include "dynar-str.h"
  41. #include "qdevice-config.h"
  42. #include "qnet-config.h"
  43. #include "qdevice-advanced-settings.h"
  44. #include "utils.h"
  45. int
  46. qdevice_advanced_settings_init(struct qdevice_advanced_settings *settings)
  47. {
  48. memset(settings, 0, sizeof(*settings));
  49. if ((settings->lock_file = strdup(QDEVICE_DEFAULT_LOCK_FILE)) == NULL) {
  50. return (-1);
  51. }
  52. if ((settings->local_socket_file = strdup(QDEVICE_DEFAULT_LOCAL_SOCKET_FILE)) == NULL) {
  53. return (-1);
  54. }
  55. settings->local_socket_backlog = QDEVICE_DEFAULT_LOCAL_SOCKET_BACKLOG;
  56. settings->max_cs_try_again = QDEVICE_DEFAULT_MAX_CS_TRY_AGAIN;
  57. if ((settings->votequorum_device_name = strdup(QDEVICE_DEFAULT_VOTEQUORUM_DEVICE_NAME)) == NULL) {
  58. return (-1);
  59. }
  60. settings->ipc_max_clients = QDEVICE_DEFAULT_IPC_MAX_CLIENTS;
  61. settings->ipc_max_receive_size = QDEVICE_DEFAULT_IPC_MAX_RECEIVE_SIZE;
  62. settings->ipc_max_send_size = QDEVICE_DEFAULT_IPC_MAX_SEND_SIZE;
  63. settings->heuristics_ipc_max_send_buffers = QDEVICE_DEFAULT_HEURISTICS_IPC_MAX_SEND_BUFFERS;
  64. settings->heuristics_ipc_max_send_receive_size = QDEVICE_DEFAULT_HEURISTICS_IPC_MAX_SEND_RECEIVE_SIZE;
  65. settings->heuristics_min_timeout = QDEVICE_DEFAULT_HEURISTICS_MIN_TIMEOUT;
  66. settings->heuristics_max_timeout = QDEVICE_DEFAULT_HEURISTICS_MAX_TIMEOUT;
  67. settings->heuristics_min_interval = QDEVICE_DEFAULT_HEURISTICS_MIN_INTERVAL;
  68. settings->heuristics_max_interval = QDEVICE_DEFAULT_HEURISTICS_MAX_INTERVAL;
  69. settings->heuristics_max_execs = QDEVICE_DEFAULT_HEURISTICS_MAX_EXECS;
  70. settings->heuristics_use_execvp = QDEVICE_DEFAULT_HEURISTICS_USE_EXECVP;
  71. settings->heuristics_max_processes = QDEVICE_DEFAULT_HEURISTICS_MAX_PROCESSES;
  72. settings->heuristics_kill_list_interval = QDEVICE_DEFAULT_HEURISTICS_KILL_LIST_INTERVAL;
  73. if ((settings->net_nss_db_dir = strdup(QDEVICE_NET_DEFAULT_NSS_DB_DIR)) == NULL) {
  74. return (-1);
  75. }
  76. settings->net_initial_msg_receive_size = QDEVICE_NET_DEFAULT_INITIAL_MSG_RECEIVE_SIZE;
  77. settings->net_initial_msg_send_size = QDEVICE_NET_DEFAULT_INITIAL_MSG_SEND_SIZE;
  78. settings->net_min_msg_send_size = QDEVICE_NET_DEFAULT_MIN_MSG_SEND_SIZE;
  79. settings->net_max_msg_receive_size = QDEVICE_NET_DEFAULT_MAX_MSG_RECEIVE_SIZE;
  80. settings->net_max_send_buffers = QDEVICE_NET_DEFAULT_MAX_SEND_BUFFERS;
  81. if ((settings->net_nss_qnetd_cn = strdup(QDEVICE_NET_DEFAULT_NSS_QNETD_CN)) == NULL) {
  82. return (-1);
  83. }
  84. if ((settings->net_nss_client_cert_nickname =
  85. strdup(QDEVICE_NET_DEFAULT_NSS_CLIENT_CERT_NICKNAME)) == NULL) {
  86. return (-1);
  87. }
  88. settings->net_heartbeat_interval_min = QDEVICE_NET_DEFAULT_HEARTBEAT_INTERVAL_MIN;
  89. settings->net_heartbeat_interval_max = QDEVICE_NET_DEFAULT_HEARTBEAT_INTERVAL_MAX;
  90. settings->net_min_connect_timeout = QDEVICE_NET_DEFAULT_MIN_CONNECT_TIMEOUT;
  91. settings->net_max_connect_timeout = QDEVICE_NET_DEFAULT_MAX_CONNECT_TIMEOUT;
  92. settings->net_test_algorithm_enabled = QDEVICE_NET_DEFAULT_TEST_ALGORITHM_ENABLED;
  93. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_MODEL;
  94. return (0);
  95. }
  96. void
  97. qdevice_advanced_settings_destroy(struct qdevice_advanced_settings *settings)
  98. {
  99. free(settings->local_socket_file);
  100. free(settings->lock_file);
  101. free(settings->votequorum_device_name);
  102. free(settings->net_nss_db_dir);
  103. free(settings->net_nss_qnetd_cn);
  104. free(settings->net_nss_client_cert_nickname);
  105. }
  106. /*
  107. * 0 - No error
  108. * -1 - Unknown option
  109. * -2 - Incorrect value
  110. */
  111. int
  112. qdevice_advanced_settings_set(struct qdevice_advanced_settings *settings,
  113. const char *option, const char *value)
  114. {
  115. long long int tmpll;
  116. if (strcasecmp(option, "lock_file") == 0) {
  117. free(settings->lock_file);
  118. if ((settings->lock_file = strdup(value)) == NULL) {
  119. return (-1);
  120. }
  121. } else if (strcasecmp(option, "local_socket_file") == 0) {
  122. free(settings->local_socket_file);
  123. if ((settings->local_socket_file = strdup(value)) == NULL) {
  124. return (-1);
  125. }
  126. } else if (strcasecmp(option, "local_socket_backlog") == 0) {
  127. if (utils_strtonum(value, QDEVICE_MIN_LOCAL_SOCKET_BACKLOG, INT_MAX, &tmpll) == -1) {
  128. return (-2);
  129. }
  130. settings->local_socket_backlog = (int)tmpll;
  131. } else if (strcasecmp(option, "max_cs_try_again") == 0) {
  132. if (utils_strtonum(value, QDEVICE_MIN_MAX_CS_TRY_AGAIN, INT_MAX, &tmpll) == -1) {
  133. return (-2);
  134. }
  135. settings->max_cs_try_again = (int)tmpll;
  136. } else if (strcasecmp(option, "votequorum_device_name") == 0) {
  137. free(settings->votequorum_device_name);
  138. if ((settings->votequorum_device_name = strdup(value)) == NULL) {
  139. return (-1);
  140. }
  141. } else if (strcasecmp(option, "ipc_max_clients") == 0) {
  142. if (utils_strtonum(value, QDEVICE_MIN_IPC_MAX_CLIENTS, LLONG_MAX, &tmpll) == -1) {
  143. return (-2);
  144. }
  145. settings->ipc_max_clients = (size_t)tmpll;
  146. } else if (strcasecmp(option, "ipc_max_receive_size") == 0) {
  147. if (utils_strtonum(value, QDEVICE_MIN_IPC_RECEIVE_SEND_SIZE, LLONG_MAX,
  148. &tmpll) == -1) {
  149. return (-2);
  150. }
  151. settings->ipc_max_receive_size = (size_t)tmpll;
  152. } else if (strcasecmp(option, "ipc_max_send_size") == 0) {
  153. if (utils_strtonum(value, QDEVICE_MIN_IPC_RECEIVE_SEND_SIZE, LLONG_MAX,
  154. &tmpll) == -1) {
  155. return (-2);
  156. }
  157. settings->ipc_max_send_size = (size_t)tmpll;
  158. } else if (strcasecmp(option, "heuristics_ipc_max_send_buffers") == 0) {
  159. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_IPC_MAX_SEND_BUFFERS, LLONG_MAX,
  160. &tmpll) == -1) {
  161. return (-2);
  162. }
  163. settings->heuristics_ipc_max_send_buffers = (size_t)tmpll;
  164. } else if (strcasecmp(option, "heuristics_ipc_max_send_receive_size") == 0) {
  165. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_IPC_MAX_SEND_RECEIVE_SIZE, LLONG_MAX,
  166. &tmpll) == -1) {
  167. return (-2);
  168. }
  169. settings->heuristics_ipc_max_send_receive_size = (size_t)tmpll;
  170. } else if (strcasecmp(option, "heuristics_min_timeout") == 0) {
  171. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_TIMEOUT, UINT32_MAX,
  172. &tmpll) == -1) {
  173. return (-2);
  174. }
  175. settings->heuristics_min_timeout = (uint32_t)tmpll;
  176. } else if (strcasecmp(option, "heuristics_max_timeout") == 0) {
  177. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_TIMEOUT, UINT32_MAX,
  178. &tmpll) == -1) {
  179. return (-2);
  180. }
  181. settings->heuristics_max_timeout = (uint32_t)tmpll;
  182. } else if (strcasecmp(option, "heuristics_min_interval") == 0) {
  183. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_INTERVAL, UINT32_MAX,
  184. &tmpll) == -1) {
  185. return (-2);
  186. }
  187. settings->heuristics_min_interval = (uint32_t)tmpll;
  188. } else if (strcasecmp(option, "heuristics_max_interval") == 0) {
  189. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_INTERVAL, UINT32_MAX,
  190. &tmpll) == -1) {
  191. return (-2);
  192. }
  193. settings->heuristics_max_interval = (uint32_t)tmpll;
  194. } else if (strcasecmp(option, "heuristics_max_execs") == 0) {
  195. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_MAX_EXECS, LLONG_MAX,
  196. &tmpll) == -1) {
  197. return (-2);
  198. }
  199. settings->heuristics_max_execs = (size_t)tmpll;
  200. } else if (strcasecmp(option, "heuristics_use_execvp") == 0) {
  201. if ((tmpll = utils_parse_bool_str(value)) == -1) {
  202. return (-2);
  203. }
  204. settings->heuristics_use_execvp = (uint8_t)tmpll;
  205. } else if (strcasecmp(option, "heuristics_max_processes") == 0) {
  206. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_MAX_PROCESSES, LLONG_MAX,
  207. &tmpll) == -1) {
  208. return (-2);
  209. }
  210. settings->heuristics_max_processes = (size_t)tmpll;
  211. } else if (strcasecmp(option, "heuristics_kill_list_interval") == 0) {
  212. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_KILL_LIST_INTERVAL, UINT32_MAX,
  213. &tmpll) == -1) {
  214. return (-2);
  215. }
  216. settings->heuristics_kill_list_interval = (uint32_t)tmpll;
  217. } else if (strcasecmp(option, "net_nss_db_dir") == 0) {
  218. free(settings->net_nss_db_dir);
  219. if ((settings->net_nss_db_dir = strdup(value)) == NULL) {
  220. return (-1);
  221. }
  222. } else if (strcasecmp(option, "net_initial_msg_receive_size") == 0) {
  223. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  224. &tmpll) == -1) {
  225. return (-2);
  226. }
  227. settings->net_initial_msg_receive_size = (size_t)tmpll;
  228. } else if (strcasecmp(option, "net_initial_msg_send_size") == 0) {
  229. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  230. &tmpll) == -1) {
  231. return (-2);
  232. }
  233. settings->net_initial_msg_send_size = (size_t)tmpll;
  234. } else if (strcasecmp(option, "net_min_msg_send_size") == 0) {
  235. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  236. &tmpll) == -1) {
  237. return (-2);
  238. }
  239. settings->net_min_msg_send_size = (size_t)tmpll;
  240. } else if (strcasecmp(option, "net_max_msg_receive_size") == 0) {
  241. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  242. &tmpll) == -1) {
  243. return (-2);
  244. }
  245. settings->net_max_msg_receive_size = (size_t)tmpll;
  246. } else if (strcasecmp(option, "net_max_send_buffers") == 0) {
  247. if (utils_strtonum(value, QDEVICE_NET_MIN_MAX_SEND_BUFFERS, LLONG_MAX,
  248. &tmpll) == -1) {
  249. return (-2);
  250. }
  251. settings->net_max_send_buffers = (size_t)tmpll;
  252. } else if (strcasecmp(option, "net_nss_qnetd_cn") == 0) {
  253. free(settings->net_nss_qnetd_cn);
  254. if ((settings->net_nss_qnetd_cn = strdup(value)) == NULL) {
  255. return (-1);
  256. }
  257. } else if (strcasecmp(option, "net_nss_client_cert_nickname") == 0) {
  258. free(settings->net_nss_client_cert_nickname);
  259. if ((settings->net_nss_client_cert_nickname = strdup(value)) == NULL) {
  260. return (-1);
  261. }
  262. } else if (strcasecmp(option, "net_heartbeat_interval_min") == 0) {
  263. if (utils_strtonum(value, QDEVICE_NET_MIN_HEARTBEAT_INTERVAL, UINT32_MAX,
  264. &tmpll) == -1) {
  265. return (-2);
  266. }
  267. settings->net_heartbeat_interval_min = (uint32_t)tmpll;
  268. } else if (strcasecmp(option, "net_heartbeat_interval_max") == 0) {
  269. if (utils_strtonum(value, QDEVICE_NET_MIN_HEARTBEAT_INTERVAL, UINT32_MAX,
  270. &tmpll) == -1) {
  271. return (-2);
  272. }
  273. settings->net_heartbeat_interval_max = (uint32_t)tmpll;
  274. } else if (strcasecmp(option, "net_min_connect_timeout") == 0) {
  275. if (utils_strtonum(value, QDEVICE_NET_MIN_CONNECT_TIMEOUT, UINT32_MAX,
  276. &tmpll) == -1) {
  277. return (-2);
  278. }
  279. settings->net_min_connect_timeout = (uint32_t)tmpll;
  280. } else if (strcasecmp(option, "net_max_connect_timeout") == 0) {
  281. if (utils_strtonum(value, QDEVICE_NET_MIN_CONNECT_TIMEOUT, UINT32_MAX,
  282. &tmpll) == -1) {
  283. return (-2);
  284. }
  285. settings->net_max_connect_timeout = (uint32_t)tmpll;
  286. } else if (strcasecmp(option, "net_test_algorithm_enabled") == 0) {
  287. if ((tmpll = utils_parse_bool_str(value)) == -1) {
  288. return (-2);
  289. }
  290. settings->net_test_algorithm_enabled = (uint8_t)tmpll;
  291. } else if (strcasecmp(option, "master_wins") == 0) {
  292. tmpll = utils_parse_bool_str(value);
  293. if (tmpll == 0) {
  294. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_OFF;
  295. } else if (tmpll == 1) {
  296. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_ON;
  297. } else if (strcasecmp(value, "model") == 0) {
  298. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_MODEL;
  299. } else {
  300. return (-2);
  301. }
  302. } else {
  303. return (-1);
  304. }
  305. return (0);
  306. }