2010-02-18 23:16:19 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2009-2010 The FreeBSD Foundation
|
2011-03-06 22:56:14 +00:00
|
|
|
* Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>
|
2010-02-18 23:16:19 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by Pawel Jakub Dawidek under sponsorship from
|
|
|
|
* the FreeBSD Foundation.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _HAST_H_
|
|
|
|
#define _HAST_H_
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <activemap.h>
|
|
|
|
|
|
|
|
#include "proto.h"
|
|
|
|
|
2010-08-27 14:26:37 +00:00
|
|
|
/*
|
|
|
|
* Version history:
|
|
|
|
* 0 - initial version
|
|
|
|
* 1 - HIO_KEEPALIVE added
|
|
|
|
*/
|
|
|
|
#define HAST_PROTO_VERSION 1
|
2010-02-18 23:16:19 +00:00
|
|
|
|
|
|
|
#define EHAST_OK 0
|
|
|
|
#define EHAST_NOENTRY 1
|
|
|
|
#define EHAST_INVALID 2
|
|
|
|
#define EHAST_NOMEMORY 3
|
|
|
|
#define EHAST_UNIMPLEMENTED 4
|
|
|
|
|
|
|
|
#define HASTCTL_CMD_UNKNOWN 0
|
|
|
|
#define HASTCTL_CMD_SETROLE 1
|
|
|
|
#define HASTCTL_CMD_STATUS 2
|
|
|
|
|
|
|
|
#define HAST_ROLE_UNDEF 0
|
|
|
|
#define HAST_ROLE_INIT 1
|
|
|
|
#define HAST_ROLE_PRIMARY 2
|
|
|
|
#define HAST_ROLE_SECONDARY 3
|
|
|
|
|
|
|
|
#define HAST_SYNCSRC_UNDEF 0
|
|
|
|
#define HAST_SYNCSRC_PRIMARY 1
|
|
|
|
#define HAST_SYNCSRC_SECONDARY 2
|
|
|
|
|
|
|
|
#define HIO_UNDEF 0
|
|
|
|
#define HIO_READ 1
|
|
|
|
#define HIO_WRITE 2
|
|
|
|
#define HIO_DELETE 3
|
|
|
|
#define HIO_FLUSH 4
|
2010-08-27 14:26:37 +00:00
|
|
|
#define HIO_KEEPALIVE 5
|
2010-02-18 23:16:19 +00:00
|
|
|
|
2011-05-19 23:18:42 +00:00
|
|
|
#define HAST_USER "hast"
|
|
|
|
#define HAST_TIMEOUT 20
|
|
|
|
#define HAST_CONFIG "/etc/hast.conf"
|
|
|
|
#define HAST_CONTROL "/var/run/hastctl"
|
2011-05-20 11:15:27 +00:00
|
|
|
#define HASTD_LISTEN_TCP4 "tcp4://0.0.0.0:8457"
|
|
|
|
#define HASTD_LISTEN_TCP6 "tcp6://[::]:8457"
|
2011-05-19 23:18:42 +00:00
|
|
|
#define HASTD_PIDFILE "/var/run/hastd.pid"
|
2010-02-18 23:16:19 +00:00
|
|
|
|
|
|
|
/* Default extent size. */
|
|
|
|
#define HAST_EXTENTSIZE 2097152
|
|
|
|
/* Default maximum number of extents that are kept dirty. */
|
|
|
|
#define HAST_KEEPDIRTY 64
|
|
|
|
|
|
|
|
#define HAST_ADDRSIZE 1024
|
|
|
|
#define HAST_TOKEN_SIZE 16
|
|
|
|
|
2011-03-17 21:02:14 +00:00
|
|
|
/* Number of seconds to sleep between reconnect retries or keepalive packets. */
|
|
|
|
#define HAST_KEEPALIVE 10
|
|
|
|
|
2011-05-19 23:18:42 +00:00
|
|
|
struct hastd_listen {
|
|
|
|
/* Address to listen on. */
|
|
|
|
char hl_addr[HAST_ADDRSIZE];
|
|
|
|
/* Protocol-specific data. */
|
|
|
|
struct proto_conn *hl_conn;
|
|
|
|
TAILQ_ENTRY(hastd_listen) hl_next;
|
|
|
|
};
|
|
|
|
|
2010-02-18 23:16:19 +00:00
|
|
|
struct hastd_config {
|
|
|
|
/* Address to communicate with hastctl(8). */
|
2011-10-17 09:59:04 +00:00
|
|
|
char hc_controladdr[HAST_ADDRSIZE];
|
2010-02-18 23:16:19 +00:00
|
|
|
/* Protocol-specific data. */
|
|
|
|
struct proto_conn *hc_controlconn;
|
2011-01-27 19:33:57 +00:00
|
|
|
/* Incoming control connection. */
|
|
|
|
struct proto_conn *hc_controlin;
|
2011-10-17 12:22:09 +00:00
|
|
|
/* PID file path. */
|
|
|
|
char hc_pidfile[PATH_MAX];
|
2011-05-19 23:18:42 +00:00
|
|
|
/* List of addresses to listen on. */
|
|
|
|
TAILQ_HEAD(, hastd_listen) hc_listen;
|
2010-02-18 23:16:19 +00:00
|
|
|
/* List of resources. */
|
|
|
|
TAILQ_HEAD(, hast_resource) hc_resources;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define HAST_REPLICATION_FULLSYNC 0
|
|
|
|
#define HAST_REPLICATION_MEMSYNC 1
|
|
|
|
#define HAST_REPLICATION_ASYNC 2
|
|
|
|
|
2011-03-06 23:09:33 +00:00
|
|
|
#define HAST_COMPRESSION_NONE 0
|
|
|
|
#define HAST_COMPRESSION_HOLE 1
|
|
|
|
#define HAST_COMPRESSION_LZF 2
|
|
|
|
|
2011-03-06 22:56:14 +00:00
|
|
|
#define HAST_CHECKSUM_NONE 0
|
|
|
|
#define HAST_CHECKSUM_CRC32 1
|
|
|
|
#define HAST_CHECKSUM_SHA256 2
|
|
|
|
|
2010-02-18 23:16:19 +00:00
|
|
|
/*
|
|
|
|
* Structure that describes single resource.
|
|
|
|
*/
|
|
|
|
struct hast_resource {
|
|
|
|
/* Resource name. */
|
|
|
|
char hr_name[NAME_MAX];
|
|
|
|
/* Replication mode (HAST_REPLICATION_*). */
|
|
|
|
int hr_replication;
|
|
|
|
/* Provider name that will appear in /dev/hast/. */
|
|
|
|
char hr_provname[NAME_MAX];
|
|
|
|
/* Synchronization extent size. */
|
|
|
|
int hr_extentsize;
|
|
|
|
/* Maximum number of extents that are kept dirty. */
|
|
|
|
int hr_keepdirty;
|
2010-08-27 15:16:52 +00:00
|
|
|
/* Path to a program to execute on various events. */
|
|
|
|
char hr_exec[PATH_MAX];
|
2011-03-06 23:09:33 +00:00
|
|
|
/* Compression algorithm. */
|
|
|
|
int hr_compression;
|
2011-03-06 22:56:14 +00:00
|
|
|
/* Checksum algorithm. */
|
|
|
|
int hr_checksum;
|
2010-02-18 23:16:19 +00:00
|
|
|
|
|
|
|
/* Path to local component. */
|
|
|
|
char hr_localpath[PATH_MAX];
|
|
|
|
/* Descriptor to access local component. */
|
|
|
|
int hr_localfd;
|
|
|
|
/* Offset into local component. */
|
|
|
|
off_t hr_localoff;
|
|
|
|
/* Size of usable space. */
|
|
|
|
off_t hr_datasize;
|
|
|
|
/* Size of entire local provider. */
|
|
|
|
off_t hr_local_mediasize;
|
|
|
|
/* Sector size of local provider. */
|
|
|
|
unsigned int hr_local_sectorsize;
|
2011-09-28 13:19:47 +00:00
|
|
|
/* Is flushing write cache supported by the local provider? */
|
|
|
|
bool hr_localflush;
|
2011-09-28 13:08:51 +00:00
|
|
|
/* Flush write cache on metadata updates? */
|
|
|
|
int hr_metaflush;
|
2010-02-18 23:16:19 +00:00
|
|
|
|
|
|
|
/* Descriptor for /dev/ggctl communication. */
|
|
|
|
int hr_ggatefd;
|
|
|
|
/* Unit number for ggate communication. */
|
|
|
|
int hr_ggateunit;
|
|
|
|
|
|
|
|
/* Address of the remote component. */
|
|
|
|
char hr_remoteaddr[HAST_ADDRSIZE];
|
2011-03-21 08:54:59 +00:00
|
|
|
/* Local address to bind to for outgoing connections. */
|
|
|
|
char hr_sourceaddr[HAST_ADDRSIZE];
|
2010-02-18 23:16:19 +00:00
|
|
|
/* Connection for incoming data. */
|
|
|
|
struct proto_conn *hr_remotein;
|
|
|
|
/* Connection for outgoing data. */
|
|
|
|
struct proto_conn *hr_remoteout;
|
|
|
|
/* Token to verify both in and out connection are coming from
|
|
|
|
the same node (not necessarily from the same address). */
|
|
|
|
unsigned char hr_token[HAST_TOKEN_SIZE];
|
2010-04-29 15:36:32 +00:00
|
|
|
/* Connection timeout. */
|
|
|
|
int hr_timeout;
|
2010-02-18 23:16:19 +00:00
|
|
|
|
|
|
|
/* Resource unique identifier. */
|
|
|
|
uint64_t hr_resuid;
|
|
|
|
/* Primary's local modification count. */
|
|
|
|
uint64_t hr_primary_localcnt;
|
|
|
|
/* Primary's remote modification count. */
|
|
|
|
uint64_t hr_primary_remotecnt;
|
|
|
|
/* Secondary's local modification count. */
|
|
|
|
uint64_t hr_secondary_localcnt;
|
|
|
|
/* Secondary's remote modification count. */
|
|
|
|
uint64_t hr_secondary_remotecnt;
|
|
|
|
/* Synchronization source. */
|
|
|
|
uint8_t hr_syncsrc;
|
|
|
|
|
|
|
|
/* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
|
|
|
|
int hr_role;
|
|
|
|
/* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */
|
|
|
|
int hr_previous_role;
|
|
|
|
/* PID of child worker process. 0 - no child. */
|
|
|
|
pid_t hr_workerpid;
|
2011-02-03 11:39:49 +00:00
|
|
|
/* Control commands from parent to child. */
|
2010-02-18 23:16:19 +00:00
|
|
|
struct proto_conn *hr_ctrl;
|
2010-08-30 23:26:10 +00:00
|
|
|
/* Events from child to parent. */
|
|
|
|
struct proto_conn *hr_event;
|
2011-02-03 11:39:49 +00:00
|
|
|
/* Connection requests from child to parent. */
|
|
|
|
struct proto_conn *hr_conn;
|
2010-02-18 23:16:19 +00:00
|
|
|
|
|
|
|
/* Activemap structure. */
|
|
|
|
struct activemap *hr_amp;
|
|
|
|
/* Locked used to synchronize access to hr_amp. */
|
|
|
|
pthread_mutex_t hr_amp_lock;
|
|
|
|
|
2011-05-23 21:15:19 +00:00
|
|
|
/* Number of BIO_READ requests. */
|
|
|
|
uint64_t hr_stat_read;
|
|
|
|
/* Number of BIO_WRITE requests. */
|
|
|
|
uint64_t hr_stat_write;
|
|
|
|
/* Number of BIO_DELETE requests. */
|
|
|
|
uint64_t hr_stat_delete;
|
|
|
|
/* Number of BIO_FLUSH requests. */
|
|
|
|
uint64_t hr_stat_flush;
|
|
|
|
/* Number of activemap updates. */
|
|
|
|
uint64_t hr_stat_activemap_update;
|
|
|
|
|
2010-02-18 23:16:19 +00:00
|
|
|
/* Next resource. */
|
|
|
|
TAILQ_ENTRY(hast_resource) hr_next;
|
|
|
|
};
|
|
|
|
|
2010-08-05 19:08:54 +00:00
|
|
|
struct hastd_config *yy_config_parse(const char *config, bool exitonerror);
|
2010-02-18 23:16:19 +00:00
|
|
|
void yy_config_free(struct hastd_config *config);
|
|
|
|
|
|
|
|
void yyerror(const char *);
|
|
|
|
int yylex(void);
|
|
|
|
int yyparse(void);
|
|
|
|
|
|
|
|
#endif /* !_HAST_H_ */
|