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