hast.h revision 222119
1232633Smp/*- 2232633Smp * Copyright (c) 2009-2010 The FreeBSD Foundation 359243Sobrien * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net> 459243Sobrien * All rights reserved. 559243Sobrien * 659243Sobrien * This software was developed by Pawel Jakub Dawidek under sponsorship from 759243Sobrien * the FreeBSD Foundation. 859243Sobrien * 959243Sobrien * Redistribution and use in source and binary forms, with or without 1059243Sobrien * modification, are permitted provided that the following conditions 1159243Sobrien * are met: 1259243Sobrien * 1. Redistributions of source code must retain the above copyright 1359243Sobrien * notice, this list of conditions and the following disclaimer. 1459243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1559243Sobrien * notice, this list of conditions and the following disclaimer in the 1659243Sobrien * documentation and/or other materials provided with the distribution. 1759243Sobrien * 18100616Smp * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1959243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2059243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2159243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 2259243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2359243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2459243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2559243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2659243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2759243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2859243Sobrien * SUCH DAMAGE. 2959243Sobrien * 3059243Sobrien * $FreeBSD: head/sbin/hastd/hast.h 222119 2011-05-20 11:15:27Z pjd $ 3159243Sobrien */ 3259243Sobrien 3359243Sobrien#ifndef _HAST_H_ 3459243Sobrien#define _HAST_H_ 3559243Sobrien 36232633Smp#include <sys/queue.h> 3759243Sobrien#include <sys/socket.h> 38232633Smp 3959243Sobrien#include <arpa/inet.h> 40131962Smp 41131962Smp#include <netinet/in.h> 42131962Smp 43131962Smp#include <limits.h> 4459243Sobrien#include <pthread.h> 4559243Sobrien#include <stdbool.h> 4659243Sobrien#include <stdint.h> 47232633Smp 4859243Sobrien#include <activemap.h> 4959243Sobrien 5059243Sobrien#include "proto.h" 51232633Smp 5259243Sobrien/* 53167465Smp * Version history: 5459243Sobrien * 0 - initial version 5559243Sobrien * 1 - HIO_KEEPALIVE added 5659243Sobrien */ 5759243Sobrien#define HAST_PROTO_VERSION 1 5859243Sobrien 5959243Sobrien#define EHAST_OK 0 60232633Smp#define EHAST_NOENTRY 1 6159243Sobrien#define EHAST_INVALID 2 6259243Sobrien#define EHAST_NOMEMORY 3 6359243Sobrien#define EHAST_UNIMPLEMENTED 4 6459243Sobrien 65232633Smp#define HASTCTL_CMD_UNKNOWN 0 6659243Sobrien#define HASTCTL_CMD_SETROLE 1 6759243Sobrien#define HASTCTL_CMD_STATUS 2 6859243Sobrien 6959243Sobrien#define HAST_ROLE_UNDEF 0 7059243Sobrien#define HAST_ROLE_INIT 1 7159243Sobrien#define HAST_ROLE_PRIMARY 2 7259243Sobrien#define HAST_ROLE_SECONDARY 3 7359243Sobrien 7459243Sobrien#define HAST_SYNCSRC_UNDEF 0 7559243Sobrien#define HAST_SYNCSRC_PRIMARY 1 76167465Smp#define HAST_SYNCSRC_SECONDARY 2 7759243Sobrien 7859243Sobrien#define HIO_UNDEF 0 7959243Sobrien#define HIO_READ 1 8059243Sobrien#define HIO_WRITE 2 8159243Sobrien#define HIO_DELETE 3 8259243Sobrien#define HIO_FLUSH 4 83232633Smp#define HIO_KEEPALIVE 5 8459243Sobrien 8559243Sobrien#define HAST_USER "hast" 8659243Sobrien#define HAST_TIMEOUT 20 8759243Sobrien#define HAST_CONFIG "/etc/hast.conf" 8859243Sobrien#define HAST_CONTROL "/var/run/hastctl" 8959243Sobrien#define HASTD_LISTEN_TCP4 "tcp4://0.0.0.0:8457" 9059243Sobrien#define HASTD_LISTEN_TCP6 "tcp6://[::]:8457" 9159243Sobrien#define HASTD_PIDFILE "/var/run/hastd.pid" 9259243Sobrien 9359243Sobrien/* Default extent size. */ 9459243Sobrien#define HAST_EXTENTSIZE 2097152 9559243Sobrien/* Default maximum number of extents that are kept dirty. */ 9659243Sobrien#define HAST_KEEPDIRTY 64 9759243Sobrien 9859243Sobrien#define HAST_ADDRSIZE 1024 99232633Smp#define HAST_TOKEN_SIZE 16 10059243Sobrien 10159243Sobrien/* Number of seconds to sleep between reconnect retries or keepalive packets. */ 10259243Sobrien#define HAST_KEEPALIVE 10 10359243Sobrien 10459243Sobrienstruct hastd_listen { 105232633Smp /* Address to listen on. */ 10659243Sobrien char hl_addr[HAST_ADDRSIZE]; 10759243Sobrien /* Protocol-specific data. */ 10859243Sobrien struct proto_conn *hl_conn; 10959243Sobrien TAILQ_ENTRY(hastd_listen) hl_next; 110232633Smp}; 11159243Sobrien 11259243Sobrienstruct hastd_config { 11359243Sobrien /* Address to communicate with hastctl(8). */ 11459243Sobrien char hc_controladdr[HAST_ADDRSIZE]; 11559243Sobrien /* Protocol-specific data. */ 11659243Sobrien struct proto_conn *hc_controlconn; 11759243Sobrien /* Incoming control connection. */ 118167465Smp struct proto_conn *hc_controlin; 11959243Sobrien /* List of addresses to listen on. */ 12059243Sobrien TAILQ_HEAD(, hastd_listen) hc_listen; 121232633Smp /* List of resources. */ 12259243Sobrien TAILQ_HEAD(, hast_resource) hc_resources; 12359243Sobrien}; 12459243Sobrien 12559243Sobrien#define HAST_REPLICATION_FULLSYNC 0 12659243Sobrien#define HAST_REPLICATION_MEMSYNC 1 12759243Sobrien#define HAST_REPLICATION_ASYNC 2 12859243Sobrien 12959243Sobrien#define HAST_COMPRESSION_NONE 0 13059243Sobrien#define HAST_COMPRESSION_HOLE 1 13159243Sobrien#define HAST_COMPRESSION_LZF 2 13259243Sobrien 13359243Sobrien#define HAST_CHECKSUM_NONE 0 13459243Sobrien#define HAST_CHECKSUM_CRC32 1 13559243Sobrien#define HAST_CHECKSUM_SHA256 2 13659243Sobrien 13759243Sobrien/* 13859243Sobrien * Structure that describes single resource. 13959243Sobrien */ 14059243Sobrienstruct hast_resource { 14159243Sobrien /* Resource name. */ 14259243Sobrien char hr_name[NAME_MAX]; 14359243Sobrien /* Replication mode (HAST_REPLICATION_*). */ 14459243Sobrien int hr_replication; 14559243Sobrien /* Provider name that will appear in /dev/hast/. */ 14659243Sobrien char hr_provname[NAME_MAX]; 14759243Sobrien /* Synchronization extent size. */ 14859243Sobrien int hr_extentsize; 14959243Sobrien /* Maximum number of extents that are kept dirty. */ 15059243Sobrien int hr_keepdirty; 15159243Sobrien /* Path to a program to execute on various events. */ 15259243Sobrien char hr_exec[PATH_MAX]; 15359243Sobrien /* Compression algorithm. */ 15459243Sobrien int hr_compression; 15559243Sobrien /* Checksum algorithm. */ 15659243Sobrien int hr_checksum; 15759243Sobrien 15859243Sobrien /* Path to local component. */ 15959243Sobrien char hr_localpath[PATH_MAX]; 16059243Sobrien /* Descriptor to access local component. */ 16159243Sobrien int hr_localfd; 16259243Sobrien /* Offset into local component. */ 16359243Sobrien off_t hr_localoff; 16459243Sobrien /* Size of usable space. */ 16559243Sobrien off_t hr_datasize; 16659243Sobrien /* Size of entire local provider. */ 16759243Sobrien off_t hr_local_mediasize; 16859243Sobrien /* Sector size of local provider. */ 169232633Smp unsigned int hr_local_sectorsize; 17059243Sobrien 17159243Sobrien /* Descriptor for /dev/ggctl communication. */ 172232633Smp int hr_ggatefd; 173232633Smp /* Unit number for ggate communication. */ 174232633Smp int hr_ggateunit; 175232633Smp 176232633Smp /* Address of the remote component. */ 177232633Smp char hr_remoteaddr[HAST_ADDRSIZE]; 178232633Smp /* Local address to bind to for outgoing connections. */ 179232633Smp char hr_sourceaddr[HAST_ADDRSIZE]; 180232633Smp /* Connection for incoming data. */ 181232633Smp struct proto_conn *hr_remotein; 182232633Smp /* Connection for outgoing data. */ 183232633Smp struct proto_conn *hr_remoteout; 184232633Smp /* Token to verify both in and out connection are coming from 185232633Smp the same node (not necessarily from the same address). */ 186232633Smp unsigned char hr_token[HAST_TOKEN_SIZE]; 187232633Smp /* Connection timeout. */ 188232633Smp int hr_timeout; 189232633Smp 190232633Smp /* Resource unique identifier. */ 191232633Smp uint64_t hr_resuid; 192232633Smp /* Primary's local modification count. */ 193232633Smp uint64_t hr_primary_localcnt; 194232633Smp /* Primary's remote modification count. */ 195232633Smp uint64_t hr_primary_remotecnt; 196232633Smp /* Secondary's local modification count. */ 197232633Smp uint64_t hr_secondary_localcnt; 19859243Sobrien /* Secondary's remote modification count. */ 199232633Smp uint64_t hr_secondary_remotecnt; 200232633Smp /* Synchronization source. */ 201232633Smp uint8_t hr_syncsrc; 202232633Smp 203232633Smp /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 204232633Smp int hr_role; 205232633Smp /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 206232633Smp int hr_previous_role; 207232633Smp /* PID of child worker process. 0 - no child. */ 208232633Smp pid_t hr_workerpid; 209232633Smp /* Control commands from parent to child. */ 210232633Smp struct proto_conn *hr_ctrl; 211232633Smp /* Events from child to parent. */ 212232633Smp struct proto_conn *hr_event; 213232633Smp /* Connection requests from child to parent. */ 214232633Smp struct proto_conn *hr_conn; 215232633Smp 216232633Smp /* Activemap structure. */ 217232633Smp struct activemap *hr_amp; 218232633Smp /* Locked used to synchronize access to hr_amp. */ 219232633Smp pthread_mutex_t hr_amp_lock; 220232633Smp 221232633Smp /* Next resource. */ 222232633Smp TAILQ_ENTRY(hast_resource) hr_next; 223232633Smp}; 224232633Smp 225232633Smpstruct hastd_config *yy_config_parse(const char *config, bool exitonerror); 226232633Smpvoid yy_config_free(struct hastd_config *config); 22759243Sobrien 228167465Smpvoid yyerror(const char *); 22959243Sobrienint yylex(void); 230145479Smpint yyparse(void); 231145479Smp 232145479Smp#endif /* !_HAST_H_ */ 233145479Smp