2 * Copyright (c) 2009-2010 The FreeBSD Foundation
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/queue.h>
36 #include <sys/socket.h>
38 #include <arpa/inet.h>
40 #include <netinet/in.h>
47 #include <activemap.h>
51 #define HAST_PROTO_VERSION 0
54 #define EHAST_NOENTRY 1
55 #define EHAST_INVALID 2
56 #define EHAST_NOMEMORY 3
57 #define EHAST_UNIMPLEMENTED 4
59 #define HASTCTL_CMD_UNKNOWN 0
60 #define HASTCTL_CMD_SETROLE 1
61 #define HASTCTL_CMD_STATUS 2
63 #define HAST_ROLE_UNDEF 0
64 #define HAST_ROLE_INIT 1
65 #define HAST_ROLE_PRIMARY 2
66 #define HAST_ROLE_SECONDARY 3
68 #define HAST_SYNCSRC_UNDEF 0
69 #define HAST_SYNCSRC_PRIMARY 1
70 #define HAST_SYNCSRC_SECONDARY 2
78 #define HAST_TIMEOUT 5
79 #define HAST_CONFIG "/etc/hast.conf"
80 #define HAST_CONTROL "/var/run/hastctl"
81 #define HASTD_PORT 8457
82 #define HASTD_LISTEN "tcp4://0.0.0.0:8457"
83 #define HASTD_PIDFILE "/var/run/hastd.pid"
85 /* Default extent size. */
86 #define HAST_EXTENTSIZE 2097152
87 /* Default maximum number of extents that are kept dirty. */
88 #define HAST_KEEPDIRTY 64
90 #define HAST_ADDRSIZE 1024
91 #define HAST_TOKEN_SIZE 16
94 /* Address to communicate with hastctl(8). */
95 char hc_controladdr[HAST_ADDRSIZE];
96 /* Protocol-specific data. */
97 struct proto_conn *hc_controlconn;
98 /* Address to listen on. */
99 char hc_listenaddr[HAST_ADDRSIZE];
100 /* Protocol-specific data. */
101 struct proto_conn *hc_listenconn;
102 /* List of resources. */
103 TAILQ_HEAD(, hast_resource) hc_resources;
106 #define HAST_REPLICATION_FULLSYNC 0
107 #define HAST_REPLICATION_MEMSYNC 1
108 #define HAST_REPLICATION_ASYNC 2
111 * Structure that describes single resource.
113 struct hast_resource {
115 char hr_name[NAME_MAX];
116 /* Replication mode (HAST_REPLICATION_*). */
118 /* Provider name that will appear in /dev/hast/. */
119 char hr_provname[NAME_MAX];
120 /* Synchronization extent size. */
122 /* Maximum number of extents that are kept dirty. */
125 /* Path to local component. */
126 char hr_localpath[PATH_MAX];
127 /* Descriptor to access local component. */
129 /* Offset into local component. */
131 /* Size of usable space. */
133 /* Size of entire local provider. */
134 off_t hr_local_mediasize;
135 /* Sector size of local provider. */
136 unsigned int hr_local_sectorsize;
138 /* Descriptor for /dev/ggctl communication. */
140 /* Unit number for ggate communication. */
143 /* Address of the remote component. */
144 char hr_remoteaddr[HAST_ADDRSIZE];
145 /* Connection for incoming data. */
146 struct proto_conn *hr_remotein;
147 /* Connection for outgoing data. */
148 struct proto_conn *hr_remoteout;
149 /* Token to verify both in and out connection are coming from
150 the same node (not necessarily from the same address). */
151 unsigned char hr_token[HAST_TOKEN_SIZE];
152 /* Connection timeout. */
155 /* Resource unique identifier. */
157 /* Primary's local modification count. */
158 uint64_t hr_primary_localcnt;
159 /* Primary's remote modification count. */
160 uint64_t hr_primary_remotecnt;
161 /* Secondary's local modification count. */
162 uint64_t hr_secondary_localcnt;
163 /* Secondary's remote modification count. */
164 uint64_t hr_secondary_remotecnt;
165 /* Synchronization source. */
168 /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
170 /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
171 int hr_previous_role;
172 /* PID of child worker process. 0 - no child. */
174 /* Control connection between parent and child. */
175 struct proto_conn *hr_ctrl;
177 /* Activemap structure. */
178 struct activemap *hr_amp;
179 /* Locked used to synchronize access to hr_amp. */
180 pthread_mutex_t hr_amp_lock;
183 TAILQ_ENTRY(hast_resource) hr_next;
186 struct hastd_config *yy_config_parse(const char *config);
187 void yy_config_free(struct hastd_config *config);
189 void yyerror(const char *);
193 #endif /* !_HAST_H_ */