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_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" 83 84 /* Default extent size. */ 85 #define HAST_EXTENTSIZE 2097152 86 /* Default maximum number of extents that are kept dirty. */ 87 #define HAST_KEEPDIRTY 64 88 89 #define HAST_ADDRSIZE 1024 90 #define HAST_TOKEN_SIZE 16 91 92 struct hastd_config { 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; 103 }; 104 105 #define HAST_REPLICATION_FULLSYNC 0 106 #define HAST_REPLICATION_MEMSYNC 1 107 #define HAST_REPLICATION_ASYNC 2 108 109 /* 110 * Structure that describes single resource. 111 */ 112 struct hast_resource { 113 /* Resource name. */ 114 char hr_name[NAME_MAX]; 115 /* Replication mode (HAST_REPLICATION_*). */ 116 int hr_replication; 117 /* Provider name that will appear in /dev/hast/. */ 118 char hr_provname[NAME_MAX]; 119 /* Synchronization extent size. */ 120 int hr_extentsize; 121 /* Maximum number of extents that are kept dirty. */ 122 int hr_keepdirty; 123 124 /* Path to local component. */ 125 char hr_localpath[PATH_MAX]; 126 /* Descriptor to access local component. */ 127 int hr_localfd; 128 /* Offset into local component. */ 129 off_t hr_localoff; 130 /* Size of usable space. */ 131 off_t hr_datasize; 132 /* Size of entire local provider. */ 133 off_t hr_local_mediasize; 134 /* Sector size of local provider. */ 135 unsigned int hr_local_sectorsize; 136 137 /* Descriptor for /dev/ggctl communication. */ 138 int hr_ggatefd; 139 /* Unit number for ggate communication. */ 140 int hr_ggateunit; 141 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]; 151 152 /* Resource unique identifier. */ 153 uint64_t hr_resuid; 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. */ 163 uint8_t hr_syncsrc; 164 165 /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 166 int hr_role; 167 /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 168 int hr_previous_role; 169 /* PID of child worker process. 0 - no child. */ 170 pid_t hr_workerpid; 171 /* Control connection between parent and child. */ 172 struct proto_conn *hr_ctrl; 173 174 /* Activemap structure. */ 175 struct activemap *hr_amp; 176 /* Locked used to synchronize access to hr_amp. */ 177 pthread_mutex_t hr_amp_lock; 178 179 /* Next resource. */ 180 TAILQ_ENTRY(hast_resource) hr_next; 181 }; 182 183 struct hastd_config *yy_config_parse(const char *config); 184 void yy_config_free(struct hastd_config *config); 185 186 void yyerror(const char *); 187 int yylex(void); 188 int yyparse(void); 189 190 #endif /* !_HAST_H_ */ 191