hast.h revision 220274
11558Srgrimes/*- 21558Srgrimes * Copyright (c) 2009-2010 The FreeBSD Foundation 31558Srgrimes * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net> 41558Srgrimes * All rights reserved. 51558Srgrimes * 61558Srgrimes * This software was developed by Pawel Jakub Dawidek under sponsorship from 71558Srgrimes * the FreeBSD Foundation. 81558Srgrimes * 91558Srgrimes * Redistribution and use in source and binary forms, with or without 101558Srgrimes * modification, are permitted provided that the following conditions 111558Srgrimes * are met: 121558Srgrimes * 1. Redistributions of source code must retain the above copyright 131558Srgrimes * notice, this list of conditions and the following disclaimer. 141558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151558Srgrimes * notice, this list of conditions and the following disclaimer in the 161558Srgrimes * documentation and/or other materials provided with the distribution. 171558Srgrimes * 181558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 191558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 201558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 211558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 221558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 231558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 241558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 251558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 261558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281558Srgrimes * SUCH DAMAGE. 291558Srgrimes * 301558Srgrimes * $FreeBSD: head/sbin/hastd/hast.h 220274 2011-04-02 09:34:33Z pjd $ 311558Srgrimes */ 321558Srgrimes 331558Srgrimes#ifndef _HAST_H_ 341558Srgrimes#define _HAST_H_ 351558Srgrimes 361558Srgrimes#include <sys/queue.h> 371558Srgrimes#include <sys/socket.h> 381558Srgrimes 391558Srgrimes#include <arpa/inet.h> 404065Swollman 411558Srgrimes#include <netinet/in.h> 421558Srgrimes 431558Srgrimes#include <limits.h> 444065Swollman#include <pthread.h> 454065Swollman#include <stdbool.h> 464065Swollman#include <stdint.h> 474065Swollman 484065Swollman#include <activemap.h> 494065Swollman 504065Swollman#include "proto.h" 511558Srgrimes 523202Sache/* 534065Swollman * Version history: 544065Swollman * 0 - initial version 553202Sache * 1 - HIO_KEEPALIVE added 561558Srgrimes */ 574065Swollman#define HAST_PROTO_VERSION 1 584065Swollman 591558Srgrimes#define EHAST_OK 0 601558Srgrimes#define EHAST_NOENTRY 1 614065Swollman#define EHAST_INVALID 2 624065Swollman#define EHAST_NOMEMORY 3 631558Srgrimes#define EHAST_UNIMPLEMENTED 4 641558Srgrimes 651558Srgrimes#define HASTCTL_CMD_UNKNOWN 0 661558Srgrimes#define HASTCTL_CMD_SETROLE 1 671558Srgrimes#define HASTCTL_CMD_STATUS 2 681558Srgrimes 691558Srgrimes#define HAST_ROLE_UNDEF 0 701558Srgrimes#define HAST_ROLE_INIT 1 711558Srgrimes#define HAST_ROLE_PRIMARY 2 721558Srgrimes#define HAST_ROLE_SECONDARY 3 731558Srgrimes 741558Srgrimes#define HAST_SYNCSRC_UNDEF 0 751558Srgrimes#define HAST_SYNCSRC_PRIMARY 1 761558Srgrimes#define HAST_SYNCSRC_SECONDARY 2 774065Swollman 784065Swollman#define HIO_UNDEF 0 79#define HIO_READ 1 80#define HIO_WRITE 2 81#define HIO_DELETE 3 82#define HIO_FLUSH 4 83#define HIO_KEEPALIVE 5 84 85#define HAST_USER "hast" 86#define HAST_TIMEOUT 20 87#define HAST_CONFIG "/etc/hast.conf" 88#define HAST_CONTROL "/var/run/hastctl" 89#define HASTD_LISTEN "tcp4://0.0.0.0:8457" 90#define HASTD_PIDFILE "/var/run/hastd.pid" 91 92/* Default extent size. */ 93#define HAST_EXTENTSIZE 2097152 94/* Default maximum number of extents that are kept dirty. */ 95#define HAST_KEEPDIRTY 64 96 97#define HAST_ADDRSIZE 1024 98#define HAST_TOKEN_SIZE 16 99 100/* Number of seconds to sleep between reconnect retries or keepalive packets. */ 101#define HAST_KEEPALIVE 10 102 103struct hastd_config { 104 /* Address to communicate with hastctl(8). */ 105 char hc_controladdr[HAST_ADDRSIZE]; 106 /* Protocol-specific data. */ 107 struct proto_conn *hc_controlconn; 108 /* Incoming control connection. */ 109 struct proto_conn *hc_controlin; 110 /* Address to listen on. */ 111 char hc_listenaddr[HAST_ADDRSIZE]; 112 /* Protocol-specific data. */ 113 struct proto_conn *hc_listenconn; 114 /* List of resources. */ 115 TAILQ_HEAD(, hast_resource) hc_resources; 116}; 117 118#define HAST_REPLICATION_FULLSYNC 0 119#define HAST_REPLICATION_MEMSYNC 1 120#define HAST_REPLICATION_ASYNC 2 121 122#define HAST_COMPRESSION_NONE 0 123#define HAST_COMPRESSION_HOLE 1 124#define HAST_COMPRESSION_LZF 2 125 126#define HAST_CHECKSUM_NONE 0 127#define HAST_CHECKSUM_CRC32 1 128#define HAST_CHECKSUM_SHA256 2 129 130/* 131 * Structure that describes single resource. 132 */ 133struct hast_resource { 134 /* Resource name. */ 135 char hr_name[NAME_MAX]; 136 /* Replication mode (HAST_REPLICATION_*). */ 137 int hr_replication; 138 /* Provider name that will appear in /dev/hast/. */ 139 char hr_provname[NAME_MAX]; 140 /* Synchronization extent size. */ 141 int hr_extentsize; 142 /* Maximum number of extents that are kept dirty. */ 143 int hr_keepdirty; 144 /* Path to a program to execute on various events. */ 145 char hr_exec[PATH_MAX]; 146 /* Compression algorithm. */ 147 int hr_compression; 148 /* Checksum algorithm. */ 149 int hr_checksum; 150 151 /* Path to local component. */ 152 char hr_localpath[PATH_MAX]; 153 /* Descriptor to access local component. */ 154 int hr_localfd; 155 /* Offset into local component. */ 156 off_t hr_localoff; 157 /* Size of usable space. */ 158 off_t hr_datasize; 159 /* Size of entire local provider. */ 160 off_t hr_local_mediasize; 161 /* Sector size of local provider. */ 162 unsigned int hr_local_sectorsize; 163 164 /* Descriptor for /dev/ggctl communication. */ 165 int hr_ggatefd; 166 /* Unit number for ggate communication. */ 167 int hr_ggateunit; 168 169 /* Address of the remote component. */ 170 char hr_remoteaddr[HAST_ADDRSIZE]; 171 /* Local address to bind to for outgoing connections. */ 172 char hr_sourceaddr[HAST_ADDRSIZE]; 173 /* Connection for incoming data. */ 174 struct proto_conn *hr_remotein; 175 /* Connection for outgoing data. */ 176 struct proto_conn *hr_remoteout; 177 /* Token to verify both in and out connection are coming from 178 the same node (not necessarily from the same address). */ 179 unsigned char hr_token[HAST_TOKEN_SIZE]; 180 /* Connection timeout. */ 181 int hr_timeout; 182 183 /* Resource unique identifier. */ 184 uint64_t hr_resuid; 185 /* Primary's local modification count. */ 186 uint64_t hr_primary_localcnt; 187 /* Primary's remote modification count. */ 188 uint64_t hr_primary_remotecnt; 189 /* Secondary's local modification count. */ 190 uint64_t hr_secondary_localcnt; 191 /* Secondary's remote modification count. */ 192 uint64_t hr_secondary_remotecnt; 193 /* Synchronization source. */ 194 uint8_t hr_syncsrc; 195 196 /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 197 int hr_role; 198 /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 199 int hr_previous_role; 200 /* PID of child worker process. 0 - no child. */ 201 pid_t hr_workerpid; 202 /* Control commands from parent to child. */ 203 struct proto_conn *hr_ctrl; 204 /* Events from child to parent. */ 205 struct proto_conn *hr_event; 206 /* Connection requests from child to parent. */ 207 struct proto_conn *hr_conn; 208 209 /* Activemap structure. */ 210 struct activemap *hr_amp; 211 /* Locked used to synchronize access to hr_amp. */ 212 pthread_mutex_t hr_amp_lock; 213 214 /* Next resource. */ 215 TAILQ_ENTRY(hast_resource) hr_next; 216}; 217 218struct hastd_config *yy_config_parse(const char *config, bool exitonerror); 219void yy_config_free(struct hastd_config *config); 220 221void yyerror(const char *); 222int yylex(void); 223int yyparse(void); 224 225#endif /* !_HAST_H_ */ 226