qdevice-instance.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2015-2020 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. #ifndef _QDEVICE_INSTANCE_H_
  35. #define _QDEVICE_INSTANCE_H_
  36. #include <sys/types.h>
  37. #include <stdlib.h>
  38. #include <stdint.h>
  39. #include <corosync/cmap.h>
  40. #include <corosync/votequorum.h>
  41. #include "qdevice-advanced-settings.h"
  42. #include "qdevice-heuristics.h"
  43. #include "qdevice-model-type.h"
  44. #include "node-list.h"
  45. #include "pr-poll-loop.h"
  46. #include "unix-socket-ipc.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. struct qdevice_instance {
  51. cmap_handle_t cmap_handle;
  52. int cmap_poll_fd;
  53. int cmap_reload_in_progress;
  54. cmap_track_handle_t cmap_reload_track_handle;
  55. cmap_track_handle_t cmap_nodelist_track_handle;
  56. cmap_track_handle_t cmap_logging_track_handle;
  57. cmap_track_handle_t cmap_heuristics_track_handle;
  58. votequorum_handle_t votequorum_handle;
  59. int votequorum_poll_fd;
  60. struct unix_socket_ipc local_ipc;
  61. enum qdevice_model_type model_type;
  62. uint32_t node_id;
  63. uint32_t heartbeat_interval; /* Heartbeat interval during normal operation */
  64. uint32_t sync_heartbeat_interval; /* Heartbeat interval during corosync sync */
  65. struct node_list config_node_list;
  66. int config_node_list_version_set;
  67. uint64_t config_node_list_version;
  68. /*
  69. * Copy of votequorum_quorum_notify_fn callback paramters.
  70. * Set after model callback is called.
  71. */
  72. uint32_t vq_quorum_quorate;
  73. uint32_t vq_quorum_node_list_entries;
  74. votequorum_node_t *vq_quorum_node_list;
  75. /*
  76. * Copy of current votequorum_nodelist_notify_fn callback parameters.
  77. * Set after model callback qdevice_votequorum_node_list_notify_callback is called.
  78. */
  79. uint8_t vq_node_list_initial_ring_id_set;
  80. votequorum_ring_id_t vq_node_list_ring_id;
  81. uint32_t vq_node_list_entries;
  82. uint32_t *vq_node_list;
  83. uint8_t vq_node_list_initial_heuristics_finished;
  84. enum qdevice_heuristics_exec_result vq_node_list_heuristics_result;
  85. /*
  86. * Copy of current votequorum_nodelist_notify_fn callback ring id
  87. * It's set before any callback is called and used for qdevice_votequorum_poll
  88. */
  89. votequorum_ring_id_t vq_poll_ring_id;
  90. /*
  91. * Copy of votequorum_expectedvotes_notify_fn callback parameters.
  92. * Set after model callback is called.
  93. */
  94. uint32_t vq_expected_votes;
  95. time_t vq_last_poll;
  96. int vq_last_poll_cast_vote;
  97. void *model_data;
  98. const struct qdevice_advanced_settings *advanced_settings;
  99. int sync_in_progress;
  100. struct qdevice_heuristics_instance heuristics_instance;
  101. struct pr_poll_loop main_poll_loop;
  102. /*
  103. * Set by poll handler when votequorum/cmap connection is closed
  104. */
  105. int votequorum_closed;
  106. int cmap_closed;
  107. /*
  108. * Set by poll handler when one of the heuristics pipes becomes closed
  109. */
  110. int heuristics_closed;
  111. };
  112. extern int qdevice_instance_init(struct qdevice_instance *instance,
  113. const struct qdevice_advanced_settings *advanced_settings);
  114. extern int qdevice_instance_destroy(struct qdevice_instance *instance);
  115. extern int qdevice_instance_configure_from_cmap(struct qdevice_instance *instance);
  116. extern int qdevice_instance_configure_from_cmap_heuristics(struct qdevice_instance *instance);
  117. extern int qdevice_instance_wait_for_initial_heuristics_exec_result(struct qdevice_instance *instance);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* _QDEVICE_INSTANCE_H_ */