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 *
| 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 *
|
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_TIMEOUT 5 85#define HAST_CONFIG "/etc/hast.conf" 86#define HAST_CONTROL "/var/run/hastctl" 87#define HASTD_PORT 8457 88#define HASTD_LISTEN "tcp4://0.0.0.0:8457" 89#define HASTD_PIDFILE "/var/run/hastd.pid" 90 91/* Default extent size. */ 92#define HAST_EXTENTSIZE 2097152 93/* Default maximum number of extents that are kept dirty. */ 94#define HAST_KEEPDIRTY 64 95 96#define HAST_ADDRSIZE 1024 97#define HAST_TOKEN_SIZE 16 98 99struct hastd_config { 100 /* Address to communicate with hastctl(8). */ 101 char hc_controladdr[HAST_ADDRSIZE]; 102 /* Protocol-specific data. */ 103 struct proto_conn *hc_controlconn; 104 /* Address to listen on. */ 105 char hc_listenaddr[HAST_ADDRSIZE]; 106 /* Protocol-specific data. */ 107 struct proto_conn *hc_listenconn; 108 /* List of resources. */ 109 TAILQ_HEAD(, hast_resource) hc_resources; 110}; 111 112#define HAST_REPLICATION_FULLSYNC 0 113#define HAST_REPLICATION_MEMSYNC 1 114#define HAST_REPLICATION_ASYNC 2 115 116/* 117 * Structure that describes single resource. 118 */ 119struct hast_resource { 120 /* Resource name. */ 121 char hr_name[NAME_MAX]; 122 /* Replication mode (HAST_REPLICATION_*). */ 123 int hr_replication; 124 /* Provider name that will appear in /dev/hast/. */ 125 char hr_provname[NAME_MAX]; 126 /* Synchronization extent size. */ 127 int hr_extentsize; 128 /* Maximum number of extents that are kept dirty. */ 129 int hr_keepdirty;
| 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_TIMEOUT 5 85#define HAST_CONFIG "/etc/hast.conf" 86#define HAST_CONTROL "/var/run/hastctl" 87#define HASTD_PORT 8457 88#define HASTD_LISTEN "tcp4://0.0.0.0:8457" 89#define HASTD_PIDFILE "/var/run/hastd.pid" 90 91/* Default extent size. */ 92#define HAST_EXTENTSIZE 2097152 93/* Default maximum number of extents that are kept dirty. */ 94#define HAST_KEEPDIRTY 64 95 96#define HAST_ADDRSIZE 1024 97#define HAST_TOKEN_SIZE 16 98 99struct hastd_config { 100 /* Address to communicate with hastctl(8). */ 101 char hc_controladdr[HAST_ADDRSIZE]; 102 /* Protocol-specific data. */ 103 struct proto_conn *hc_controlconn; 104 /* Address to listen on. */ 105 char hc_listenaddr[HAST_ADDRSIZE]; 106 /* Protocol-specific data. */ 107 struct proto_conn *hc_listenconn; 108 /* List of resources. */ 109 TAILQ_HEAD(, hast_resource) hc_resources; 110}; 111 112#define HAST_REPLICATION_FULLSYNC 0 113#define HAST_REPLICATION_MEMSYNC 1 114#define HAST_REPLICATION_ASYNC 2 115 116/* 117 * Structure that describes single resource. 118 */ 119struct hast_resource { 120 /* Resource name. */ 121 char hr_name[NAME_MAX]; 122 /* Replication mode (HAST_REPLICATION_*). */ 123 int hr_replication; 124 /* Provider name that will appear in /dev/hast/. */ 125 char hr_provname[NAME_MAX]; 126 /* Synchronization extent size. */ 127 int hr_extentsize; 128 /* Maximum number of extents that are kept dirty. */ 129 int hr_keepdirty;
|
130 131 /* Path to local component. */ 132 char hr_localpath[PATH_MAX]; 133 /* Descriptor to access local component. */ 134 int hr_localfd; 135 /* Offset into local component. */ 136 off_t hr_localoff; 137 /* Size of usable space. */ 138 off_t hr_datasize; 139 /* Size of entire local provider. */ 140 off_t hr_local_mediasize; 141 /* Sector size of local provider. */ 142 unsigned int hr_local_sectorsize; 143 144 /* Descriptor for /dev/ggctl communication. */ 145 int hr_ggatefd; 146 /* Unit number for ggate communication. */ 147 int hr_ggateunit; 148 149 /* Address of the remote component. */ 150 char hr_remoteaddr[HAST_ADDRSIZE]; 151 /* Connection for incoming data. */ 152 struct proto_conn *hr_remotein; 153 /* Connection for outgoing data. */ 154 struct proto_conn *hr_remoteout; 155 /* Token to verify both in and out connection are coming from 156 the same node (not necessarily from the same address). */ 157 unsigned char hr_token[HAST_TOKEN_SIZE]; 158 /* Connection timeout. */ 159 int hr_timeout; 160 161 /* Resource unique identifier. */ 162 uint64_t hr_resuid; 163 /* Primary's local modification count. */ 164 uint64_t hr_primary_localcnt; 165 /* Primary's remote modification count. */ 166 uint64_t hr_primary_remotecnt; 167 /* Secondary's local modification count. */ 168 uint64_t hr_secondary_localcnt; 169 /* Secondary's remote modification count. */ 170 uint64_t hr_secondary_remotecnt; 171 /* Synchronization source. */ 172 uint8_t hr_syncsrc; 173 174 /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 175 int hr_role; 176 /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 177 int hr_previous_role; 178 /* PID of child worker process. 0 - no child. */ 179 pid_t hr_workerpid; 180 /* Control connection between parent and child. */ 181 struct proto_conn *hr_ctrl; 182 183 /* Activemap structure. */ 184 struct activemap *hr_amp; 185 /* Locked used to synchronize access to hr_amp. */ 186 pthread_mutex_t hr_amp_lock; 187 188 /* Next resource. */ 189 TAILQ_ENTRY(hast_resource) hr_next; 190}; 191 192struct hastd_config *yy_config_parse(const char *config, bool exitonerror); 193void yy_config_free(struct hastd_config *config); 194 195void yyerror(const char *); 196int yylex(void); 197int yyparse(void); 198 199#endif /* !_HAST_H_ */
| 132 133 /* Path to local component. */ 134 char hr_localpath[PATH_MAX]; 135 /* Descriptor to access local component. */ 136 int hr_localfd; 137 /* Offset into local component. */ 138 off_t hr_localoff; 139 /* Size of usable space. */ 140 off_t hr_datasize; 141 /* Size of entire local provider. */ 142 off_t hr_local_mediasize; 143 /* Sector size of local provider. */ 144 unsigned int hr_local_sectorsize; 145 146 /* Descriptor for /dev/ggctl communication. */ 147 int hr_ggatefd; 148 /* Unit number for ggate communication. */ 149 int hr_ggateunit; 150 151 /* Address of the remote component. */ 152 char hr_remoteaddr[HAST_ADDRSIZE]; 153 /* Connection for incoming data. */ 154 struct proto_conn *hr_remotein; 155 /* Connection for outgoing data. */ 156 struct proto_conn *hr_remoteout; 157 /* Token to verify both in and out connection are coming from 158 the same node (not necessarily from the same address). */ 159 unsigned char hr_token[HAST_TOKEN_SIZE]; 160 /* Connection timeout. */ 161 int hr_timeout; 162 163 /* Resource unique identifier. */ 164 uint64_t hr_resuid; 165 /* Primary's local modification count. */ 166 uint64_t hr_primary_localcnt; 167 /* Primary's remote modification count. */ 168 uint64_t hr_primary_remotecnt; 169 /* Secondary's local modification count. */ 170 uint64_t hr_secondary_localcnt; 171 /* Secondary's remote modification count. */ 172 uint64_t hr_secondary_remotecnt; 173 /* Synchronization source. */ 174 uint8_t hr_syncsrc; 175 176 /* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 177 int hr_role; 178 /* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */ 179 int hr_previous_role; 180 /* PID of child worker process. 0 - no child. */ 181 pid_t hr_workerpid; 182 /* Control connection between parent and child. */ 183 struct proto_conn *hr_ctrl; 184 185 /* Activemap structure. */ 186 struct activemap *hr_amp; 187 /* Locked used to synchronize access to hr_amp. */ 188 pthread_mutex_t hr_amp_lock; 189 190 /* Next resource. */ 191 TAILQ_ENTRY(hast_resource) hr_next; 192}; 193 194struct hastd_config *yy_config_parse(const char *config, bool exitonerror); 195void yy_config_free(struct hastd_config *config); 196 197void yyerror(const char *); 198int yylex(void); 199int yyparse(void); 200 201#endif /* !_HAST_H_ */
|