hast.h revision 218048
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: head/sbin/hastd/hast.h 218048 2011-01-28 22:33:47Z pjd $ 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/* 52 * Version history: 53 * 0 - initial version 54 * 1 - HIO_KEEPALIVE added 55 */ 56#define HAST_PROTO_VERSION 1 57 58#define EHAST_OK 0 59#define EHAST_NOENTRY 1 60#define EHAST_INVALID 2 61#define EHAST_NOMEMORY 3 62#define EHAST_UNIMPLEMENTED 4 63 64#define HASTCTL_CMD_UNKNOWN 0 65#define HASTCTL_CMD_SETROLE 1 66#define HASTCTL_CMD_STATUS 2 67 68#define HAST_ROLE_UNDEF 0 69#define HAST_ROLE_INIT 1 70#define HAST_ROLE_PRIMARY 2 71#define HAST_ROLE_SECONDARY 3 72 73#define HAST_SYNCSRC_UNDEF 0 74#define HAST_SYNCSRC_PRIMARY 1 75#define HAST_SYNCSRC_SECONDARY 2 76 77#define HIO_UNDEF 0 78#define HIO_READ 1 79#define HIO_WRITE 2 80#define HIO_DELETE 3 81#define HIO_FLUSH 4 82#define HIO_KEEPALIVE 5 83 84#define HAST_USER "hast" 85#define HAST_TIMEOUT 5 86#define HAST_CONFIG "/etc/hast.conf" 87#define HAST_CONTROL "/var/run/hastctl" 88#define HASTD_PORT 8457 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 100struct hastd_config { 101 /* Address to communicate with hastctl(8). */ 102 char hc_controladdr[HAST_ADDRSIZE]; 103 /* Protocol-specific data. */ 104 struct proto_conn *hc_controlconn; 105 /* Incoming control connection. */ 106 struct proto_conn *hc_controlin; 107 /* Address to listen on. */ 108 char hc_listenaddr[HAST_ADDRSIZE]; 109 /* Protocol-specific data. */ 110 struct proto_conn *hc_listenconn; 111 /* List of resources. */ 112 TAILQ_HEAD(, hast_resource) hc_resources; 113}; 114 115#define HAST_REPLICATION_FULLSYNC 0 116#define HAST_REPLICATION_MEMSYNC 1 117#define HAST_REPLICATION_ASYNC 2 118 119/* 120 * Structure that describes single resource. 121 */ 122struct hast_resource { 123 /* Resource name. */ 124 char hr_name[NAME_MAX]; 125 /* Replication mode (HAST_REPLICATION_*). */ 126 int hr_replication; 127 /* Provider name that will appear in /dev/hast/. */ 128 char hr_provname[NAME_MAX]; 129 /* Synchronization extent size. */ 130 int hr_extentsize; 131 /* Maximum number of extents that are kept dirty. */ 132 int hr_keepdirty; 133 /* Path to a program to execute on various events. */ 134 char hr_exec[PATH_MAX]; 135 136 /* Path to local component. */ 137 char hr_localpath[PATH_MAX]; 138 /* Descriptor to access local component. */ 139 int hr_localfd; 140 /* Offset into local component. */ 141 off_t hr_localoff; 142 /* Size of usable space. */ 143 off_t hr_datasize; 144 /* Size of entire local provider. */ 145 off_t hr_local_mediasize; 146 /* Sector size of local provider. */ 147 unsigned int hr_local_sectorsize; 148 149 /* Descriptor for /dev/ggctl communication. */ 150 int hr_ggatefd; 151 /* Unit number for ggate communication. */ 152 int hr_ggateunit; 153 154 /* Address of the remote component. */ 155 char hr_remoteaddr[HAST_ADDRSIZE]; 156 /* Connection for incoming data. */ 157 struct proto_conn *hr_remotein; 158 /* Connection for outgoing data. */ 159 struct proto_conn *hr_remoteout; 160 /* Token to verify both in and out connection are coming from 161 the same node (not necessarily from the same address). */ 162 unsigned char hr_token[HAST_TOKEN_SIZE]; 163 /* Connection timeout. */ 164 int hr_timeout; 165 166 /* Resource unique identifier. */ 167 uint64_t hr_resuid; 168 /* Primary's local modification count. */ 169 uint64_t hr_primary_localcnt; 170 /* Primary's remote modification count. */ 171 uint64_t hr_primary_remotecnt; 172 /* Secondary's local modification count. */ 173 uint64_t hr_secondary_localcnt; 174 /* Secondary's remote modification count. */ 175 uint64_t hr_secondary_remotecnt; 176 /* Synchronization source. */ 177 uint8_t hr_syncsrc; 178 179 /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 180 int hr_role; 181 /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 182 int hr_previous_role; 183 /* PID of child worker process. 0 - no child. */ 184 pid_t hr_workerpid; 185 /* Control connection between parent and child. */ 186 struct proto_conn *hr_ctrl; 187 /* Events from child to parent. */ 188 struct proto_conn *hr_event; 189 190 /* Activemap structure. */ 191 struct activemap *hr_amp; 192 /* Locked used to synchronize access to hr_amp. */ 193 pthread_mutex_t hr_amp_lock; 194 195 /* Next resource. */ 196 TAILQ_ENTRY(hast_resource) hr_next; 197}; 198 199struct hastd_config *yy_config_parse(const char *config, bool exitonerror); 200void yy_config_free(struct hastd_config *config); 201 202void yyerror(const char *); 203int yylex(void); 204int yyparse(void); 205 206#endif /* !_HAST_H_ */ 207