]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sbin/hastd/hast.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sbin / hastd / hast.h
1 /*-
2  * Copyright (c) 2009-2010 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by Pawel Jakub Dawidek under sponsorship from
6  * the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #ifndef _HAST_H_
33 #define _HAST_H_
34
35 #include <sys/queue.h>
36 #include <sys/socket.h>
37
38 #include <arpa/inet.h>
39
40 #include <netinet/in.h>
41
42 #include <limits.h>
43 #include <pthread.h>
44 #include <stdbool.h>
45 #include <stdint.h>
46
47 #include <activemap.h>
48
49 #include "proto.h"
50
51 #define HAST_PROTO_VERSION      0
52
53 #define EHAST_OK                0
54 #define EHAST_NOENTRY           1
55 #define EHAST_INVALID           2
56 #define EHAST_NOMEMORY          3
57 #define EHAST_UNIMPLEMENTED     4
58
59 #define HASTCTL_CMD_UNKNOWN     0
60 #define HASTCTL_CMD_SETROLE     1
61 #define HASTCTL_CMD_STATUS      2
62
63 #define HAST_ROLE_UNDEF         0
64 #define HAST_ROLE_INIT          1
65 #define HAST_ROLE_PRIMARY       2
66 #define HAST_ROLE_SECONDARY     3
67
68 #define HAST_SYNCSRC_UNDEF      0
69 #define HAST_SYNCSRC_PRIMARY    1
70 #define HAST_SYNCSRC_SECONDARY  2
71
72 #define HIO_UNDEF               0
73 #define HIO_READ                1
74 #define HIO_WRITE               2
75 #define HIO_DELETE              3
76 #define HIO_FLUSH               4
77
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"
84
85 /* Default extent size. */
86 #define HAST_EXTENTSIZE 2097152
87 /* Default maximum number of extents that are kept dirty. */
88 #define HAST_KEEPDIRTY  64
89
90 #define HAST_ADDRSIZE   1024
91 #define HAST_TOKEN_SIZE 16
92
93 struct hastd_config {
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;
104 };
105
106 #define HAST_REPLICATION_FULLSYNC       0
107 #define HAST_REPLICATION_MEMSYNC        1
108 #define HAST_REPLICATION_ASYNC          2
109
110 /*
111  * Structure that describes single resource.
112  */
113 struct hast_resource {
114         /* Resource name. */
115         char    hr_name[NAME_MAX];
116         /* Replication mode (HAST_REPLICATION_*). */
117         int     hr_replication;
118         /* Provider name that will appear in /dev/hast/. */
119         char    hr_provname[NAME_MAX];
120         /* Synchronization extent size. */
121         int     hr_extentsize;
122         /* Maximum number of extents that are kept dirty. */
123         int     hr_keepdirty;
124
125         /* Path to local component. */
126         char    hr_localpath[PATH_MAX];
127         /* Descriptor to access local component. */
128         int     hr_localfd;
129         /* Offset into local component. */
130         off_t   hr_localoff;
131         /* Size of usable space. */
132         off_t   hr_datasize;
133         /* Size of entire local provider. */
134         off_t   hr_local_mediasize;
135         /* Sector size of local provider. */
136         unsigned int hr_local_sectorsize;
137
138         /* Descriptor for /dev/ggctl communication. */
139         int     hr_ggatefd;
140         /* Unit number for ggate communication. */
141         int     hr_ggateunit;
142
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. */
153         int     hr_timeout;
154
155         /* Resource unique identifier. */
156         uint64_t hr_resuid;
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. */
166         uint8_t hr_syncsrc;
167
168         /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
169         int     hr_role;
170         /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
171         int     hr_previous_role;
172         /* PID of child worker process. 0 - no child. */
173         pid_t   hr_workerpid;
174         /* Control connection between parent and child. */
175         struct proto_conn *hr_ctrl;
176
177         /* Activemap structure. */
178         struct activemap *hr_amp;
179         /* Locked used to synchronize access to hr_amp. */
180         pthread_mutex_t hr_amp_lock;
181
182         /* Next resource. */
183         TAILQ_ENTRY(hast_resource) hr_next;
184 };
185
186 struct hastd_config *yy_config_parse(const char *config);
187 void yy_config_free(struct hastd_config *config);
188
189 void yyerror(const char *);
190 int yylex(void);
191 int yyparse(void);
192
193 #endif  /* !_HAST_H_ */