[Midnightbsd-cvs] src [11211] sync hastd with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jul 1 16:47:04 EDT 2018


Revision: 11211
          http://svnweb.midnightbsd.org/src/?rev=11211
Author:   laffer1
Date:     2018-07-01 16:47:04 -0400 (Sun, 01 Jul 2018)
Log Message:
-----------
sync hastd with freebsd

Modified Paths:
--------------
    trunk/sbin/hastd/Makefile
    trunk/sbin/hastd/activemap.c
    trunk/sbin/hastd/activemap.h
    trunk/sbin/hastd/control.c
    trunk/sbin/hastd/control.h
    trunk/sbin/hastd/crc32.c
    trunk/sbin/hastd/crc32.h
    trunk/sbin/hastd/ebuf.c
    trunk/sbin/hastd/ebuf.h
    trunk/sbin/hastd/event.c
    trunk/sbin/hastd/event.h
    trunk/sbin/hastd/hast.conf.5
    trunk/sbin/hastd/hast.h
    trunk/sbin/hastd/hast_checksum.c
    trunk/sbin/hastd/hast_checksum.h
    trunk/sbin/hastd/hast_compression.c
    trunk/sbin/hastd/hast_compression.h
    trunk/sbin/hastd/hast_proto.c
    trunk/sbin/hastd/hast_proto.h
    trunk/sbin/hastd/hastd.8
    trunk/sbin/hastd/hastd.c
    trunk/sbin/hastd/hastd.h
    trunk/sbin/hastd/hooks.c
    trunk/sbin/hastd/hooks.h
    trunk/sbin/hastd/lzf.c
    trunk/sbin/hastd/lzf.h
    trunk/sbin/hastd/metadata.c
    trunk/sbin/hastd/metadata.h
    trunk/sbin/hastd/nv.c
    trunk/sbin/hastd/nv.h
    trunk/sbin/hastd/parse.y
    trunk/sbin/hastd/pjdlog.c
    trunk/sbin/hastd/pjdlog.h
    trunk/sbin/hastd/primary.c
    trunk/sbin/hastd/proto.c
    trunk/sbin/hastd/proto.h
    trunk/sbin/hastd/proto_common.c
    trunk/sbin/hastd/proto_impl.h
    trunk/sbin/hastd/proto_socketpair.c
    trunk/sbin/hastd/proto_tcp.c
    trunk/sbin/hastd/proto_uds.c
    trunk/sbin/hastd/rangelock.c
    trunk/sbin/hastd/rangelock.h
    trunk/sbin/hastd/refcnt.h
    trunk/sbin/hastd/secondary.c
    trunk/sbin/hastd/subr.c
    trunk/sbin/hastd/subr.h
    trunk/sbin/hastd/synch.h
    trunk/sbin/hastd/token.l

Property Changed:
----------------
    trunk/sbin/hastd/hast.conf.5
    trunk/sbin/hastd/hastd.8
    trunk/sbin/hastd/parse.y
    trunk/sbin/hastd/token.l

Modified: trunk/sbin/hastd/Makefile
===================================================================
--- trunk/sbin/hastd/Makefile	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/Makefile	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/sbin/hastd/Makefile 270911 2014-09-01 03:22:47Z ngie $
 
 .include <bsd.own.mk>
 
@@ -19,10 +20,9 @@
 SRCS+=	y.tab.h
 MAN=	hastd.8 hast.conf.5
 
-WARNS=	0
-
 NO_WFORMAT=
 NO_WCAST_ALIGN=
+NO_WMISSING_VARIABLE_DECLARATIONS=
 CFLAGS+=-I${.CURDIR}
 CFLAGS+=-DHAVE_CAPSICUM
 CFLAGS+=-DPROTO_TCP_DEFAULT_PORT=8457
@@ -31,7 +31,7 @@
 CFLAGS+=-DINET6
 .endif
 
-DPADD=	${LIBGEOM} ${LIBBSDXML} ${LIBSBUF} ${LIBL} ${LIBPTHREAD} ${LIBUTIL}
+DPADD=	${LIBGEOM} ${LIBBSDXML} ${LIBSBUF} ${LIBPTHREAD} ${LIBUTIL}
 LDADD=	-lgeom -lbsdxml -lsbuf -lpthread -lutil
 .if ${MK_OPENSSL} != "no"
 DPADD+=	${LIBCRYPTO}

Modified: trunk/sbin/hastd/activemap.c
===================================================================
--- trunk/sbin/hastd/activemap.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/activemap.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/activemap.c 229778 2012-01-07 16:09:33Z uqs $");
 
 #include <sys/param.h>	/* powerof2() */
 #include <sys/queue.h>

Modified: trunk/sbin/hastd/activemap.h
===================================================================
--- trunk/sbin/hastd/activemap.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/activemap.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/activemap.h 204076 2010-02-18 23:16:19Z pjd $
  */
 
 #ifndef	_ACTIVEMAP_H_

Modified: trunk/sbin/hastd/control.c
===================================================================
--- trunk/sbin/hastd/control.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/control.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/control.c 260006 2013-12-28 19:21:22Z trociny $");
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -215,6 +216,16 @@
 	    "stat_delete_error%u", no);
 	nv_add_uint64(nvout, nv_get_uint64(cnvin, "stat_flush_error"),
 	    "stat_flush_error%u", no);
+	nv_add_uint64(nvout, nv_get_uint64(cnvin, "idle_queue_size"),
+	    "idle_queue_size%u", no);
+	nv_add_uint64(nvout, nv_get_uint64(cnvin, "local_queue_size"),
+	    "local_queue_size%u", no);
+	nv_add_uint64(nvout, nv_get_uint64(cnvin, "send_queue_size"),
+	    "send_queue_size%u", no);
+	nv_add_uint64(nvout, nv_get_uint64(cnvin, "recv_queue_size"),
+	    "recv_queue_size%u", no);
+	nv_add_uint64(nvout, nv_get_uint64(cnvin, "done_queue_size"),
+	    "done_queue_size%u", no);
 end:
 	if (cnvin != NULL)
 		nv_free(cnvin);
@@ -271,6 +282,7 @@
 	nv_add_string(nvout, compression_name(res->hr_compression),
 	    "compression%u", no);
 	nv_add_string(nvout, role2str(res->hr_role), "role%u", no);
+	nv_add_int32(nvout, res->hr_workerpid, "workerpid%u", no);
 
 	switch (res->hr_role) {
 	case HAST_ROLE_PRIMARY:
@@ -477,6 +489,7 @@
 			nv_add_uint64(nvout, res->hr_stat_flush_error +
 			    res->hr_stat_activemap_flush_error,
 			    "stat_flush_error");
+			res->output_status_aux(nvout);
 			nv_add_int16(nvout, 0, "error");
 			break;
 		case CONTROL_RELOAD:

Modified: trunk/sbin/hastd/control.h
===================================================================
--- trunk/sbin/hastd/control.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/control.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/control.h 221076 2011-04-26 19:38:30Z trociny $
  */
 
 #ifndef	_CONTROL_H_

Modified: trunk/sbin/hastd/crc32.c
===================================================================
--- trunk/sbin/hastd/crc32.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/crc32.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
  *  code or tables extracted from it, as desired without restriction.
@@ -43,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/crc32.c 219351 2011-03-06 22:56:14Z pjd $");
 
 #include <stdint.h>
 

Modified: trunk/sbin/hastd/crc32.h
===================================================================
--- trunk/sbin/hastd/crc32.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/crc32.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,8 +1,9 @@
+/* $MidnightBSD$ */
 /*-
  *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
  *  code or tables extracted from it, as desired without restriction.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/crc32.h 219351 2011-03-06 22:56:14Z pjd $
  */
 
 #ifndef _CRC32_H_

Modified: trunk/sbin/hastd/ebuf.c
===================================================================
--- trunk/sbin/hastd/ebuf.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/ebuf.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/ebuf.c 229945 2012-01-10 22:39:07Z pjd $");
 
 #include <sys/param.h>
 

Modified: trunk/sbin/hastd/ebuf.h
===================================================================
--- trunk/sbin/hastd/ebuf.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/ebuf.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/ebuf.h 204076 2010-02-18 23:16:19Z pjd $
  */
 
 #ifndef	_EBUF_H_

Modified: trunk/sbin/hastd/event.c
===================================================================
--- trunk/sbin/hastd/event.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/event.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 Pawel Jakub Dawidek <pjd at FreeBSD.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/event.c 229945 2012-01-10 22:39:07Z pjd $");
 
 #include <errno.h>
 

Modified: trunk/sbin/hastd/event.h
===================================================================
--- trunk/sbin/hastd/event.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/event.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 Pawel Jakub Dawidek <pjd at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/event.h 212049 2010-08-31 09:38:43Z pjd $
  */
 
 #ifndef	_EVENT_H_

Modified: trunk/sbin/hastd/hast.conf.5
===================================================================
--- trunk/sbin/hastd/hast.conf.5	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast.conf.5	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2010 The FreeBSD Foundation
 .\" Copyright (c) 2010-2012 Pawel Jakub Dawidek <pawel at dawidek.net>
 .\" All rights reserved.
@@ -26,7 +27,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/hastd/hast.conf.5 307403 2016-10-16 22:02:50Z sevan $
 .\"
 .Dd January 25, 2012
 .Dt HAST.CONF 5
@@ -445,5 +446,5 @@
 The
 .Nm
 was written by
-.An Pawel Jakub Dawidek Aq pjd at FreeBSD.org
+.An Pawel Jakub Dawidek Aq Mt pjd at FreeBSD.org
 under sponsorship of the FreeBSD Foundation.


Property changes on: trunk/sbin/hastd/hast.conf.5
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/hastd/hast.h
===================================================================
--- trunk/sbin/hastd/hast.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -27,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/hast.h 260006 2013-12-28 19:21:22Z trociny $
  */
 
 #ifndef	_HAST_H_
@@ -137,6 +138,8 @@
 #define	HAST_CHECKSUM_CRC32	1
 #define	HAST_CHECKSUM_SHA256	2
 
+struct nv;
+
 /*
  * Structure that describes single resource.
  */
@@ -226,8 +229,10 @@
 
 	/* Activemap structure. */
 	struct activemap *hr_amp;
-	/* Locked used to synchronize access to hr_amp. */
+	/* Lock used to synchronize access to hr_amp. */
 	pthread_mutex_t hr_amp_lock;
+	/* Lock used to synchronize access to hr_amp diskmap. */
+	pthread_mutex_t hr_amp_diskmap_lock;
 
 	/* Number of BIO_READ requests. */
 	uint64_t	hr_stat_read;
@@ -252,6 +257,9 @@
 	/* Number of activemap flush errors. */
 	uint64_t	hr_stat_activemap_flush_error;
 
+	/* Function to output worker specific info on control status request. */
+	void	(*output_status_aux)(struct nv *);
+
 	/* Next resource. */
 	TAILQ_ENTRY(hast_resource) hr_next;
 };
@@ -259,8 +267,4 @@
 struct hastd_config *yy_config_parse(const char *config, bool exitonerror);
 void yy_config_free(struct hastd_config *config);
 
-void yyerror(const char *);
-int yylex(void);
-int yyparse(void);
-
 #endif	/* !_HAST_H_ */

Modified: trunk/sbin/hastd/hast_checksum.c
===================================================================
--- trunk/sbin/hastd/hast_checksum.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast_checksum.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/hast_checksum.c 228543 2011-12-15 22:03:17Z pjd $");
 
 #include <errno.h>
 #include <string.h>

Modified: trunk/sbin/hastd/hast_checksum.h
===================================================================
--- trunk/sbin/hastd/hast_checksum.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast_checksum.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/hast_checksum.h 219351 2011-03-06 22:56:14Z pjd $
  */
 
 #ifndef	_HAST_CHECKSUM_H_

Modified: trunk/sbin/hastd/hast_compression.c
===================================================================
--- trunk/sbin/hastd/hast_compression.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast_compression.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/hast_compression.c 229778 2012-01-07 16:09:33Z uqs $");
 
 #include <sys/endian.h>
 

Modified: trunk/sbin/hastd/hast_compression.h
===================================================================
--- trunk/sbin/hastd/hast_compression.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast_compression.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/hast_compression.h 219354 2011-03-06 23:09:33Z pjd $
  */
 
 #ifndef	_HAST_COMPRESSION_H_

Modified: trunk/sbin/hastd/hast_proto.c
===================================================================
--- trunk/sbin/hastd/hast_proto.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast_proto.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/hast_proto.c 246922 2013-02-17 21:12:34Z pjd $");
 
 #include <sys/endian.h>
 

Modified: trunk/sbin/hastd/hast_proto.h
===================================================================
--- trunk/sbin/hastd/hast_proto.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hast_proto.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/hast_proto.h 220744 2011-04-17 16:18:45Z trociny $
  */
 
 #ifndef	_HAST_PROTO_H_

Modified: trunk/sbin/hastd/hastd.8
===================================================================
--- trunk/sbin/hastd/hastd.8	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hastd.8	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2010 The FreeBSD Foundation
 .\" All rights reserved.
 .\"
@@ -25,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/hastd/hastd.8 307403 2016-10-16 22:02:50Z sevan $
 .\"
 .Dd February 1, 2010
 .Dt HASTD 8
@@ -51,7 +52,7 @@
 This machine is called primary.
 The
 .Nm
-daemon operates on block level, which makes it transparent for file
+daemon operates on block level, which makes it transparent to file
 systems and applications.
 .Pp
 There is one main
@@ -68,9 +69,9 @@
 hastd: <resource name> (<role>)
 .Ed
 .Pp
-When (and only when)
+If (and only if)
 .Nm
-operates in primary role for the given resource, corresponding
+operates in primary role for the given resource, a corresponding
 .Pa /dev/hast/<name>
 disk-like device (GEOM provider) is created.
 File systems and applications can use this provider to send I/O
@@ -77,11 +78,11 @@
 requests to.
 Every write, delete and flush operation
 .Dv ( BIO_WRITE , BIO_DELETE , BIO_FLUSH )
-is send to local component and synchronously replicated
-to the remote (secondary) node if it is available.
+is sent to the local component and replicated on the remote (secondary) node
+if it is available.
 Read operations
 .Dv ( BIO_READ )
-are handled locally unless I/O error occurs or local version of the data
+are handled locally unless an I/O error occurs or the local version of the data
 is not up-to-date yet (synchronization is in progress).
 .Pp
 The
@@ -100,38 +101,38 @@
 .Nm
 daemons is always initiated from the one running as primary to the one
 running as secondary.
-When primary
+When the primary
 .Nm
-is unable to connect or connection fails, it will try to re-establish
-connection every few seconds.
-Once connection is established, primary
+is unable to connect or the connection fails, it will try to re-establish
+the connection every few seconds.
+Once the connection is established, the primary
 .Nm
 will synchronize every extent that was modified during connection outage
 to the secondary
 .Nm .
 .Pp
-It is possible that in case of connection outage between the nodes
+It is possible that in the case of a connection outage between the nodes the
 .Nm
 primary role for the given resource will be configured on both nodes.
 This in turn leads to incompatible data modifications.
-Such condition is called split-brain and cannot be automatically
+Such a condition is called a split-brain and cannot be automatically
 resolved by the
 .Nm
-daemon as this will lead most likely to data corruption or lost of
+daemon as this will lead most likely to data corruption or loss of
 important changes.
 Even though it cannot be fixed by
 .Nm
-itself, it will be detected and further connection between independently
+itself, it will be detected and a further connection between independently
 modified nodes will not be possible.
-Once this situation is manually resolved by an administrator, resource
+Once this situation is manually resolved by an administrator, the resource
 on one of the nodes can be initialized (erasing local data), which makes
-connection to the remote node possible again.
-Connection of freshly initialized component will trigger full resource
+a connection to the remote node possible again.
+Connection of the freshly initialized component will trigger full resource
 synchronization.
 .Pp
-The
+A
 .Nm
-daemon itself never picks his role up automatically.
+daemon never picks its role automatically.
 The role has to be configured with the
 .Xr hastctl 8
 control utility by additional software like
@@ -139,7 +140,7 @@
 or
 .Nm heartbeat
 that can reliably manage role separation and switch secondary node to
-primary role in case of original primary failure.
+primary role in case of the primary's failure.
 .Pp
 The
 .Nm
@@ -171,7 +172,7 @@
 .Pa /var/run/hastd.pid .
 .El
 .Sh FILES
-.Bl -tag -width ".Pa /var/run/hastctl" -compact
+.Bl -tag -width ".Pa /var/run/hastd.pid" -compact
 .It Pa /etc/hast.conf
 The configuration file for
 .Nm
@@ -228,5 +229,5 @@
 The
 .Nm
 was developed by
-.An Pawel Jakub Dawidek Aq pjd at FreeBSD.org
+.An Pawel Jakub Dawidek Aq Mt pjd at FreeBSD.org
 under sponsorship of the FreeBSD Foundation.


Property changes on: trunk/sbin/hastd/hastd.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/hastd/hastd.c
===================================================================
--- trunk/sbin/hastd/hastd.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hastd.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/hastd.c 260006 2013-12-28 19:21:22Z trociny $");
 
 #include <sys/param.h>
 #include <sys/linker.h>
@@ -806,12 +807,6 @@
 		 */
 		version = 1;
 	}
-	if (version > HAST_PROTO_VERSION) {
-		pjdlog_info("Remote protocol version %hhu is not supported, falling back to version %hhu.",
-		    version, (unsigned char)HAST_PROTO_VERSION);
-		version = HAST_PROTO_VERSION;
-	}
-	pjdlog_debug(1, "Negotiated protocol version %hhu.", version);
 	token = nv_get_uint8_array(nvin, &size, "token");
 	/*
 	 * NULL token means that this is first connection.
@@ -925,6 +920,12 @@
 	 */
 
 	if (token == NULL) {
+		if (version > HAST_PROTO_VERSION) {
+			pjdlog_info("Remote protocol version %hhu is not supported, falling back to version %hhu.",
+			    version, (unsigned char)HAST_PROTO_VERSION);
+			version = HAST_PROTO_VERSION;
+		}
+		pjdlog_debug(1, "Negotiated protocol version %hhu.", version);
 		res->hr_version = version;
 		arc4random_buf(res->hr_token, sizeof(res->hr_token));
 		nvout = nv_alloc();

Modified: trunk/sbin/hastd/hastd.h
===================================================================
--- trunk/sbin/hastd/hastd.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hastd.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/hastd.h 218044 2011-01-28 21:56:47Z pjd $
  */
 
 #ifndef	_HASTD_H_

Modified: trunk/sbin/hastd/hooks.c
===================================================================
--- trunk/sbin/hastd/hooks.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hooks.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 The FreeBSD Foundation
  * Copyright (c) 2010 Pawel Jakub Dawidek <pjd at FreeBSD.org>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/hooks.c 229945 2012-01-10 22:39:07Z pjd $");
 
 #include <sys/types.h>
 #include <sys/sysctl.h>

Modified: trunk/sbin/hastd/hooks.h
===================================================================
--- trunk/sbin/hastd/hooks.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/hooks.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 The FreeBSD Foundation
  * Copyright (c) 2010 Pawel Jakub Dawidek <pjd at FreeBSD.org>
@@ -27,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/hooks.h 213429 2010-10-04 21:43:06Z pjd $
  */
 
 #ifndef	_HOOKS_H_

Modified: trunk/sbin/hastd/lzf.c
===================================================================
--- trunk/sbin/hastd/lzf.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/lzf.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp at schmorp.de>
  * 

Modified: trunk/sbin/hastd/lzf.h
===================================================================
--- trunk/sbin/hastd/lzf.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/lzf.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp at schmorp.de>
  * 
@@ -132,7 +133,11 @@
  * Unconditionally aligning does not cost very much, so do it if unsure
  */
 #ifndef STRICT_ALIGN
-# define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
+# if !(defined(__i386) || defined (__amd64))
+#  define STRICT_ALIGN 1
+# else
+#  define STRICT_ALIGN 0
+# endif
 #endif
 
 /*

Modified: trunk/sbin/hastd/metadata.c
===================================================================
--- trunk/sbin/hastd/metadata.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/metadata.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/metadata.c 229945 2012-01-10 22:39:07Z pjd $");
 
 #include <errno.h>
 #include <fcntl.h>

Modified: trunk/sbin/hastd/metadata.h
===================================================================
--- trunk/sbin/hastd/metadata.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/metadata.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/metadata.h 204076 2010-02-18 23:16:19Z pjd $
  */
 
 #ifndef	_METADATA_H_

Modified: trunk/sbin/hastd/nv.c
===================================================================
--- trunk/sbin/hastd/nv.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/nv.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/nv.c 260006 2013-12-28 19:21:22Z trociny $");
 
 #include <sys/param.h>
 #include <sys/endian.h>
@@ -566,7 +567,7 @@
 		return (NULL);
 	PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST);
 	PJDLOG_ASSERT(nvh->nvh_dsize >= 1);
-	str = NVH_DATA(nvh);
+	str = (char *)NVH_DATA(nvh);
 	PJDLOG_ASSERT(str[nvh->nvh_dsize - 1] == '\0');
 	PJDLOG_ASSERT(strlen(str) == nvh->nvh_dsize - 1);
 	return (str);

Modified: trunk/sbin/hastd/nv.h
===================================================================
--- trunk/sbin/hastd/nv.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/nv.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/nv.h 217732 2011-01-22 22:38:18Z pjd $
  */
 
 #ifndef	_NV_H_

Modified: trunk/sbin/hastd/parse.y
===================================================================
--- trunk/sbin/hastd/parse.y	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/parse.y	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 %{
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
@@ -28,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/parse.y 250914 2013-05-22 17:47:45Z jkim $
  */
 
 #include <sys/param.h>	/* MAXHOSTNAMELEN */
@@ -75,318 +76,13 @@
 static char depth1_localpath[PATH_MAX];
 static int depth1_metaflush;
 
+extern void yyerror(const char *);
+extern int yylex(void);
 extern void yyrestart(FILE *);
 
-static int
-isitme(const char *name)
-{
-	char buf[MAXHOSTNAMELEN];
-	unsigned long hostid;
-	char *pos;
-	size_t bufsize;
-
-	/*
-	 * First check if the given name matches our full hostname.
-	 */
-	if (gethostname(buf, sizeof(buf)) < 0) {
-		pjdlog_errno(LOG_ERR, "gethostname() failed");
-		return (-1);
-	}
-	if (strcmp(buf, name) == 0)
-		return (1);
-
-	/*
-	 * Check if it matches first part of the host name.
-	 */
-	pos = strchr(buf, '.');
-	if (pos != NULL && (size_t)(pos - buf) == strlen(name) &&
-	    strncmp(buf, name, pos - buf) == 0) {
-		return (1);
-	}
-
-	/*
-	 * Check if it matches host UUID.
-	 */
-	bufsize = sizeof(buf);
-	if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) {
-		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed");
-		return (-1);
-	}
-	if (strcasecmp(buf, name) == 0)
-		return (1);
-
- 	/*
-	 * Check if it matches hostid.
-	 */
-	bufsize = sizeof(hostid);
-	if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) {
-		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed");
-		return (-1);
-	}
-	(void)snprintf(buf, sizeof(buf), "hostid%lu", hostid);
-	if (strcmp(buf, name) == 0)
-		return (1);
-
-	/*
-	 * Looks like this isn't about us.
-	 */
-	return (0);
-}
-
-static bool
-family_supported(int family)
-{
-	int sock;
-
-	sock = socket(family, SOCK_STREAM, 0);
-	if (sock == -1 && errno == EPROTONOSUPPORT)
-		return (false);
-	if (sock >= 0)
-		(void)close(sock);
-	return (true);
-}
-
-static int
-node_names(char **namesp)
-{
-	static char names[MAXHOSTNAMELEN * 3];
-	char buf[MAXHOSTNAMELEN];
-	unsigned long hostid;
-	char *pos;
-	size_t bufsize;
-
-	if (gethostname(buf, sizeof(buf)) < 0) {
-		pjdlog_errno(LOG_ERR, "gethostname() failed");
-		return (-1);
-	}
-
-	/* First component of the host name. */
-	pos = strchr(buf, '.');
-	if (pos != NULL && pos != buf) {
-		(void)strlcpy(names, buf, MIN((size_t)(pos - buf + 1),
-		    sizeof(names)));
-		(void)strlcat(names, ", ", sizeof(names));
-	}
-
-	/* Full host name. */
-	(void)strlcat(names, buf, sizeof(names));
-	(void)strlcat(names, ", ", sizeof(names));
-
-	/* Host UUID. */
-	bufsize = sizeof(buf);
-	if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) {
-		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed");
-		return (-1);
-	}
-	(void)strlcat(names, buf, sizeof(names));
-	(void)strlcat(names, ", ", sizeof(names));
-
-	/* Host ID. */
-	bufsize = sizeof(hostid);
-	if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) {
-		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed");
-		return (-1);
-	}
-	(void)snprintf(buf, sizeof(buf), "hostid%lu", hostid);
-	(void)strlcat(names, buf, sizeof(names));
-
-	*namesp = names;
-
-	return (0);
-}
-
-void
-yyerror(const char *str)
-{
-
-	pjdlog_error("Unable to parse configuration file at line %d near '%s': %s",
-	    lineno, yytext, str);
-}
-
-struct hastd_config *
-yy_config_parse(const char *config, bool exitonerror)
-{
-	int ret;
-
-	curres = NULL;
-	mynode = false;
-	depth = 0;
-	lineno = 0;
-
-	depth0_timeout = HAST_TIMEOUT;
-	depth0_replication = HAST_REPLICATION_MEMSYNC;
-	depth0_checksum = HAST_CHECKSUM_NONE;
-	depth0_compression = HAST_COMPRESSION_HOLE;
-	strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control));
-	strlcpy(depth0_pidfile, HASTD_PIDFILE, sizeof(depth0_pidfile));
-	TAILQ_INIT(&depth0_listen);
-	strlcpy(depth0_listen_tcp4, HASTD_LISTEN_TCP4,
-	    sizeof(depth0_listen_tcp4));
-	strlcpy(depth0_listen_tcp6, HASTD_LISTEN_TCP6,
-	    sizeof(depth0_listen_tcp6));
-	depth0_exec[0] = '\0';
-	depth0_metaflush = 1;
-
-	lconfig = calloc(1, sizeof(*lconfig));
-	if (lconfig == NULL) {
-		pjdlog_error("Unable to allocate memory for configuration.");
-		if (exitonerror)
-			exit(EX_TEMPFAIL);
-		return (NULL);
-	}
-
-	TAILQ_INIT(&lconfig->hc_listen);
-	TAILQ_INIT(&lconfig->hc_resources);
-
-	yyin = fopen(config, "r");
-	if (yyin == NULL) {
-		pjdlog_errno(LOG_ERR, "Unable to open configuration file %s",
-		    config);
-		yy_config_free(lconfig);
-		if (exitonerror)
-			exit(EX_OSFILE);
-		return (NULL);
-	}
-	yyrestart(yyin);
-	ret = yyparse();
-	fclose(yyin);
-	if (ret != 0) {
-		yy_config_free(lconfig);
-		if (exitonerror)
-			exit(EX_CONFIG);
-		return (NULL);
-	}
-
-	/*
-	 * Let's see if everything is set up.
-	 */
-	if (lconfig->hc_controladdr[0] == '\0') {
-		strlcpy(lconfig->hc_controladdr, depth0_control,
-		    sizeof(lconfig->hc_controladdr));
-	}
-	if (lconfig->hc_pidfile[0] == '\0') {
-		strlcpy(lconfig->hc_pidfile, depth0_pidfile,
-		    sizeof(lconfig->hc_pidfile));
-	}
-	if (!TAILQ_EMPTY(&depth0_listen))
-		TAILQ_CONCAT(&lconfig->hc_listen, &depth0_listen, hl_next);
-	if (TAILQ_EMPTY(&lconfig->hc_listen)) {
-		struct hastd_listen *lst;
-
-		if (family_supported(AF_INET)) {
-			lst = calloc(1, sizeof(*lst));
-			if (lst == NULL) {
-				pjdlog_error("Unable to allocate memory for listen address.");
-				yy_config_free(lconfig);
-				if (exitonerror)
-					exit(EX_TEMPFAIL);
-				return (NULL);
-			}
-			(void)strlcpy(lst->hl_addr, depth0_listen_tcp4,
-			    sizeof(lst->hl_addr));
-			TAILQ_INSERT_TAIL(&lconfig->hc_listen, lst, hl_next);
-		} else {
-			pjdlog_debug(1,
-			    "No IPv4 support in the kernel, not listening on IPv4 address.");
-		}
-		if (family_supported(AF_INET6)) {
-			lst = calloc(1, sizeof(*lst));
-			if (lst == NULL) {
-				pjdlog_error("Unable to allocate memory for listen address.");
-				yy_config_free(lconfig);
-				if (exitonerror)
-					exit(EX_TEMPFAIL);
-				return (NULL);
-			}
-			(void)strlcpy(lst->hl_addr, depth0_listen_tcp6,
-			    sizeof(lst->hl_addr));
-			TAILQ_INSERT_TAIL(&lconfig->hc_listen, lst, hl_next);
-		} else {
-			pjdlog_debug(1,
-			    "No IPv6 support in the kernel, not listening on IPv6 address.");
-		}
-		if (TAILQ_EMPTY(&lconfig->hc_listen)) {
-			pjdlog_error("No address to listen on.");
-			yy_config_free(lconfig);
-			if (exitonerror)
-				exit(EX_TEMPFAIL);
-			return (NULL);
-		}
-	}
-	TAILQ_FOREACH(curres, &lconfig->hc_resources, hr_next) {
-		PJDLOG_ASSERT(curres->hr_provname[0] != '\0');
-		PJDLOG_ASSERT(curres->hr_localpath[0] != '\0');
-		PJDLOG_ASSERT(curres->hr_remoteaddr[0] != '\0');
-
-		if (curres->hr_replication == -1) {
-			/*
-			 * Replication is not set at resource-level.
-			 * Use global or default setting.
-			 */
-			curres->hr_replication = depth0_replication;
-			curres->hr_original_replication = depth0_replication;
-		}
-		if (curres->hr_checksum == -1) {
-			/*
-			 * Checksum is not set at resource-level.
-			 * Use global or default setting.
-			 */
-			curres->hr_checksum = depth0_checksum;
-		}
-		if (curres->hr_compression == -1) {
-			/*
-			 * Compression is not set at resource-level.
-			 * Use global or default setting.
-			 */
-			curres->hr_compression = depth0_compression;
-		}
-		if (curres->hr_timeout == -1) {
-			/*
-			 * Timeout is not set at resource-level.
-			 * Use global or default setting.
-			 */
-			curres->hr_timeout = depth0_timeout;
-		}
-		if (curres->hr_exec[0] == '\0') {
-			/*
-			 * Exec is not set at resource-level.
-			 * Use global or default setting.
-			 */
-			strlcpy(curres->hr_exec, depth0_exec,
-			    sizeof(curres->hr_exec));
-		}
-		if (curres->hr_metaflush == -1) {
-			/*
-			 * Metaflush is not set at resource-level.
-			 * Use global or default setting.
-			 */
-			curres->hr_metaflush = depth0_metaflush;
-		}
-	}
-
-	return (lconfig);
-}
-
-void
-yy_config_free(struct hastd_config *config)
-{
-	struct hastd_listen *lst;
-	struct hast_resource *res;
-
-	while ((lst = TAILQ_FIRST(&depth0_listen)) != NULL) {
-		TAILQ_REMOVE(&depth0_listen, lst, hl_next);
-		free(lst);
-	}
-	while ((lst = TAILQ_FIRST(&config->hc_listen)) != NULL) {
-		TAILQ_REMOVE(&config->hc_listen, lst, hl_next);
-		free(lst);
-	}
-	while ((res = TAILQ_FIRST(&config->hc_resources)) != NULL) {
-		TAILQ_REMOVE(&config->hc_resources, res, hr_next);
-		free(res);
-	}
-	free(config);
-}
+static int isitme(const char *name);
+static bool family_supported(int family);
+static int node_names(char **namesp);
 %}
 
 %token CONTROL PIDFILE LISTEN REPLICATION CHECKSUM COMPRESSION METAFLUSH
@@ -1027,3 +723,316 @@
 		free($2);
 	}
 	;
+
+%%
+
+static int
+isitme(const char *name)
+{
+	char buf[MAXHOSTNAMELEN];
+	unsigned long hostid;
+	char *pos;
+	size_t bufsize;
+
+	/*
+	 * First check if the given name matches our full hostname.
+	 */
+	if (gethostname(buf, sizeof(buf)) < 0) {
+		pjdlog_errno(LOG_ERR, "gethostname() failed");
+		return (-1);
+	}
+	if (strcmp(buf, name) == 0)
+		return (1);
+
+	/*
+	 * Check if it matches first part of the host name.
+	 */
+	pos = strchr(buf, '.');
+	if (pos != NULL && (size_t)(pos - buf) == strlen(name) &&
+	    strncmp(buf, name, pos - buf) == 0) {
+		return (1);
+	}
+
+	/*
+	 * Check if it matches host UUID.
+	 */
+	bufsize = sizeof(buf);
+	if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) {
+		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed");
+		return (-1);
+	}
+	if (strcasecmp(buf, name) == 0)
+		return (1);
+
+	/*
+	 * Check if it matches hostid.
+	 */
+	bufsize = sizeof(hostid);
+	if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) {
+		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed");
+		return (-1);
+	}
+	(void)snprintf(buf, sizeof(buf), "hostid%lu", hostid);
+	if (strcmp(buf, name) == 0)
+		return (1);
+
+	/*
+	 * Looks like this isn't about us.
+	 */
+	return (0);
+}
+
+static bool
+family_supported(int family)
+{
+	int sock;
+
+	sock = socket(family, SOCK_STREAM, 0);
+	if (sock == -1 && errno == EPROTONOSUPPORT)
+		return (false);
+	if (sock >= 0)
+		(void)close(sock);
+	return (true);
+}
+
+static int
+node_names(char **namesp)
+{
+	static char names[MAXHOSTNAMELEN * 3];
+	char buf[MAXHOSTNAMELEN];
+	unsigned long hostid;
+	char *pos;
+	size_t bufsize;
+
+	if (gethostname(buf, sizeof(buf)) < 0) {
+		pjdlog_errno(LOG_ERR, "gethostname() failed");
+		return (-1);
+	}
+
+	/* First component of the host name. */
+	pos = strchr(buf, '.');
+	if (pos != NULL && pos != buf) {
+		(void)strlcpy(names, buf, MIN((size_t)(pos - buf + 1),
+		    sizeof(names)));
+		(void)strlcat(names, ", ", sizeof(names));
+	}
+
+	/* Full host name. */
+	(void)strlcat(names, buf, sizeof(names));
+	(void)strlcat(names, ", ", sizeof(names));
+
+	/* Host UUID. */
+	bufsize = sizeof(buf);
+	if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) {
+		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed");
+		return (-1);
+	}
+	(void)strlcat(names, buf, sizeof(names));
+	(void)strlcat(names, ", ", sizeof(names));
+
+	/* Host ID. */
+	bufsize = sizeof(hostid);
+	if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) {
+		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed");
+		return (-1);
+	}
+	(void)snprintf(buf, sizeof(buf), "hostid%lu", hostid);
+	(void)strlcat(names, buf, sizeof(names));
+
+	*namesp = names;
+
+	return (0);
+}
+
+void
+yyerror(const char *str)
+{
+
+	pjdlog_error("Unable to parse configuration file at line %d near '%s': %s",
+	    lineno, yytext, str);
+}
+
+struct hastd_config *
+yy_config_parse(const char *config, bool exitonerror)
+{
+	int ret;
+
+	curres = NULL;
+	mynode = false;
+	depth = 0;
+	lineno = 0;
+
+	depth0_timeout = HAST_TIMEOUT;
+	depth0_replication = HAST_REPLICATION_MEMSYNC;
+	depth0_checksum = HAST_CHECKSUM_NONE;
+	depth0_compression = HAST_COMPRESSION_HOLE;
+	strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control));
+	strlcpy(depth0_pidfile, HASTD_PIDFILE, sizeof(depth0_pidfile));
+	TAILQ_INIT(&depth0_listen);
+	strlcpy(depth0_listen_tcp4, HASTD_LISTEN_TCP4,
+	    sizeof(depth0_listen_tcp4));
+	strlcpy(depth0_listen_tcp6, HASTD_LISTEN_TCP6,
+	    sizeof(depth0_listen_tcp6));
+	depth0_exec[0] = '\0';
+	depth0_metaflush = 1;
+
+	lconfig = calloc(1, sizeof(*lconfig));
+	if (lconfig == NULL) {
+		pjdlog_error("Unable to allocate memory for configuration.");
+		if (exitonerror)
+			exit(EX_TEMPFAIL);
+		return (NULL);
+	}
+
+	TAILQ_INIT(&lconfig->hc_listen);
+	TAILQ_INIT(&lconfig->hc_resources);
+
+	yyin = fopen(config, "r");
+	if (yyin == NULL) {
+		pjdlog_errno(LOG_ERR, "Unable to open configuration file %s",
+		    config);
+		yy_config_free(lconfig);
+		if (exitonerror)
+			exit(EX_OSFILE);
+		return (NULL);
+	}
+	yyrestart(yyin);
+	ret = yyparse();
+	fclose(yyin);
+	if (ret != 0) {
+		yy_config_free(lconfig);
+		if (exitonerror)
+			exit(EX_CONFIG);
+		return (NULL);
+	}
+
+	/*
+	 * Let's see if everything is set up.
+	 */
+	if (lconfig->hc_controladdr[0] == '\0') {
+		strlcpy(lconfig->hc_controladdr, depth0_control,
+		    sizeof(lconfig->hc_controladdr));
+	}
+	if (lconfig->hc_pidfile[0] == '\0') {
+		strlcpy(lconfig->hc_pidfile, depth0_pidfile,
+		    sizeof(lconfig->hc_pidfile));
+	}
+	if (!TAILQ_EMPTY(&depth0_listen))
+		TAILQ_CONCAT(&lconfig->hc_listen, &depth0_listen, hl_next);
+	if (TAILQ_EMPTY(&lconfig->hc_listen)) {
+		struct hastd_listen *lst;
+
+		if (family_supported(AF_INET)) {
+			lst = calloc(1, sizeof(*lst));
+			if (lst == NULL) {
+				pjdlog_error("Unable to allocate memory for listen address.");
+				yy_config_free(lconfig);
+				if (exitonerror)
+					exit(EX_TEMPFAIL);
+				return (NULL);
+			}
+			(void)strlcpy(lst->hl_addr, depth0_listen_tcp4,
+			    sizeof(lst->hl_addr));
+			TAILQ_INSERT_TAIL(&lconfig->hc_listen, lst, hl_next);
+		} else {
+			pjdlog_debug(1,
+			    "No IPv4 support in the kernel, not listening on IPv4 address.");
+		}
+		if (family_supported(AF_INET6)) {
+			lst = calloc(1, sizeof(*lst));
+			if (lst == NULL) {
+				pjdlog_error("Unable to allocate memory for listen address.");
+				yy_config_free(lconfig);
+				if (exitonerror)
+					exit(EX_TEMPFAIL);
+				return (NULL);
+			}
+			(void)strlcpy(lst->hl_addr, depth0_listen_tcp6,
+			    sizeof(lst->hl_addr));
+			TAILQ_INSERT_TAIL(&lconfig->hc_listen, lst, hl_next);
+		} else {
+			pjdlog_debug(1,
+			    "No IPv6 support in the kernel, not listening on IPv6 address.");
+		}
+		if (TAILQ_EMPTY(&lconfig->hc_listen)) {
+			pjdlog_error("No address to listen on.");
+			yy_config_free(lconfig);
+			if (exitonerror)
+				exit(EX_TEMPFAIL);
+			return (NULL);
+		}
+	}
+	TAILQ_FOREACH(curres, &lconfig->hc_resources, hr_next) {
+		PJDLOG_ASSERT(curres->hr_provname[0] != '\0');
+		PJDLOG_ASSERT(curres->hr_localpath[0] != '\0');
+		PJDLOG_ASSERT(curres->hr_remoteaddr[0] != '\0');
+
+		if (curres->hr_replication == -1) {
+			/*
+			 * Replication is not set at resource-level.
+			 * Use global or default setting.
+			 */
+			curres->hr_replication = depth0_replication;
+			curres->hr_original_replication = depth0_replication;
+		}
+		if (curres->hr_checksum == -1) {
+			/*
+			 * Checksum is not set at resource-level.
+			 * Use global or default setting.
+			 */
+			curres->hr_checksum = depth0_checksum;
+		}
+		if (curres->hr_compression == -1) {
+			/*
+			 * Compression is not set at resource-level.
+			 * Use global or default setting.
+			 */
+			curres->hr_compression = depth0_compression;
+		}
+		if (curres->hr_timeout == -1) {
+			/*
+			 * Timeout is not set at resource-level.
+			 * Use global or default setting.
+			 */
+			curres->hr_timeout = depth0_timeout;
+		}
+		if (curres->hr_exec[0] == '\0') {
+			/*
+			 * Exec is not set at resource-level.
+			 * Use global or default setting.
+			 */
+			strlcpy(curres->hr_exec, depth0_exec,
+			    sizeof(curres->hr_exec));
+		}
+		if (curres->hr_metaflush == -1) {
+			/*
+			 * Metaflush is not set at resource-level.
+			 * Use global or default setting.
+			 */
+			curres->hr_metaflush = depth0_metaflush;
+		}
+	}
+
+	return (lconfig);
+}
+
+void
+yy_config_free(struct hastd_config *config)
+{
+	struct hastd_listen *lst;
+	struct hast_resource *res;
+
+	while ((lst = TAILQ_FIRST(&depth0_listen)) != NULL) {
+		TAILQ_REMOVE(&depth0_listen, lst, hl_next);
+		free(lst);
+	}
+	while ((lst = TAILQ_FIRST(&config->hc_listen)) != NULL) {
+		TAILQ_REMOVE(&config->hc_listen, lst, hl_next);
+		free(lst);
+	}
+	while ((res = TAILQ_FIRST(&config->hc_resources)) != NULL) {
+		TAILQ_REMOVE(&config->hc_resources, res, hr_next);
+		free(res);
+	}
+	free(config);
+}


Property changes on: trunk/sbin/hastd/parse.y
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/hastd/pjdlog.c
===================================================================
--- trunk/sbin/hastd/pjdlog.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/pjdlog.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pjd at FreeBSD.org>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/pjdlog.c 225773 2011-09-27 06:43:51Z pjd $");
 
 #include <sys/types.h>
 #include <sys/socket.h>

Modified: trunk/sbin/hastd/pjdlog.h
===================================================================
--- trunk/sbin/hastd/pjdlog.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/pjdlog.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pjd at FreeBSD.org>
@@ -27,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/pjdlog.h 242593 2012-11-05 00:38:14Z pjd $
  */
 
 #ifndef	_PJDLOG_H_
@@ -95,7 +96,7 @@
 #define	PJDLOG_VERIFY(expr)	do {					\
 	if (!(expr)) {							\
 		pjdlog_abort(__func__, __FILE__, __LINE__, #expr,	\
-		    "%s", __func__);					\
+		    __func__);						\
 	}								\
 } while (0)
 #define	PJDLOG_RVERIFY(expr, ...)	do {				\

Modified: trunk/sbin/hastd/primary.c
===================================================================
--- trunk/sbin/hastd/primary.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/primary.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009 The FreeBSD Foundation
  * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/primary.c 260006 2013-12-28 19:21:22Z trociny $");
 
 #include <sys/types.h>
 #include <sys/time.h>
@@ -78,7 +79,7 @@
 	 * kernel. Each component has to decrease this counter by one
 	 * even on failure.
 	 */
-	unsigned int		 hio_countdown;
+	refcnt_t		 hio_countdown;
 	/*
 	 * Each component has a place to store its own error.
 	 * Once the request is handled by all components we can decide if the
@@ -94,6 +95,15 @@
 	 */
 	bool			 hio_done;
 	/*
+	 * Number of components we are still waiting before sending write
+	 * completion ack to GEOM Gate. Used for memsync.
+	 */
+	refcnt_t		 hio_writecount;
+	/*
+	 * Memsync request was acknowleged by remote.
+	 */
+	bool			 hio_memsyncacked;
+	/*
 	 * Remember replication from the time the request was initiated,
 	 * so we won't get confused when replication changes on reload.
 	 */
@@ -108,6 +118,7 @@
  * until some in-progress requests are freed.
  */
 static TAILQ_HEAD(, hio) hio_free_list;
+static size_t hio_free_list_size;
 static pthread_mutex_t hio_free_list_lock;
 static pthread_cond_t hio_free_list_cond;
 /*
@@ -116,20 +127,26 @@
  * responsible for managing his own send list.
  */
 static TAILQ_HEAD(, hio) *hio_send_list;
+static size_t *hio_send_list_size;
 static pthread_mutex_t *hio_send_list_lock;
 static pthread_cond_t *hio_send_list_cond;
+#define	hio_send_local_list_size	hio_send_list_size[0]
+#define	hio_send_remote_list_size	hio_send_list_size[1]
 /*
  * There is one recv list for every component, although local components don't
  * use recv lists as local requests are done synchronously.
  */
 static TAILQ_HEAD(, hio) *hio_recv_list;
+static size_t *hio_recv_list_size;
 static pthread_mutex_t *hio_recv_list_lock;
 static pthread_cond_t *hio_recv_list_cond;
+#define	hio_recv_remote_list_size	hio_recv_list_size[1]
 /*
  * Request is placed on done list by the slowest component (the one that
  * decreased hio_countdown from 1 to 0).
  */
 static TAILQ_HEAD(, hio) hio_done_list;
+static size_t hio_done_list_size;
 static pthread_mutex_t hio_done_list_lock;
 static pthread_cond_t hio_done_list_cond;
 /*
@@ -164,25 +181,21 @@
 	((res)->hr_remotein != NULL && (res)->hr_remoteout != NULL)
 
 #define	QUEUE_INSERT1(hio, name, ncomp)	do {				\
-	bool _wakeup;							\
-									\
 	mtx_lock(&hio_##name##_list_lock[(ncomp)]);			\
-	_wakeup = TAILQ_EMPTY(&hio_##name##_list[(ncomp)]);		\
+	if (TAILQ_EMPTY(&hio_##name##_list[(ncomp)]))			\
+		cv_broadcast(&hio_##name##_list_cond[(ncomp)]);		\
 	TAILQ_INSERT_TAIL(&hio_##name##_list[(ncomp)], (hio),		\
 	    hio_next[(ncomp)]);						\
-	mtx_unlock(&hio_##name##_list_lock[ncomp]);			\
-	if (_wakeup)							\
-		cv_signal(&hio_##name##_list_cond[(ncomp)]);		\
+	hio_##name##_list_size[(ncomp)]++;				\
+	mtx_unlock(&hio_##name##_list_lock[(ncomp)]);			\
 } while (0)
 #define	QUEUE_INSERT2(hio, name)	do {				\
-	bool _wakeup;							\
-									\
 	mtx_lock(&hio_##name##_list_lock);				\
-	_wakeup = TAILQ_EMPTY(&hio_##name##_list);			\
+	if (TAILQ_EMPTY(&hio_##name##_list))				\
+		cv_broadcast(&hio_##name##_list_cond);			\
 	TAILQ_INSERT_TAIL(&hio_##name##_list, (hio), hio_##name##_next);\
+	hio_##name##_list_size++;					\
 	mtx_unlock(&hio_##name##_list_lock);				\
-	if (_wakeup)							\
-		cv_signal(&hio_##name##_list_cond);			\
 } while (0)
 #define	QUEUE_TAKE1(hio, name, ncomp, timeout)	do {			\
 	bool _last;							\
@@ -196,6 +209,8 @@
 			_last = true;					\
 	}								\
 	if (hio != NULL) {						\
+		PJDLOG_ASSERT(hio_##name##_list_size[(ncomp)] != 0);	\
+		hio_##name##_list_size[(ncomp)]--;			\
 		TAILQ_REMOVE(&hio_##name##_list[(ncomp)], (hio),	\
 		    hio_next[(ncomp)]);					\
 	}								\
@@ -207,10 +222,16 @@
 		cv_wait(&hio_##name##_list_cond,			\
 		    &hio_##name##_list_lock);				\
 	}								\
+	PJDLOG_ASSERT(hio_##name##_list_size != 0);			\
+	hio_##name##_list_size--;					\
 	TAILQ_REMOVE(&hio_##name##_list, (hio), hio_##name##_next);	\
 	mtx_unlock(&hio_##name##_list_lock);				\
 } while (0)
 
+#define ISFULLSYNC(hio)	((hio)->hio_replication == HAST_REPLICATION_FULLSYNC)
+#define ISMEMSYNC(hio)	((hio)->hio_replication == HAST_REPLICATION_MEMSYNC)
+#define ISASYNC(hio)	((hio)->hio_replication == HAST_REPLICATION_ASYNC)
+
 #define	SYNCREQ(hio)		do {					\
 	(hio)->hio_ggio.gctl_unit = -1;					\
 	(hio)->hio_ggio.gctl_seq = 1;					\
@@ -219,6 +240,9 @@
 #define	SYNCREQDONE(hio)	do { (hio)->hio_ggio.gctl_unit = -2; } while (0)
 #define	ISSYNCREQDONE(hio)	((hio)->hio_ggio.gctl_unit == -2)
 
+#define ISMEMSYNCWRITE(hio)	(ISMEMSYNC(hio) &&			\
+	    (hio)->hio_ggio.gctl_cmd == BIO_WRITE && !ISSYNCREQ(hio))
+
 static struct hast_resource *gres;
 
 static pthread_mutex_t range_lock;
@@ -239,6 +263,22 @@
 static void *guard_thread(void *arg);
 
 static void
+output_status_aux(struct nv *nvout)
+{
+
+	nv_add_uint64(nvout, (uint64_t)hio_free_list_size,
+	    "idle_queue_size");
+	nv_add_uint64(nvout, (uint64_t)hio_send_local_list_size,
+	    "local_queue_size");
+	nv_add_uint64(nvout, (uint64_t)hio_send_remote_list_size,
+	    "send_queue_size");
+	nv_add_uint64(nvout, (uint64_t)hio_recv_remote_list_size,
+	    "recv_queue_size");
+	nv_add_uint64(nvout, (uint64_t)hio_done_list_size,
+	    "done_queue_size");
+}
+
+static void
 cleanup(struct hast_resource *res)
 {
 	int rerrno;
@@ -291,22 +331,28 @@
 	exit(exitcode);
 }
 
+/* Expects res->hr_amp locked, returns unlocked. */
 static int
 hast_activemap_flush(struct hast_resource *res)
 {
 	const unsigned char *buf;
 	size_t size;
+	int ret;
 
+	mtx_lock(&res->hr_amp_diskmap_lock);
 	buf = activemap_bitmap(res->hr_amp, &size);
+	mtx_unlock(&res->hr_amp_lock);
 	PJDLOG_ASSERT(buf != NULL);
 	PJDLOG_ASSERT((size % res->hr_local_sectorsize) == 0);
+	ret = 0;
 	if (pwrite(res->hr_localfd, buf, size, METADATA_SIZE) !=
 	    (ssize_t)size) {
 		pjdlog_errno(LOG_ERR, "Unable to flush activemap to disk");
 		res->hr_stat_activemap_write_error++;
-		return (-1);
+		ret = -1;
 	}
-	if (res->hr_metaflush == 1 && g_flush(res->hr_localfd) == -1) {
+	if (ret == 0 && res->hr_metaflush == 1 &&
+	    g_flush(res->hr_localfd) == -1) {
 		if (errno == EOPNOTSUPP) {
 			pjdlog_warning("The %s provider doesn't support flushing write cache. Disabling it.",
 			    res->hr_localpath);
@@ -315,10 +361,11 @@
 			pjdlog_errno(LOG_ERR,
 			    "Unable to flush disk cache on activemap update");
 			res->hr_stat_activemap_flush_error++;
-			return (-1);
+			ret = -1;
 		}
 	}
-	return (0);
+	mtx_unlock(&res->hr_amp_diskmap_lock);
+	return (ret);
 }
 
 static bool
@@ -348,6 +395,12 @@
 		    "Unable to allocate %zu bytes of memory for send lists.",
 		    sizeof(hio_send_list[0]) * ncomps);
 	}
+	hio_send_list_size = malloc(sizeof(hio_send_list_size[0]) * ncomps);
+	if (hio_send_list_size == NULL) {
+		primary_exitx(EX_TEMPFAIL,
+		    "Unable to allocate %zu bytes of memory for send list counters.",
+		    sizeof(hio_send_list_size[0]) * ncomps);
+	}
 	hio_send_list_lock = malloc(sizeof(hio_send_list_lock[0]) * ncomps);
 	if (hio_send_list_lock == NULL) {
 		primary_exitx(EX_TEMPFAIL,
@@ -366,6 +419,12 @@
 		    "Unable to allocate %zu bytes of memory for recv lists.",
 		    sizeof(hio_recv_list[0]) * ncomps);
 	}
+	hio_recv_list_size = malloc(sizeof(hio_recv_list_size[0]) * ncomps);
+	if (hio_recv_list_size == NULL) {
+		primary_exitx(EX_TEMPFAIL,
+		    "Unable to allocate %zu bytes of memory for recv list counters.",
+		    sizeof(hio_recv_list_size[0]) * ncomps);
+	}
 	hio_recv_list_lock = malloc(sizeof(hio_recv_list_lock[0]) * ncomps);
 	if (hio_recv_list_lock == NULL) {
 		primary_exitx(EX_TEMPFAIL,
@@ -386,7 +445,7 @@
 	}
 
 	/*
-	 * Initialize lists, their locks and theirs condition variables.
+	 * Initialize lists, their counters, locks and condition variables.
 	 */
 	TAILQ_INIT(&hio_free_list);
 	mtx_init(&hio_free_list_lock);
@@ -393,9 +452,11 @@
 	cv_init(&hio_free_list_cond);
 	for (ii = 0; ii < HAST_NCOMPONENTS; ii++) {
 		TAILQ_INIT(&hio_send_list[ii]);
+		hio_send_list_size[ii] = 0;
 		mtx_init(&hio_send_list_lock[ii]);
 		cv_init(&hio_send_list_cond[ii]);
 		TAILQ_INIT(&hio_recv_list[ii]);
+		hio_recv_list_size[ii] = 0;
 		mtx_init(&hio_recv_list_lock[ii]);
 		cv_init(&hio_recv_list_cond[ii]);
 		rw_init(&hio_remote_lock[ii]);
@@ -415,7 +476,7 @@
 			    "Unable to allocate %zu bytes of memory for hio request.",
 			    sizeof(*hio));
 		}
-		hio->hio_countdown = 0;
+		refcnt_init(&hio->hio_countdown, 0);
 		hio->hio_errors = malloc(sizeof(hio->hio_errors[0]) * ncomps);
 		if (hio->hio_errors == NULL) {
 			primary_exitx(EX_TEMPFAIL,
@@ -438,6 +499,7 @@
 		hio->hio_ggio.gctl_length = MAXPHYS;
 		hio->hio_ggio.gctl_error = 0;
 		TAILQ_INSERT_HEAD(&hio_free_list, hio, hio_free_next);
+		hio_free_list_size++;
 	}
 }
 
@@ -774,6 +836,7 @@
 			free(map);
 			goto close;
 		}
+		mtx_lock(&res->hr_amp_lock);
 		/*
 		 * Merge local and remote bitmaps.
 		 */
@@ -955,6 +1018,7 @@
 	}
 
 	gres = res;
+	res->output_status_aux = output_status_aux;
 	mode = pjdlog_mode_get();
 	debuglevel = pjdlog_debug_get();
 
@@ -1288,8 +1352,13 @@
 			    ggio->gctl_offset, ggio->gctl_length)) {
 				res->hr_stat_activemap_update++;
 				(void)hast_activemap_flush(res);
+			} else {
+				mtx_unlock(&res->hr_amp_lock);
 			}
-			mtx_unlock(&res->hr_amp_lock);
+			if (ISMEMSYNC(hio)) {
+				hio->hio_memsyncacked = false;
+				refcnt_init(&hio->hio_writecount, ncomps);
+			}
 			break;
 		case BIO_DELETE:
 			res->hr_stat_delete++;
@@ -1300,12 +1369,7 @@
 		}
 		pjdlog_debug(2,
 		    "ggate_recv: (%p) Moving request to the send queues.", hio);
-		hio->hio_countdown = ncomps;
-		if (hio->hio_replication == HAST_REPLICATION_MEMSYNC &&
-		    ggio->gctl_cmd == BIO_WRITE) {
-			/* Each remote request needs two responses in memsync. */
-			hio->hio_countdown++;
-		}
+		refcnt_init(&hio->hio_countdown, ncomps);
 		for (ii = ncomp; ii < ncomps; ii++)
 			QUEUE_INSERT1(hio, send, ii);
 	}
@@ -1376,8 +1440,7 @@
 				    ret, (intmax_t)ggio->gctl_length);
 			} else {
 				hio->hio_errors[ncomp] = 0;
-				if (hio->hio_replication ==
-				    HAST_REPLICATION_ASYNC) {
+				if (ISASYNC(hio)) {
 					ggio->gctl_error = 0;
 					write_complete(res, hio);
 				}
@@ -1415,42 +1478,13 @@
 			}
 			break;
 		}
-
-		if (hio->hio_replication != HAST_REPLICATION_MEMSYNC ||
-		    ggio->gctl_cmd != BIO_WRITE || ISSYNCREQ(hio)) {
-			if (refcnt_release(&hio->hio_countdown) > 0)
-				continue;
-		} else {
-			/*
-			 * Depending on hio_countdown value, requests finished
-			 * in the following order:
-			 * 0: remote memsync, remote final, local write
-			 * 1: remote memsync, local write, (remote final)
-			 * 2: local write, (remote memsync), (remote final)
-			 */
-			switch (refcnt_release(&hio->hio_countdown)) {
-			case 0:
-				/*
-				 * Local write finished as last.
-				 */
-				break;
-			case 1:
-				/*
-				 * Local write finished after remote memsync
-				 * reply arrvied. We can complete the write now.
-				 */
-				if (hio->hio_errors[0] == 0)
-					write_complete(res, hio);
-				continue;
-			case 2:
-				/*
-				 * Local write finished as first.
-				 */
-				continue;
-			default:
-				PJDLOG_ABORT("Invalid hio_countdown.");
+		if (ISMEMSYNCWRITE(hio)) {
+			if (refcnt_release(&hio->hio_writecount) == 0) {
+				write_complete(res, hio);
 			}
 		}
+		if (refcnt_release(&hio->hio_countdown) > 0)
+			continue;
 		if (ISSYNCREQ(hio)) {
 			mtx_lock(&sync_lock);
 			SYNCREQDONE(hio);
@@ -1572,10 +1606,8 @@
 		nv_add_uint64(nv, (uint64_t)ggio->gctl_seq, "seq");
 		nv_add_uint64(nv, offset, "offset");
 		nv_add_uint64(nv, length, "length");
-		if (hio->hio_replication == HAST_REPLICATION_MEMSYNC &&
-		    ggio->gctl_cmd == BIO_WRITE && !ISSYNCREQ(hio)) {
+		if (ISMEMSYNCWRITE(hio))
 			nv_add_uint8(nv, 1, "memsync");
-		}
 		if (nv_error(nv) != 0) {
 			hio->hio_errors[ncomp] = nv_error(nv);
 			pjdlog_debug(2,
@@ -1607,6 +1639,7 @@
 		mtx_lock(&hio_recv_list_lock[ncomp]);
 		wakeup = TAILQ_EMPTY(&hio_recv_list[ncomp]);
 		TAILQ_INSERT_TAIL(&hio_recv_list[ncomp], hio, hio_next[ncomp]);
+		hio_recv_list_size[ncomp]++;
 		mtx_unlock(&hio_recv_list_lock[ncomp]);
 		if (hast_proto_send(res, res->hr_remoteout, nv, data,
 		    data != NULL ? length : 0) == -1) {
@@ -1618,17 +1651,9 @@
 			    "Unable to send request (%s): ",
 			    strerror(hio->hio_errors[ncomp]));
 			remote_close(res, ncomp);
-			/*
-			 * Take request back from the receive queue and move
-			 * it immediately to the done queue.
-			 */
-			mtx_lock(&hio_recv_list_lock[ncomp]);
-			TAILQ_REMOVE(&hio_recv_list[ncomp], hio,
-			    hio_next[ncomp]);
-			mtx_unlock(&hio_recv_list_lock[ncomp]);
-			goto done_queue;
+		} else {
+			rw_unlock(&hio_remote_lock[ncomp]);
 		}
-		rw_unlock(&hio_remote_lock[ncomp]);
 		nv_free(nv);
 		if (wakeup)
 			cv_signal(&hio_recv_list_cond[ncomp]);
@@ -1649,10 +1674,15 @@
 			if (activemap_need_sync(res->hr_amp, ggio->gctl_offset,
 			    ggio->gctl_length)) {
 				(void)hast_activemap_flush(res);
+			} else {
+				mtx_unlock(&res->hr_amp_lock);
 			}
-			mtx_unlock(&res->hr_amp_lock);
-			if (hio->hio_replication == HAST_REPLICATION_MEMSYNC)
-				(void)refcnt_release(&hio->hio_countdown);
+			if (ISMEMSYNCWRITE(hio)) {
+				if (refcnt_release(&hio->hio_writecount) == 0) {
+					if (hio->hio_errors[0] == 0)
+						write_complete(res, hio);
+				}
+			}
 		}
 		if (refcnt_release(&hio->hio_countdown) > 0)
 			continue;
@@ -1708,7 +1738,9 @@
 			PJDLOG_ASSERT(hio != NULL);
 			TAILQ_REMOVE(&hio_recv_list[ncomp], hio,
 			    hio_next[ncomp]);
+			hio_recv_list_size[ncomp]--;
 			mtx_unlock(&hio_recv_list_lock[ncomp]);
+			hio->hio_errors[ncomp] = ENOTCONN;
 			goto done_queue;
 		}
 		if (hast_proto_recv_hdr(res->hr_remotein, &nv) == -1) {
@@ -1731,6 +1763,7 @@
 			if (hio->hio_ggio.gctl_seq == seq) {
 				TAILQ_REMOVE(&hio_recv_list[ncomp], hio,
 				    hio_next[ncomp]);
+				hio_recv_list_size[ncomp]--;
 				break;
 			}
 		}
@@ -1781,80 +1814,34 @@
 		hio->hio_errors[ncomp] = 0;
 		nv_free(nv);
 done_queue:
-		if (hio->hio_replication != HAST_REPLICATION_MEMSYNC ||
-		    hio->hio_ggio.gctl_cmd != BIO_WRITE || ISSYNCREQ(hio)) {
-			if (refcnt_release(&hio->hio_countdown) > 0)
-				continue;
-		} else {
-			/*
-			 * Depending on hio_countdown value, requests finished
-			 * in the following order:
-			 *
-			 * 0: local write, remote memsync, remote final
-			 * or
-			 * 0: remote memsync, local write, remote final
-			 *
-			 * 1: local write, remote memsync, (remote final)
-			 * or
-			 * 1: remote memsync, remote final, (local write)
-			 *
-			 * 2: remote memsync, (local write), (remote final)
-			 * or
-			 * 2: remote memsync, (remote final), (local write)
-			 */
-			switch (refcnt_release(&hio->hio_countdown)) {
-			case 0:
-				/*
-				 * Remote final reply arrived.
-				 */
-				PJDLOG_ASSERT(!memsyncack);
-				break;
-			case 1:
-				if (memsyncack) {
-					/*
-					 * Local request already finished, so we
-					 * can complete the write.
-					 */
+		if (ISMEMSYNCWRITE(hio)) {
+			if (!hio->hio_memsyncacked) {
+				PJDLOG_ASSERT(memsyncack ||
+				    hio->hio_errors[ncomp] != 0);
+				/* Remote ack arrived. */
+				if (refcnt_release(&hio->hio_writecount) == 0) {
 					if (hio->hio_errors[0] == 0)
 						write_complete(res, hio);
-					/*
-					 * We still need to wait for final
-					 * remote reply.
-					 */
+				}
+				hio->hio_memsyncacked = true;
+				if (hio->hio_errors[ncomp] == 0) {
 					pjdlog_debug(2,
-					    "remote_recv: (%p) Moving request back to the recv queue.",
-					    hio);
+					    "remote_recv: (%p) Moving request "
+					    "back to the recv queue.", hio);
 					mtx_lock(&hio_recv_list_lock[ncomp]);
 					TAILQ_INSERT_TAIL(&hio_recv_list[ncomp],
 					    hio, hio_next[ncomp]);
+					hio_recv_list_size[ncomp]++;
 					mtx_unlock(&hio_recv_list_lock[ncomp]);
-				} else {
-					/*
-					 * Remote final reply arrived before
-					 * local write finished.
-					 * Nothing to do in such case.
-					 */
+					continue;
 				}
-				continue;
-			case 2:
-				/*
-				 * We received remote memsync reply even before
-				 * local write finished.
-				 */
-				PJDLOG_ASSERT(memsyncack);
-
-				pjdlog_debug(2,
-				    "remote_recv: (%p) Moving request back to the recv queue.",
-				    hio);
-				mtx_lock(&hio_recv_list_lock[ncomp]);
-				TAILQ_INSERT_TAIL(&hio_recv_list[ncomp], hio,
-				    hio_next[ncomp]);
-				mtx_unlock(&hio_recv_list_lock[ncomp]);
-				continue;
-			default:
-				PJDLOG_ABORT("Invalid hio_countdown.");
+			} else {
+				PJDLOG_ASSERT(!memsyncack);
+				/* Remote final reply arrived. */
 			}
 		}
+		if (refcnt_release(&hio->hio_countdown) > 0)
+			continue;
 		if (ISSYNCREQ(hio)) {
 			mtx_lock(&sync_lock);
 			SYNCREQDONE(hio);
@@ -1917,8 +1904,9 @@
 			    ggio->gctl_offset, ggio->gctl_length)) {
 				res->hr_stat_activemap_update++;
 				(void)hast_activemap_flush(res);
+			} else {
+				mtx_unlock(&res->hr_amp_lock);
 			}
-			mtx_unlock(&res->hr_amp_lock);
 		}
 		if (ggio->gctl_cmd == BIO_WRITE) {
 			/*
@@ -2014,8 +2002,11 @@
 			 */
 			if (activemap_extent_complete(res->hr_amp, syncext))
 				(void)hast_activemap_flush(res);
+			else
+				mtx_unlock(&res->hr_amp_lock);
+		} else {
+			mtx_unlock(&res->hr_amp_lock);
 		}
-		mtx_unlock(&res->hr_amp_lock);
 		if (dorewind) {
 			dorewind = false;
 			if (offset == -1)
@@ -2139,7 +2130,7 @@
 			ncomp = 1;
 		}
 		mtx_unlock(&metadata_lock);
-		hio->hio_countdown = 1;
+		refcnt_init(&hio->hio_countdown, 1);
 		QUEUE_INSERT1(hio, send, ncomp);
 
 		/*
@@ -2189,7 +2180,7 @@
 
 		pjdlog_debug(2, "sync: (%p) Moving request to the send queue.",
 		    hio);
-		hio->hio_countdown = 1;
+		refcnt_init(&hio->hio_countdown, 1);
 		QUEUE_INSERT1(hio, send, ncomp);
 
 		/*

Modified: trunk/sbin/hastd/proto.c
===================================================================
--- trunk/sbin/hastd/proto.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/proto.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/proto.c 260006 2013-12-28 19:21:22Z trociny $");
 
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -298,8 +299,8 @@
 	protoname = mconn->pc_proto->prt_name;
 	PJDLOG_ASSERT(protoname != NULL);
 
-	ret = conn->pc_proto->prt_send(conn->pc_ctx, protoname,
-	    strlen(protoname) + 1, fd);
+	ret = conn->pc_proto->prt_send(conn->pc_ctx,
+	    (const unsigned char *)protoname, strlen(protoname) + 1, fd);
 	proto_close(mconn);
 	if (ret != 0) {
 		errno = ret;
@@ -325,7 +326,7 @@
 
 	bzero(protoname, sizeof(protoname));
 
-	ret = conn->pc_proto->prt_recv(conn->pc_ctx, protoname,
+	ret = conn->pc_proto->prt_recv(conn->pc_ctx, (unsigned char *)protoname,
 	    sizeof(protoname) - 1, &fd);
 	if (ret != 0) {
 		errno = ret;

Modified: trunk/sbin/hastd/proto.h
===================================================================
--- trunk/sbin/hastd/proto.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/proto.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/proto.h 219818 2011-03-21 08:54:59Z pjd $
  */
 
 #ifndef	_PROTO_H_

Modified: trunk/sbin/hastd/proto_common.c
===================================================================
--- trunk/sbin/hastd/proto_common.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/proto_common.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/proto_common.c 237931 2012-07-01 16:26:07Z pjd $");
 
 #include <sys/types.h>
 #include <sys/socket.h>

Modified: trunk/sbin/hastd/proto_impl.h
===================================================================
--- trunk/sbin/hastd/proto_impl.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/proto_impl.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/proto_impl.h 219873 2011-03-22 16:21:11Z pjd $
  */
 
 #ifndef	_PROTO_IMPL_H_

Modified: trunk/sbin/hastd/proto_socketpair.c
===================================================================
--- trunk/sbin/hastd/proto_socketpair.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/proto_socketpair.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/proto_socketpair.c 229945 2012-01-10 22:39:07Z pjd $");
 
 #include <sys/types.h>
 #include <sys/socket.h>

Modified: trunk/sbin/hastd/proto_tcp.c
===================================================================
--- trunk/sbin/hastd/proto_tcp.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/proto_tcp.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/proto_tcp.c 229945 2012-01-10 22:39:07Z pjd $");
 
 #include <sys/param.h>	/* MAXHOSTNAMELEN */
 #include <sys/socket.h>

Modified: trunk/sbin/hastd/proto_uds.c
===================================================================
--- trunk/sbin/hastd/proto_uds.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/proto_uds.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/proto_uds.c 229945 2012-01-10 22:39:07Z pjd $");
 
 /* UDS - UNIX Domain Socket */
 

Modified: trunk/sbin/hastd/rangelock.c
===================================================================
--- trunk/sbin/hastd/rangelock.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/rangelock.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/rangelock.c 231525 2012-02-11 16:41:52Z pjd $");
 
 #include <sys/queue.h>
 

Modified: trunk/sbin/hastd/rangelock.h
===================================================================
--- trunk/sbin/hastd/rangelock.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/rangelock.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/rangelock.h 204076 2010-02-18 23:16:19Z pjd $
  */
 
 #ifndef	_RANGELOCK_H_

Modified: trunk/sbin/hastd/refcnt.h
===================================================================
--- trunk/sbin/hastd/refcnt.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/refcnt.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2005 John Baldwin <jhb at FreeBSD.org>
  * All rights reserved.
@@ -10,9 +11,6 @@
  * 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.
- * 3. Neither the name of the author nor the names of any co-contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -26,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sbin/hastd/refcnt.h 262192 2014-02-18 20:27:17Z jhb $
  */
 
 #ifndef __REFCNT_H__
@@ -36,15 +34,24 @@
 
 #include "pjdlog.h"
 
+typedef unsigned int refcnt_t;
+
 static __inline void
-refcnt_acquire(volatile unsigned int *count)
+refcnt_init(refcnt_t *count, unsigned int v)
 {
 
+	*count = v;
+}
+
+static __inline void
+refcnt_acquire(refcnt_t *count)
+{
+
 	atomic_add_acq_int(count, 1);
 }
 
 static __inline unsigned int
-refcnt_release(volatile unsigned int *count)
+refcnt_release(refcnt_t *count)
 {
 	unsigned int old;
 

Modified: trunk/sbin/hastd/secondary.c
===================================================================
--- trunk/sbin/hastd/secondary.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/secondary.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * Copyright (c) 2010 Pawel Jakub Dawidek <pjd at FreeBSD.org>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/secondary.c 260006 2013-12-28 19:21:22Z trociny $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -82,19 +83,21 @@
  * until some in-progress requests are freed.
  */
 static TAILQ_HEAD(, hio) hio_free_list;
+static size_t hio_free_list_size;
 static pthread_mutex_t hio_free_list_lock;
 static pthread_cond_t hio_free_list_cond;
 /*
- * Disk thread (the one that do I/O requests) takes requests from this list.
+ * Disk thread (the one that does I/O requests) takes requests from this list.
  */
 static TAILQ_HEAD(, hio) hio_disk_list;
+static size_t hio_disk_list_size;
 static pthread_mutex_t hio_disk_list_lock;
 static pthread_cond_t hio_disk_list_cond;
 /*
- * There is one recv list for every component, although local components don't
- * use recv lists as local requests are done synchronously.
+ * Thread that sends requests back to primary takes requests from this list.
  */
 static TAILQ_HEAD(, hio) hio_send_list;
+static size_t hio_send_list_size;
 static pthread_mutex_t hio_send_list_lock;
 static pthread_cond_t hio_send_list_cond;
 
@@ -108,14 +111,12 @@
 static void *send_thread(void *arg);
 
 #define	QUEUE_INSERT(name, hio)	do {					\
-	bool _wakeup;							\
-									\
 	mtx_lock(&hio_##name##_list_lock);				\
-	_wakeup = TAILQ_EMPTY(&hio_##name##_list);			\
+	if (TAILQ_EMPTY(&hio_##name##_list))				\
+		cv_broadcast(&hio_##name##_list_cond);			\
 	TAILQ_INSERT_TAIL(&hio_##name##_list, (hio), hio_next);		\
+	hio_##name##_list_size++;					\
 	mtx_unlock(&hio_##name##_list_lock);				\
-	if (_wakeup)							\
-		cv_signal(&hio_##name##_list_cond);			\
 } while (0)
 #define	QUEUE_TAKE(name, hio)	do {					\
 	mtx_lock(&hio_##name##_list_lock);				\
@@ -123,11 +124,22 @@
 		cv_wait(&hio_##name##_list_cond,			\
 		    &hio_##name##_list_lock);				\
 	}								\
+	PJDLOG_ASSERT(hio_##name##_list_size != 0);			\
+	hio_##name##_list_size--;					\
 	TAILQ_REMOVE(&hio_##name##_list, (hio), hio_next);		\
 	mtx_unlock(&hio_##name##_list_lock);				\
 } while (0)
 
 static void
+output_status_aux(struct nv *nvout)
+{
+
+	nv_add_uint64(nvout, (uint64_t)hio_free_list_size, "idle_queue_size");
+	nv_add_uint64(nvout, (uint64_t)hio_disk_list_size, "local_queue_size");
+	nv_add_uint64(nvout, (uint64_t)hio_send_list_size, "send_queue_size");
+}
+
+static void
 hio_clear(struct hio *hio)
 {
 
@@ -191,6 +203,7 @@
 		}
 		hio_clear(hio);
 		TAILQ_INSERT_HEAD(&hio_free_list, hio, hio_next);
+		hio_free_list_size++;
 	}
 }
 
@@ -442,6 +455,7 @@
 	}
 
 	gres = res;
+	res->output_status_aux = output_status_aux;
 	mode = pjdlog_mode_get();
 	debuglevel = pjdlog_debug_get();
 
@@ -582,7 +596,7 @@
 			hio->hio_error = EINVAL;
 			goto end;
 		}
-		if (hio->hio_length > MAXPHYS) {
+		if (hio->hio_cmd != HIO_DELETE && hio->hio_length > MAXPHYS) {
 			pjdlog_error("Data length is too large (%ju > %ju).",
 			    (uintmax_t)hio->hio_length, (uintmax_t)MAXPHYS);
 			hio->hio_error = EINVAL;

Modified: trunk/sbin/hastd/subr.c
===================================================================
--- trunk/sbin/hastd/subr.c	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/subr.c	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -29,16 +30,17 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/hastd/subr.c 280250 2015-03-19 12:32:48Z rwatson $");
 
-#ifdef HAVE_CAPSICUM
-#include <sys/capability.h>
-#endif
 #include <sys/param.h>
 #include <sys/disk.h>
 #include <sys/ioctl.h>
 #include <sys/jail.h>
 #include <sys/stat.h>
+#ifdef HAVE_CAPSICUM
+#include <sys/capsicum.h>
+#include <geom/gate/g_gate.h>
+#endif
 
 #include <errno.h>
 #include <fcntl.h>
@@ -224,22 +226,56 @@
 		return (-1);
 	}
 
-	/*
-	 * Until capsicum doesn't allow ioctl(2) we cannot use it to sandbox
-	 * primary and secondary worker processes, as primary uses GGATE
-	 * ioctls and secondary uses ioctls to handle BIO_DELETE and BIO_FLUSH.
-	 * For now capsicum is only used to sandbox hastctl.
-	 */
 #ifdef HAVE_CAPSICUM
-	if (res == NULL) {
-		capsicum = (cap_enter() == 0);
-		if (!capsicum) {
-			pjdlog_common(LOG_DEBUG, 1, errno,
-			    "Unable to sandbox using capsicum");
+	capsicum = (cap_enter() == 0);
+	if (!capsicum) {
+		pjdlog_common(LOG_DEBUG, 1, errno,
+		    "Unable to sandbox using capsicum");
+	} else if (res != NULL) {
+		cap_rights_t rights;
+		static const unsigned long geomcmds[] = {
+		    DIOCGDELETE,
+		    DIOCGFLUSH
+		};
+
+		PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY ||
+		    res->hr_role == HAST_ROLE_SECONDARY);
+
+		cap_rights_init(&rights, CAP_FLOCK, CAP_IOCTL, CAP_PREAD,
+		    CAP_PWRITE);
+		if (cap_rights_limit(res->hr_localfd, &rights) == -1) {
+			pjdlog_errno(LOG_ERR,
+			    "Unable to limit capability rights on local descriptor");
 		}
-	} else
+		if (cap_ioctls_limit(res->hr_localfd, geomcmds,
+		    sizeof(geomcmds) / sizeof(geomcmds[0])) == -1) {
+			pjdlog_errno(LOG_ERR,
+			    "Unable to limit allowed GEOM ioctls");
+		}
+
+		if (res->hr_role == HAST_ROLE_PRIMARY) {
+			static const unsigned long ggatecmds[] = {
+			    G_GATE_CMD_MODIFY,
+			    G_GATE_CMD_START,
+			    G_GATE_CMD_DONE,
+			    G_GATE_CMD_DESTROY
+			};
+
+			cap_rights_init(&rights, CAP_IOCTL);
+			if (cap_rights_limit(res->hr_ggatefd, &rights) == -1) {
+				pjdlog_errno(LOG_ERR,
+				    "Unable to limit capability rights to CAP_IOCTL on ggate descriptor");
+			}
+			if (cap_ioctls_limit(res->hr_ggatefd, ggatecmds,
+			    sizeof(ggatecmds) / sizeof(ggatecmds[0])) == -1) {
+				pjdlog_errno(LOG_ERR,
+				    "Unable to limit allowed ggate ioctls");
+			}
+		}
+	}
+#else
+	capsicum = false;
 #endif
-		capsicum = false;
 
 	/*
 	 * Better be sure that everything succeeded.

Modified: trunk/sbin/hastd/subr.h
===================================================================
--- trunk/sbin/hastd/subr.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/subr.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 The FreeBSD Foundation
  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel at dawidek.net>
@@ -27,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/subr.h 229699 2012-01-06 12:27:17Z pjd $
  */
 
 #ifndef	_SUBR_H_

Modified: trunk/sbin/hastd/synch.h
===================================================================
--- trunk/sbin/hastd/synch.h	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/synch.h	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/synch.h 236919 2012-06-11 20:27:52Z hselasky $
  */
 
 #ifndef	_SYNCH_H_
@@ -168,7 +169,7 @@
 		return (false);
 	}
 
-        error = clock_gettime(CLOCK_MONOTONIC, &ts);
+	error = clock_gettime(CLOCK_MONOTONIC, &ts);
 	PJDLOG_ASSERT(error == 0);
 	ts.tv_sec += timeout;
 	error = pthread_cond_timedwait(cv, lock, &ts);

Modified: trunk/sbin/hastd/token.l
===================================================================
--- trunk/sbin/hastd/token.l	2018-07-01 20:46:16 UTC (rev 11210)
+++ trunk/sbin/hastd/token.l	2018-07-01 20:47:04 UTC (rev 11211)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 %{
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
@@ -28,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/hastd/token.l 250914 2013-05-22 17:47:45Z jkim $
  */
 
 #include <stdio.h>
@@ -42,6 +43,9 @@
 int lineno;
 
 #define	DP	do { } while (0)
+#define	YY_DECL	int yylex(void)
+
+extern int yylex(void);
 %}
 
 %option noinput


Property changes on: trunk/sbin/hastd/token.l
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list