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_CONFIG "/etc/hast.conf"
79 #define HAST_CONTROL "/var/run/hastctl"
80 #define HASTD_PORT 8457
81 #define HASTD_LISTEN "tcp4://0.0.0.0:8457"
82 #define HASTD_PIDFILE "/var/run/hastd.pid"
84 /* Default extent size. */
85 #define HAST_EXTENTSIZE 2097152
86 /* Default maximum number of extents that are kept dirty. */
87 #define HAST_KEEPDIRTY 64
89 #define HAST_ADDRSIZE 1024
90 #define HAST_TOKEN_SIZE 16
93 /* Address to communicate with hastctl(8). */
94 char hc_controladdr[HAST_ADDRSIZE];
95 /* Protocol-specific data. */
96 struct proto_conn *hc_controlconn;
97 /* Address to listen on. */
98 char hc_listenaddr[HAST_ADDRSIZE];
99 /* Protocol-specific data. */
100 struct proto_conn *hc_listenconn;
101 /* List of resources. */
102 TAILQ_HEAD(, hast_resource) hc_resources;
105 #define HAST_REPLICATION_FULLSYNC 0
106 #define HAST_REPLICATION_MEMSYNC 1
107 #define HAST_REPLICATION_ASYNC 2
110 * Structure that describes single resource.
112 struct hast_resource {
114 char hr_name[NAME_MAX];
115 /* Replication mode (HAST_REPLICATION_*). */
117 /* Provider name that will appear in /dev/hast/. */
118 char hr_provname[NAME_MAX];
119 /* Synchronization extent size. */
121 /* Maximum number of extents that are kept dirty. */
124 /* Path to local component. */
125 char hr_localpath[PATH_MAX];
126 /* Descriptor to access local component. */
128 /* Offset into local component. */
130 /* Size of usable space. */
132 /* Size of entire local provider. */
133 off_t hr_local_mediasize;
134 /* Sector size of local provider. */
135 unsigned int hr_local_sectorsize;
137 /* Descriptor for /dev/ggctl communication. */
139 /* Unit number for ggate communication. */
142 /* Address of the remote component. */
143 char hr_remoteaddr[HAST_ADDRSIZE];
144 /* Connection for incoming data. */
145 struct proto_conn *hr_remotein;
146 /* Connection for outgoing data. */
147 struct proto_conn *hr_remoteout;
148 /* Token to verify both in and out connection are coming from
149 the same node (not necessarily from the same address). */
150 unsigned char hr_token[HAST_TOKEN_SIZE];
152 /* Resource unique identifier. */
154 /* Primary's local modification count. */
155 uint64_t hr_primary_localcnt;
156 /* Primary's remote modification count. */
157 uint64_t hr_primary_remotecnt;
158 /* Secondary's local modification count. */
159 uint64_t hr_secondary_localcnt;
160 /* Secondary's remote modification count. */
161 uint64_t hr_secondary_remotecnt;
162 /* Synchronization source. */
165 /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
167 /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
168 int hr_previous_role;
169 /* PID of child worker process. 0 - no child. */
171 /* Control connection between parent and child. */
172 struct proto_conn *hr_ctrl;
174 /* Activemap structure. */
175 struct activemap *hr_amp;
176 /* Locked used to synchronize access to hr_amp. */
177 pthread_mutex_t hr_amp_lock;
180 TAILQ_ENTRY(hast_resource) hr_next;
183 struct hastd_config *yy_config_parse(const char *config);
184 void yy_config_free(struct hastd_config *config);
186 void yyerror(const char *);
190 #endif /* !_HAST_H_ */