/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2009-2010 The FreeBSD Foundation4* Copyright (c) 2011 Pawel Jakub Dawidek <[email protected]>5* All rights reserved.6*7* This software was developed by Pawel Jakub Dawidek under sponsorship from8* the FreeBSD Foundation.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*/3132#ifndef _HAST_H_33#define _HAST_H_3435#include <sys/queue.h>36#include <sys/socket.h>3738#include <arpa/inet.h>3940#include <netinet/in.h>4142#include <limits.h>43#include <pthread.h>44#include <stdbool.h>45#include <stdint.h>4647#include <activemap.h>4849#include "proto.h"5051/*52* Version history:53* 0 - initial version54* 1 - HIO_KEEPALIVE added55* 2 - "memsync" and "received" attributes added for memsync mode56*/57#define HAST_PROTO_VERSION 25859#define EHAST_OK 060#define EHAST_NOENTRY 161#define EHAST_INVALID 262#define EHAST_NOMEMORY 363#define EHAST_UNIMPLEMENTED 46465#define HASTCTL_CMD_UNKNOWN 066#define HASTCTL_CMD_SETROLE 167#define HASTCTL_CMD_STATUS 26869#define HAST_ROLE_UNDEF 070#define HAST_ROLE_INIT 171#define HAST_ROLE_PRIMARY 272#define HAST_ROLE_SECONDARY 37374#define HAST_SYNCSRC_UNDEF 075#define HAST_SYNCSRC_PRIMARY 176#define HAST_SYNCSRC_SECONDARY 27778#define HIO_UNDEF 079#define HIO_READ 180#define HIO_WRITE 281#define HIO_DELETE 382#define HIO_FLUSH 483#define HIO_KEEPALIVE 58485#define HAST_USER "hast"86#define HAST_TIMEOUT 2087#define HAST_CONFIG "/etc/hast.conf"88#define HAST_CONTROL "/var/run/hastctl"89#define HASTD_LISTEN_TCP4 "tcp4://0.0.0.0:8457"90#define HASTD_LISTEN_TCP6 "tcp6://[::]:8457"91#define HASTD_PIDFILE "/var/run/hastd.pid"9293/* Default extent size. */94#define HAST_EXTENTSIZE 209715295/* Default maximum number of extents that are kept dirty. */96#define HAST_KEEPDIRTY 649798#define HAST_ADDRSIZE 102499#define HAST_TOKEN_SIZE 16100101/* Number of seconds to sleep between reconnect retries or keepalive packets. */102#define HAST_KEEPALIVE 10103104struct hastd_listen {105/* Address to listen on. */106char hl_addr[HAST_ADDRSIZE];107/* Protocol-specific data. */108struct proto_conn *hl_conn;109TAILQ_ENTRY(hastd_listen) hl_next;110};111112struct hastd_config {113/* Address to communicate with hastctl(8). */114char hc_controladdr[HAST_ADDRSIZE];115/* Protocol-specific data. */116struct proto_conn *hc_controlconn;117/* Incoming control connection. */118struct proto_conn *hc_controlin;119/* PID file path. */120char hc_pidfile[PATH_MAX];121/* List of addresses to listen on. */122TAILQ_HEAD(, hastd_listen) hc_listen;123/* List of resources. */124TAILQ_HEAD(, hast_resource) hc_resources;125};126127#define HAST_REPLICATION_FULLSYNC 0128#define HAST_REPLICATION_MEMSYNC 1129#define HAST_REPLICATION_ASYNC 2130131#define HAST_COMPRESSION_NONE 0132#define HAST_COMPRESSION_HOLE 1133#define HAST_COMPRESSION_LZF 2134135#define HAST_CHECKSUM_NONE 0136#define HAST_CHECKSUM_CRC32 1137#define HAST_CHECKSUM_SHA256 2138139struct nv;140141/*142* Structure that describes single resource.143*/144struct hast_resource {145/* Resource name. */146char hr_name[NAME_MAX];147/* Negotiated replication mode (HAST_REPLICATION_*). */148int hr_replication;149/* Configured replication mode (HAST_REPLICATION_*). */150int hr_original_replication;151/* Provider name that will appear in /dev/hast/. */152char hr_provname[NAME_MAX];153/* Synchronization extent size. */154int hr_extentsize;155/* Maximum number of extents that are kept dirty. */156int hr_keepdirty;157/* Path to a program to execute on various events. */158char hr_exec[PATH_MAX];159/* Compression algorithm. */160int hr_compression;161/* Checksum algorithm. */162int hr_checksum;163/* Protocol version. */164int hr_version;165166/* Path to local component. */167char hr_localpath[PATH_MAX];168/* Descriptor to access local component. */169int hr_localfd;170/* Offset into local component. */171off_t hr_localoff;172/* Size of usable space. */173off_t hr_datasize;174/* Size of entire local provider. */175off_t hr_local_mediasize;176/* Sector size of local provider. */177unsigned int hr_local_sectorsize;178/* Is flushing write cache supported by the local provider? */179bool hr_localflush;180/* Flush write cache on metadata updates? */181int hr_metaflush;182183/* Descriptor for /dev/ggctl communication. */184int hr_ggatefd;185/* Unit number for ggate communication. */186int hr_ggateunit;187188/* Address of the remote component. */189char hr_remoteaddr[HAST_ADDRSIZE];190/* Local address to bind to for outgoing connections. */191char hr_sourceaddr[HAST_ADDRSIZE];192/* Connection for incoming data. */193struct proto_conn *hr_remotein;194/* Connection for outgoing data. */195struct proto_conn *hr_remoteout;196/* Token to verify both in and out connection are coming from197the same node (not necessarily from the same address). */198unsigned char hr_token[HAST_TOKEN_SIZE];199/* Connection timeout. */200int hr_timeout;201202/* Resource unique identifier. */203uint64_t hr_resuid;204/* Primary's local modification count. */205uint64_t hr_primary_localcnt;206/* Primary's remote modification count. */207uint64_t hr_primary_remotecnt;208/* Secondary's local modification count. */209uint64_t hr_secondary_localcnt;210/* Secondary's remote modification count. */211uint64_t hr_secondary_remotecnt;212/* Synchronization source. */213uint8_t hr_syncsrc;214215/* Resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */216int hr_role;217/* Previous resource role: HAST_ROLE_{INIT,PRIMARY,SECONDARY}. */218int hr_previous_role;219/* PID of child worker process. 0 - no child. */220pid_t hr_workerpid;221/* Control commands from parent to child. */222struct proto_conn *hr_ctrl;223/* Events from child to parent. */224struct proto_conn *hr_event;225/* Connection requests from child to parent. */226struct proto_conn *hr_conn;227228/* Activemap structure. */229struct activemap *hr_amp;230/* Lock used to synchronize access to hr_amp. */231pthread_mutex_t hr_amp_lock;232/* Lock used to synchronize access to hr_amp diskmap. */233pthread_mutex_t hr_amp_diskmap_lock;234235/* Number of BIO_READ requests. */236uint64_t hr_stat_read;237/* Number of BIO_WRITE requests. */238uint64_t hr_stat_write;239/* Number of BIO_DELETE requests. */240uint64_t hr_stat_delete;241/* Number of BIO_FLUSH requests. */242uint64_t hr_stat_flush;243/* Number of activemap updates. */244uint64_t hr_stat_activemap_update;245/* Number of local read errors. */246uint64_t hr_stat_read_error;247/* Number of local write errors. */248uint64_t hr_stat_write_error;249/* Number of local delete errors. */250uint64_t hr_stat_delete_error;251/* Number of flush errors. */252uint64_t hr_stat_flush_error;253/* Number of activemap write errors. */254uint64_t hr_stat_activemap_write_error;255/* Number of activemap flush errors. */256uint64_t hr_stat_activemap_flush_error;257258/* Function to output worker specific info on control status request. */259void (*output_status_aux)(struct nv *);260261/* Next resource. */262TAILQ_ENTRY(hast_resource) hr_next;263};264265struct hastd_config *yy_config_parse(const char *config, bool exitonerror);266void yy_config_free(struct hastd_config *config);267268#endif /* !_HAST_H_ */269270271