Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jan 2012 17:22:11 +0000 (UTC)
From:      Mikolaj Golub <trociny@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r229509 - in stable/9/sbin: hastctl hastd
Message-ID:  <201201041722.q04HMBe2088691@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trociny
Date: Wed Jan  4 17:22:10 2012
New Revision: 229509
URL: http://svn.freebsd.org/changeset/base/229509

Log:
  MFC r225773, r225781, r225782, r225783, r225784, 225785, r225786, r225787,
    r225830, r225831, r225832, r225835, r226461, r226462, r226463, r226842,
    r226851, r226852, r226854, r226855, r226856, r226857, r226859, r226861,
    r228542, r228542, r228543, r228544, r228695, r228696:
  
  r225773 (pjd):
  
  Ensure that pjdlog functions don't modify errno.
  
  r225781 (pjd):
  
  No need to use KEEP_ERRNO() macro around pjdlog functions, as they don't
  modify errno.
  
  r225782 (pjd):
  
  Prefer PJDLOG_ASSERT() and PJDLOG_ABORT() over assert() and abort().
  pjdlog versions will log problem to syslog when application is running in
  background.
  
  r225783 (pjd):
  
  Correct two mistakes when converting asserts to PJDLOG_ASSERT()/PJDLOG_ABORT().
  
  r225784 (pjd):
  
  - Convert some impossible conditions into assertions.
  - Add missing 'if' in comment.
  
  r225785 (pjd):
  
  Prefer PJDLOG_ASSERT()/PJDLOG_ABORT() over assert().
  
  r225786 (pjd):
  
  No need to wrap pjdlog functions around with KEEP_ERRNO() macro.
  
  r225787 (pjd):
  
  Use PJDLOG_ASSERT() and PJDLOG_ABORT() everywhere instead of assert().
  
  r225830 (pjd):
  
  After every activemap change flush disk's write cache, so that write
  reordering won't make the actual write to be committed before marking
  the coresponding extent as dirty.
  
  It can be disabled in configuration file.
  
  If BIO_FLUSH is not supported by the underlying file system we log a warning
  and never send BIO_FLUSH again to that GEOM provider.
  
  r225831 (pjd):
  
  Break a bit earlier.
  
  r225832 (pjd):
  
  If the underlying provider doesn't support BIO_FLUSH, log it only once
  and don't bother trying in the future.
  
  r225835 (pjd):
  
  Correct typo.
  
  r226461 (pjd):
  
  When path to the configuration file is relative, obtain full path,
  so we can always find the file, even after daemonizing and changing
  working directory to /.
  
  r226462 (pjd):
  
  Remove redundant space.
  
  r226463 (pjd):
  
  Allow to specify pidfile in HAST configuration file.
  
  r226842 (pjd):
  
  Correct comments.
  
  r226851 (pjd):
  
  Delay resuid generation until first connection to secondary, not until first
  write. This way on first connection we will synchronize only the extents that
  were modified during the lifetime of primary node, not entire GEOM provider.
  
  r226852 (pjd):
  
  Minor cleanups.
  
  r226854 (pjd):
  
  - Eliminate the need for hio_nv.
  - Introduce hio_clear() function for clearing hio before returning it
    onto free queue.
  
  r226855 (pjd):
  
  Improve comment so it doesn't suggest race is possible, but that we handle
  the race.
  
  r226856 (pjd):
  
  Reduce indentation.
  
  r226857 (pjd):
  
  Minor cleanups.
  
  r226859 (pjd):
  
  Implement 'async' mode for HAST.
  
  r226861 (pjd):
  
  Remove redundant space.
  
  r228542 (pjd):
  
  Remove redundant setting of the error variable.
  
  Found by:       Clang Static Analyzer
  
  r228543 (pjd):
  
  Simplify code by changing functions types from int to avoid, as the functions
  always return 0.
  
  Found by:       Clang Static Analyzer
  
  r228544 (pjd):
  
  Remove redundant assignment.
  
  Found by:       Clang Static Analyzer
  
  r228695 (pjd):
  
  Don't use function name as format string.
  
  Detected by:    clang
  
  r228696 (pjd):
  
  Use lex's standard way of not generating unused function.
  
  Inspired by:    r228555

Modified:
  stable/9/sbin/hastctl/hastctl.c
  stable/9/sbin/hastd/Makefile
  stable/9/sbin/hastd/activemap.c
  stable/9/sbin/hastd/control.c
  stable/9/sbin/hastd/ebuf.c
  stable/9/sbin/hastd/event.c
  stable/9/sbin/hastd/hast.conf.5
  stable/9/sbin/hastd/hast.h
  stable/9/sbin/hastd/hast_checksum.c
  stable/9/sbin/hastd/hast_proto.c
  stable/9/sbin/hastd/hastd.c
  stable/9/sbin/hastd/hooks.c
  stable/9/sbin/hastd/metadata.c
  stable/9/sbin/hastd/nv.c
  stable/9/sbin/hastd/parse.y
  stable/9/sbin/hastd/pjdlog.c
  stable/9/sbin/hastd/pjdlog.h
  stable/9/sbin/hastd/primary.c
  stable/9/sbin/hastd/proto_tcp.c
  stable/9/sbin/hastd/rangelock.c
  stable/9/sbin/hastd/secondary.c
  stable/9/sbin/hastd/subr.c
  stable/9/sbin/hastd/synch.h
  stable/9/sbin/hastd/token.l
Directory Properties:
  stable/9/sbin/hastctl/   (props changed)
  stable/9/sbin/hastd/   (props changed)

Modified: stable/9/sbin/hastctl/hastctl.c
==============================================================================
--- stable/9/sbin/hastctl/hastctl.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastctl/hastctl.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -36,7 +36,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/stat.h>
 #include <sys/sysctl.h>
 
-#include <assert.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -433,19 +432,19 @@ main(int argc, char *argv[])
 	pjdlog_debug_set(debug);
 
 	cfg = yy_config_parse(cfgpath, true);
-	assert(cfg != NULL);
+	PJDLOG_ASSERT(cfg != NULL);
 
 	switch (cmd) {
 	case CMD_CREATE:
 		control_create(argc, argv, mediasize, extentsize, keepdirty);
 		/* NOTREACHED */
-		assert(!"What are we doing here?!");
+		PJDLOG_ABORT("What are we doing here?!");
 		break;
 	case CMD_DUMP:
 		/* Dump metadata from local component of the given resource. */
 		control_dump(argc, argv);
 		/* NOTREACHED */
-		assert(!"What are we doing here?!");
+		PJDLOG_ABORT("What are we doing here?!");
 		break;
 	case CMD_ROLE:
 		/* Change role for the given resources. */
@@ -476,7 +475,7 @@ main(int argc, char *argv[])
 		}
 		break;
 	default:
-		assert(!"Impossible command!");
+		PJDLOG_ABORT("Impossible command!");
 	}
 
 	/* Setup control connection... */
@@ -523,7 +522,7 @@ main(int argc, char *argv[])
 		error = control_status(nv);
 		break;
 	default:
-		assert(!"Impossible command!");
+		PJDLOG_ABORT("Impossible command!");
 	}
 
 	exit(error);

Modified: stable/9/sbin/hastd/Makefile
==============================================================================
--- stable/9/sbin/hastd/Makefile	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/Makefile	Wed Jan  4 17:22:10 2012	(r229509)
@@ -28,9 +28,6 @@ CFLAGS+=-DINET
 .if ${MK_INET6_SUPPORT} != "no"
 CFLAGS+=-DINET6
 .endif
-# This is needed to have WARNS > 1.
-CFLAGS+=-DYY_NO_UNPUT
-CFLAGS+=-DYY_NO_INPUT
 
 DPADD=	${LIBGEOM} ${LIBBSDXML} ${LIBSBUF} ${LIBL} ${LIBPTHREAD} ${LIBUTIL}
 LDADD=	-lgeom -lbsdxml -lsbuf -ll -lpthread -lutil

Modified: stable/9/sbin/hastd/activemap.c
==============================================================================
--- stable/9/sbin/hastd/activemap.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/activemap.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>	/* powerof2() */
 #include <sys/queue.h>
 
-#include <assert.h>
 #include <bitstring.h>
 #include <errno.h>
 #include <stdint.h>
@@ -41,7 +40,14 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include <string.h>
 
-#include <activemap.h>
+#include <pjdlog.h>
+
+#include "activemap.h"
+
+#ifndef	PJDLOG_ASSERT
+#include <assert.h>
+#define	PJDLOG_ASSERT(...)	assert(__VA_ARGS__)
+#endif
 
 #define	ACTIVEMAP_MAGIC	0xac71e4
 struct activemap {
@@ -93,9 +99,9 @@ off2ext(const struct activemap *amp, off
 {
 	int extent;
 
-	assert(offset >= 0 && offset < amp->am_mediasize);
+	PJDLOG_ASSERT(offset >= 0 && offset < amp->am_mediasize);
 	extent = (offset >> amp->am_extentshift);
-	assert(extent >= 0 && extent < amp->am_nextents);
+	PJDLOG_ASSERT(extent >= 0 && extent < amp->am_nextents);
 	return (extent);
 }
 
@@ -104,9 +110,9 @@ ext2off(const struct activemap *amp, int
 {
 	off_t offset;
 
-	assert(extent >= 0 && extent < amp->am_nextents);
+	PJDLOG_ASSERT(extent >= 0 && extent < amp->am_nextents);
 	offset = ((off_t)extent << amp->am_extentshift);
-	assert(offset >= 0 && offset < amp->am_mediasize);
+	PJDLOG_ASSERT(offset >= 0 && offset < amp->am_mediasize);
 	return (offset);
 }
 
@@ -122,7 +128,7 @@ ext2reqs(const struct activemap *amp, in
 	if (ext < amp->am_nextents - 1)
 		return (((amp->am_extentsize - 1) / MAXPHYS) + 1);
 
-	assert(ext == amp->am_nextents - 1);
+	PJDLOG_ASSERT(ext == amp->am_nextents - 1);
 	left = amp->am_mediasize % amp->am_extentsize;
 	if (left == 0)
 		left = amp->am_extentsize;
@@ -139,13 +145,13 @@ activemap_init(struct activemap **ampp, 
 {
 	struct activemap *amp;
 
-	assert(ampp != NULL);
-	assert(mediasize > 0);
-	assert(extentsize > 0);
-	assert(powerof2(extentsize));
-	assert(sectorsize > 0);
-	assert(powerof2(sectorsize));
-	assert(keepdirty > 0);
+	PJDLOG_ASSERT(ampp != NULL);
+	PJDLOG_ASSERT(mediasize > 0);
+	PJDLOG_ASSERT(extentsize > 0);
+	PJDLOG_ASSERT(powerof2(extentsize));
+	PJDLOG_ASSERT(sectorsize > 0);
+	PJDLOG_ASSERT(powerof2(sectorsize));
+	PJDLOG_ASSERT(keepdirty > 0);
 
 	amp = malloc(sizeof(*amp));
 	if (amp == NULL)
@@ -225,10 +231,10 @@ keepdirty_add(struct activemap *amp, int
 	 */
 	if (amp->am_nkeepdirty >= amp->am_nkeepdirty_limit) {
 		kd = TAILQ_LAST(&amp->am_keepdirty, skeepdirty);
-		assert(kd != NULL);
+		PJDLOG_ASSERT(kd != NULL);
 		TAILQ_REMOVE(&amp->am_keepdirty, kd, kd_next);
 		amp->am_nkeepdirty--;
-		assert(amp->am_nkeepdirty > 0);
+		PJDLOG_ASSERT(amp->am_nkeepdirty > 0);
 	}
 	if (kd == NULL)
 		kd = malloc(sizeof(*kd));
@@ -261,7 +267,7 @@ keepdirty_free(struct activemap *amp)
 		amp->am_nkeepdirty--;
 		free(kd);
 	}
-	assert(amp->am_nkeepdirty == 0);
+	PJDLOG_ASSERT(amp->am_nkeepdirty == 0);
 }
 
 /*
@@ -271,7 +277,7 @@ void
 activemap_free(struct activemap *amp)
 {
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	amp->am_magic = 0;
 
@@ -293,8 +299,8 @@ activemap_write_start(struct activemap *
 	off_t end;
 	int ext;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
-	assert(length > 0);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(length > 0);
 
 	modified = false;
 	end = offset + length - 1;
@@ -307,7 +313,7 @@ activemap_write_start(struct activemap *
 		 * was modified and has to be flushed to disk.
 		 */
 		if (amp->am_memtab[ext]++ == 0) {
-			assert(!bit_test(amp->am_memmap, ext));
+			PJDLOG_ASSERT(!bit_test(amp->am_memmap, ext));
 			bit_set(amp->am_memmap, ext);
 			amp->am_ndirty++;
 		}
@@ -329,8 +335,8 @@ activemap_write_complete(struct activema
 	off_t end;
 	int ext;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
-	assert(length > 0);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(length > 0);
 
 	modified = false;
 	end = offset + length - 1;
@@ -342,8 +348,8 @@ activemap_write_complete(struct activema
 		 * By returning true we inform the caller that on-disk bitmap
 		 * was modified and has to be flushed to disk.
 		 */
-		assert(amp->am_memtab[ext] > 0);
-		assert(bit_test(amp->am_memmap, ext));
+		PJDLOG_ASSERT(amp->am_memtab[ext] > 0);
+		PJDLOG_ASSERT(bit_test(amp->am_memmap, ext));
 		if (--amp->am_memtab[ext] == 0) {
 			bit_clear(amp->am_memmap, ext);
 			amp->am_ndirty--;
@@ -365,15 +371,15 @@ activemap_extent_complete(struct activem
 	bool modified;
 	int reqs;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
-	assert(extent >= 0 && extent < amp->am_nextents);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(extent >= 0 && extent < amp->am_nextents);
 
 	modified = false;
 
 	reqs = ext2reqs(amp, extent);
-	assert(amp->am_memtab[extent] >= reqs);
+	PJDLOG_ASSERT(amp->am_memtab[extent] >= reqs);
 	amp->am_memtab[extent] -= reqs;
-	assert(bit_test(amp->am_memmap, extent));
+	PJDLOG_ASSERT(bit_test(amp->am_memmap, extent));
 	if (amp->am_memtab[extent] == 0) {
 		bit_clear(amp->am_memmap, extent);
 		amp->am_ndirty--;
@@ -390,7 +396,7 @@ uint64_t
 activemap_ndirty(const struct activemap *amp)
 {
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	return (amp->am_ndirty);
 }
@@ -403,7 +409,7 @@ bool
 activemap_differ(const struct activemap *amp)
 {
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	return (memcmp(amp->am_diskmap, amp->am_memmap,
 	    amp->am_mapsize) != 0);
@@ -416,7 +422,7 @@ size_t
 activemap_size(const struct activemap *amp)
 {
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	return (amp->am_mapsize);
 }
@@ -429,7 +435,7 @@ size_t
 activemap_ondisk_size(const struct activemap *amp)
 {
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	return (amp->am_diskmapsize);
 }
@@ -442,8 +448,8 @@ activemap_copyin(struct activemap *amp, 
 {
 	int ext;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
-	assert(size >= amp->am_mapsize);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(size >= amp->am_mapsize);
 
 	memcpy(amp->am_diskmap, buf, amp->am_mapsize);
 	memcpy(amp->am_memmap, buf, amp->am_mapsize);
@@ -481,8 +487,8 @@ activemap_merge(struct activemap *amp, c
 	bitstr_t *remmap = __DECONST(bitstr_t *, buf);
 	int ext;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
-	assert(size >= amp->am_mapsize);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(size >= amp->am_mapsize);
 
 	bit_ffs(remmap, amp->am_nextents, &ext);
 	if (ext == -1) {
@@ -521,7 +527,7 @@ const unsigned char *
 activemap_bitmap(struct activemap *amp, size_t *sizep)
 {
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	if (sizep != NULL)
 		*sizep = amp->am_diskmapsize;
@@ -539,11 +545,11 @@ activemap_calc_ondisk_size(uint64_t medi
 {
 	uint64_t nextents, mapsize;
 
-	assert(mediasize > 0);
-	assert(extentsize > 0);
-	assert(powerof2(extentsize));
-	assert(sectorsize > 0);
-	assert(powerof2(sectorsize));
+	PJDLOG_ASSERT(mediasize > 0);
+	PJDLOG_ASSERT(extentsize > 0);
+	PJDLOG_ASSERT(powerof2(extentsize));
+	PJDLOG_ASSERT(sectorsize > 0);
+	PJDLOG_ASSERT(powerof2(sectorsize));
 
 	nextents = ((mediasize - 1) / extentsize) + 1;
 	mapsize = sizeof(bitstr_t) * bitstr_size(nextents);
@@ -558,7 +564,7 @@ activemap_sync_rewind(struct activemap *
 {
 	int ext;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	bit_ffs(amp->am_syncmap, amp->am_nextents, &ext);
 	if (ext == -1) {
@@ -581,9 +587,9 @@ activemap_sync_offset(struct activemap *
 	off_t syncoff, left;
 	int ext;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
-	assert(lengthp != NULL);
-	assert(syncextp != NULL);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(lengthp != NULL);
+	PJDLOG_ASSERT(syncextp != NULL);
 
 	*syncextp = -1;
 
@@ -632,9 +638,10 @@ activemap_sync_offset(struct activemap *
 	if (left > MAXPHYS)
 		left = MAXPHYS;
 
-	assert(left >= 0 && left <= MAXPHYS);
-	assert(syncoff >= 0 && syncoff < amp->am_mediasize);
-	assert(syncoff + left >= 0 && syncoff + left <= amp->am_mediasize);
+	PJDLOG_ASSERT(left >= 0 && left <= MAXPHYS);
+	PJDLOG_ASSERT(syncoff >= 0 && syncoff < amp->am_mediasize);
+	PJDLOG_ASSERT(syncoff + left >= 0 &&
+	    syncoff + left <= amp->am_mediasize);
 
 	*lengthp = left;
 	return (syncoff);
@@ -651,7 +658,7 @@ activemap_need_sync(struct activemap *am
 	off_t end;
 	int ext;
 
-	assert(amp->am_magic == ACTIVEMAP_MAGIC);
+	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
 
 	modified = false;
 	end = offset + length - 1;
@@ -659,7 +666,7 @@ activemap_need_sync(struct activemap *am
 	for (ext = off2ext(amp, offset); ext <= off2ext(amp, end); ext++) {
 		if (bit_test(amp->am_syncmap, ext)) {
 			/* Already marked for synchronization. */
-			assert(bit_test(amp->am_memmap, ext));
+			PJDLOG_ASSERT(bit_test(amp->am_memmap, ext));
 			continue;
 		}
 		bit_set(amp->am_syncmap, ext);

Modified: stable/9/sbin/hastd/control.c
==============================================================================
--- stable/9/sbin/hastd/control.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/control.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#include <assert.h>
 #include <errno.h>
 #include <pthread.h>
 #include <signal.h>
@@ -82,8 +81,8 @@ control_set_role_common(struct hastd_con
 		nv_add_string(nvout, name, "resource%u", no);
 
 	if (res == NULL) {
-		assert(cfg != NULL);
-		assert(name != NULL);
+		PJDLOG_ASSERT(cfg != NULL);
+		PJDLOG_ASSERT(name != NULL);
 
 		TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) {
 			if (strcmp(res->hr_name, name) == 0)
@@ -94,7 +93,7 @@ control_set_role_common(struct hastd_con
 			return;
 		}
 	}
-	assert(res != NULL);
+	PJDLOG_ASSERT(res != NULL);
 
 	/* Send previous role back. */
 	nv_add_string(nvout, role2str(res->hr_role), "role%u", no);
@@ -222,9 +221,9 @@ control_status(struct hastd_config *cfg,
     struct hast_resource *res, const char *name, unsigned int no)
 {
 
-	assert(cfg != NULL);
-	assert(nvout != NULL);
-	assert(name != NULL);
+	PJDLOG_ASSERT(cfg != NULL);
+	PJDLOG_ASSERT(nvout != NULL);
+	PJDLOG_ASSERT(name != NULL);
 
 	/* Name is always needed. */
 	nv_add_string(nvout, name, "resource%u", no);
@@ -239,7 +238,7 @@ control_status(struct hastd_config *cfg,
 			return;
 		}
 	}
-	assert(res != NULL);
+	PJDLOG_ASSERT(res != NULL);
 	nv_add_string(nvout, res->hr_provname, "provname%u", no);
 	nv_add_string(nvout, res->hr_localpath, "localpath%u", no);
 	nv_add_string(nvout, res->hr_remoteaddr, "remoteaddr%u", no);
@@ -267,7 +266,7 @@ control_status(struct hastd_config *cfg,
 
 	switch (res->hr_role) {
 	case HAST_ROLE_PRIMARY:
-		assert(res->hr_workerpid != 0);
+		PJDLOG_ASSERT(res->hr_workerpid != 0);
 		/* FALLTHROUGH */
 	case HAST_ROLE_SECONDARY:
 		if (res->hr_workerpid != 0)
@@ -313,7 +312,6 @@ control_handle(struct hastd_config *cfg)
 	cmd = nv_get_uint8(nvin, "cmd");
 	if (cmd == 0) {
 		pjdlog_error("Control header is missing 'cmd' field.");
-		error = EHAST_INVALID;
 		goto close;
 	}
 
@@ -321,7 +319,6 @@ control_handle(struct hastd_config *cfg)
 	nvout = nv_alloc();
 	if (nvout == NULL) {
 		pjdlog_error("Unable to allocate header for control response.");
-		error = EHAST_NOMEMORY;
 		goto close;
 	}
 
@@ -470,7 +467,7 @@ ctrl_thread(void *arg)
 			 * something related to us has changes, it sends reload
 			 * message to us.
 			 */
-			assert(res->hr_role == HAST_ROLE_PRIMARY);
+			PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY);
 			primary_config_reload(res, nvin);
 			nv_add_int16(nvout, 0, "error");
 			break;

Modified: stable/9/sbin/hastd/ebuf.c
==============================================================================
--- stable/9/sbin/hastd/ebuf.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/ebuf.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -32,15 +32,21 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 
-#include <assert.h>
 #include <errno.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <strings.h>
 #include <unistd.h>
 
+#include <pjdlog.h>
+
 #include "ebuf.h"
 
+#ifndef	PJDLOG_ASSERT
+#include <assert.h>
+#define	PJDLOG_ASSERT(...)	assert(__VA_ARGS__)
+#endif
+
 #define	EBUF_MAGIC	0xeb0f41c
 struct ebuf {
 	/* Magic to assert the caller uses valid structure. */
@@ -91,7 +97,7 @@ void
 ebuf_free(struct ebuf *eb)
 {
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
 
 	eb->eb_magic = 0;
 
@@ -103,7 +109,7 @@ int
 ebuf_add_head(struct ebuf *eb, const void *data, size_t size)
 {
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
 
 	if (size > (size_t)(eb->eb_used - eb->eb_start)) {
 		/*
@@ -113,7 +119,7 @@ ebuf_add_head(struct ebuf *eb, const voi
 		if (ebuf_head_extend(eb, size) < 0)
 			return (-1);
 	}
-	assert(size <= (size_t)(eb->eb_used - eb->eb_start));
+	PJDLOG_ASSERT(size <= (size_t)(eb->eb_used - eb->eb_start));
 
 	eb->eb_size += size;
 	eb->eb_used -= size;
@@ -130,7 +136,7 @@ int
 ebuf_add_tail(struct ebuf *eb, const void *data, size_t size)
 {
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
 
 	if (size > (size_t)(eb->eb_end - (eb->eb_used + eb->eb_size))) {
 		/*
@@ -140,7 +146,8 @@ ebuf_add_tail(struct ebuf *eb, const voi
 		if (ebuf_tail_extend(eb, size) < 0)
 			return (-1);
 	}
-	assert(size <= (size_t)(eb->eb_end - (eb->eb_used + eb->eb_size)));
+	PJDLOG_ASSERT(size <=
+	    (size_t)(eb->eb_end - (eb->eb_used + eb->eb_size)));
 
 	/*
 	 * If data is NULL the caller just wants to reserve space.
@@ -156,8 +163,8 @@ void
 ebuf_del_head(struct ebuf *eb, size_t size)
 {
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
-	assert(size <= eb->eb_size);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(size <= eb->eb_size);
 
 	eb->eb_used += size;
 	eb->eb_size -= size;
@@ -167,8 +174,8 @@ void
 ebuf_del_tail(struct ebuf *eb, size_t size)
 {
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
-	assert(size <= eb->eb_size);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(size <= eb->eb_size);
 
 	eb->eb_size -= size;
 }
@@ -180,7 +187,7 @@ void *
 ebuf_data(struct ebuf *eb, size_t *sizep)
 {
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
 
 	if (sizep != NULL)
 		*sizep = eb->eb_size;
@@ -194,7 +201,7 @@ size_t
 ebuf_size(struct ebuf *eb)
 {
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
 
 	return (eb->eb_size);
 }
@@ -208,7 +215,7 @@ ebuf_head_extend(struct ebuf *eb, size_t
 	unsigned char *newstart, *newused;
 	size_t newsize;
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
 
 	newsize = eb->eb_end - eb->eb_start + (PAGE_SIZE / 4) + size;
 
@@ -236,7 +243,7 @@ ebuf_tail_extend(struct ebuf *eb, size_t
 	unsigned char *newstart;
 	size_t newsize;
 
-	assert(eb != NULL && eb->eb_magic == EBUF_MAGIC);
+	PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC);
 
 	newsize = eb->eb_end - eb->eb_start + size + ((3 * PAGE_SIZE) / 4);
 

Modified: stable/9/sbin/hastd/event.c
==============================================================================
--- stable/9/sbin/hastd/event.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/event.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -27,7 +27,6 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include <assert.h>
 #include <errno.h>
 
 #include "hast.h"
@@ -46,8 +45,8 @@ event_send(const struct hast_resource *r
 	struct nv *nvin, *nvout;
 	int error;
 
-	assert(res != NULL);
-	assert(event >= EVENT_MIN && event <= EVENT_MAX);
+	PJDLOG_ASSERT(res != NULL);
+	PJDLOG_ASSERT(event >= EVENT_MIN && event <= EVENT_MAX);
 
 	nvin = nvout = NULL;
 
@@ -89,7 +88,7 @@ event_recv(const struct hast_resource *r
 	uint8_t event;
 	int error;
 
-	assert(res != NULL);
+	PJDLOG_ASSERT(res != NULL);
 
 	nvin = nvout = NULL;
 

Modified: stable/9/sbin/hastd/hast.conf.5
==============================================================================
--- stable/9/sbin/hastd/hast.conf.5	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/hast.conf.5	Wed Jan  4 17:22:10 2012	(r229509)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 20, 2011
+.Dd October 27, 2011
 .Dt HAST.CONF 5
 .Os
 .Sh NAME
@@ -63,17 +63,21 @@ checksum <algorithm>
 compression <algorithm>
 timeout <seconds>
 exec <path>
+metaflush "on" | "off"
+pidfile <path>
 
 on <node> {
 	# Node section
         control <addr>
         listen <addr>
+        pidfile <path>
 }
 
 on <node> {
 	# Node section
         control <addr>
         listen <addr>
+        pidfile <path>
 }
 
 resource <name> {
@@ -85,12 +89,14 @@ resource <name> {
 	local <path>
 	timeout <seconds>
 	exec <path>
+	metaflush "on" | "off"
 
 	on <node> {
 		# Resource-node section
 		name <name>
 		# Required
 		local <path>
+		metaflush "on" | "off"
 		# Required
 		remote <addr>
 		source <addr>
@@ -100,6 +106,7 @@ resource <name> {
 		name <name>
 		# Required
 		local <path>
+		metaflush "on" | "off"
 		# Required
 		remote <addr>
 		source <addr>
@@ -142,6 +149,14 @@ unix:///var/run/hastctl
 .Pp
 The default value is
 .Pa uds:///var/run/hastctl .
+.It Ic pidfile Aq path
+.Pp
+File in which to store the process ID of the main
+.Xr hastd 8
+process.
+.Pp
+The default value is
+.Pa /var/run/hastd.pid .
 .It Ic listen Aq addr
 .Pp
 Address to listen on in form of:
@@ -209,9 +224,6 @@ completes.
 This is the fastest and the most dangerous replication mode.
 This mode should be used when replicating to a distant node where
 latency is too high for other modes.
-The
-.Ic async
-replication mode is currently not implemented.
 .El
 .It Ic checksum Aq algorithm
 .Pp
@@ -318,6 +330,25 @@ It can be one of:
 .Ar secondary ,
 .Ar primary .
 .Pp
+.It Ic metaflush on | off
+.Pp
+When set to
+.Va on ,
+flush write cache of the local provider after every metadata (activemap) update.
+Flushing write cache ensures that provider will not reorder writes and that
+metadata will be properly updated before real data is stored.
+If the local provider does not support flushing write cache (it returns
+.Er EOPNOTSUPP
+on the
+.Cm BIO_FLUSH
+request),
+.Nm hastd
+will disable
+.Ic metaflush
+automatically.
+The default value is
+.Va on .
+.Pp
 .It Ic name Aq name
 .Pp
 GEOM provider name that will appear as

Modified: stable/9/sbin/hastd/hast.h
==============================================================================
--- stable/9/sbin/hastd/hast.h	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/hast.h	Wed Jan  4 17:22:10 2012	(r229509)
@@ -111,11 +111,13 @@ struct hastd_listen {
 
 struct hastd_config {
 	/* Address to communicate with hastctl(8). */
-	char	 hc_controladdr[HAST_ADDRSIZE];
+	char	hc_controladdr[HAST_ADDRSIZE];
 	/* Protocol-specific data. */
 	struct proto_conn *hc_controlconn;
 	/* Incoming control connection. */
 	struct proto_conn *hc_controlin;
+	/* PID file path. */
+	char	hc_pidfile[PATH_MAX];
 	/* List of addresses to listen on. */
 	TAILQ_HEAD(, hastd_listen) hc_listen;
 	/* List of resources. */
@@ -167,6 +169,10 @@ struct hast_resource {
 	off_t	hr_local_mediasize;
 	/* Sector size of local provider. */
 	unsigned int hr_local_sectorsize;
+	/* Is flushing write cache supported by the local provider? */
+	bool	hr_localflush;
+	/* Flush write cache on metadata updates? */
+	int	hr_metaflush;
 
 	/* Descriptor for /dev/ggctl communication. */
 	int	hr_ggatefd;

Modified: stable/9/sbin/hastd/hast_checksum.c
==============================================================================
--- stable/9/sbin/hastd/hast_checksum.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/hast_checksum.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$");
 #define	MAX_HASH_SIZE	4
 #endif
 
-static int
+static void
 hast_crc32_checksum(const unsigned char *data, size_t size,
     unsigned char *hash, size_t *hsizep)
 {
@@ -58,12 +58,10 @@ hast_crc32_checksum(const unsigned char 
 	/* XXXPJD: Do we have to use htole32() on crc first? */
 	bcopy(&crc, hash, sizeof(crc));
 	*hsizep = sizeof(crc);
-
-	return (0);
 }
 
 #ifdef HAVE_CRYPTO
-static int
+static void
 hast_sha256_checksum(const unsigned char *data, size_t size,
     unsigned char *hash, size_t *hsizep)
 {
@@ -73,8 +71,6 @@ hast_sha256_checksum(const unsigned char
 	SHA256_Update(&ctx, data, size);
 	SHA256_Final(hash, &ctx);
 	*hsizep = SHA256_DIGEST_LENGTH;
-
-	return (0);
 }
 #endif	/* HAVE_CRYPTO */
 
@@ -99,25 +95,21 @@ checksum_send(const struct hast_resource
 {
 	unsigned char hash[MAX_HASH_SIZE];
 	size_t hsize;
-	int ret;
 
 	switch (res->hr_checksum) {
 	case HAST_CHECKSUM_NONE:
 		return (0);
 	case HAST_CHECKSUM_CRC32:
-		ret = hast_crc32_checksum(*datap, *sizep, hash, &hsize);
+		hast_crc32_checksum(*datap, *sizep, hash, &hsize);
 		break;
 #ifdef HAVE_CRYPTO
 	case HAST_CHECKSUM_SHA256:
-		ret = hast_sha256_checksum(*datap, *sizep, hash, &hsize);
+		hast_sha256_checksum(*datap, *sizep, hash, &hsize);
 		break;
 #endif
 	default:
 		PJDLOG_ABORT("Invalid checksum: %d.", res->hr_checksum);
 	}
-
-	if (ret != 0)
-		return (ret);
 	nv_add_string(nv, checksum_name(res->hr_checksum), "checksum");
 	nv_add_uint8_array(nv, hash, hsize, "hash");
 	if (nv_error(nv) != 0) {
@@ -135,7 +127,6 @@ checksum_recv(const struct hast_resource
 	const unsigned char *rhash;
 	size_t chsize, rhsize;
 	const char *algo;
-	int ret;
 
 	algo = nv_get_string(nv, "checksum");
 	if (algo == NULL)
@@ -146,10 +137,10 @@ checksum_recv(const struct hast_resource
 		return (-1);	/* Hash not found. */
 	}
 	if (strcmp(algo, "crc32") == 0)
-		ret = hast_crc32_checksum(*datap, *sizep, chash, &chsize);
+		hast_crc32_checksum(*datap, *sizep, chash, &chsize);
 #ifdef HAVE_CRYPTO
 	else if (strcmp(algo, "sha256") == 0)
-		ret = hast_sha256_checksum(*datap, *sizep, chash, &chsize);
+		hast_sha256_checksum(*datap, *sizep, chash, &chsize);
 #endif
 	else {
 		pjdlog_error("Unknown checksum algorithm '%s'.", algo);

Modified: stable/9/sbin/hastd/hast_proto.c
==============================================================================
--- stable/9/sbin/hastd/hast_proto.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/hast_proto.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/endian.h>
 
-#include <assert.h>
 #include <errno.h>
 #include <strings.h>
 
@@ -158,7 +157,7 @@ hast_proto_recv_hdr(const struct proto_c
 	if (ebuf_add_tail(eb, NULL, hdr.size) < 0)
 		goto fail;
 	hptr = ebuf_data(eb, NULL);
-	assert(hptr != NULL);
+	PJDLOG_ASSERT(hptr != NULL);
 	if (proto_recv(conn, hptr, hdr.size) < 0)
 		goto fail;
 	nv = nv_ntoh(eb);
@@ -183,8 +182,8 @@ hast_proto_recv_data(const struct hast_r
 	void *dptr;
 	int ret;
 
-	assert(data != NULL);
-	assert(size > 0);
+	PJDLOG_ASSERT(data != NULL);
+	PJDLOG_ASSERT(size > 0);
 
 	ret = -1;
 	freedata = false;

Modified: stable/9/sbin/hastd/hastd.c
==============================================================================
--- stable/9/sbin/hastd/hastd.c	Wed Jan  4 17:17:11 2012	(r229508)
+++ stable/9/sbin/hastd/hastd.c	Wed Jan  4 17:22:10 2012	(r229509)
@@ -386,6 +386,12 @@ resource_needs_restart(const struct hast
 			return (true);
 		if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
 			return (true);
+		/*
+		 * When metaflush has changed we don't really need restart,
+		 * but it is just easier this way.
+		 */
+		if (res0->hr_metaflush != res1->hr_metaflush)
+			return (true);
 	}
 	return (false);
 }
@@ -416,6 +422,8 @@ resource_needs_reload(const struct hast_
 		return (true);
 	if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
 		return (true);
+	if (res0->hr_metaflush != res1->hr_metaflush)
+		return (true);
 	return (false);
 }
 
@@ -436,6 +444,7 @@ resource_reload(const struct hast_resour
 	nv_add_int32(nvout, (int32_t)res->hr_compression, "compression");
 	nv_add_int32(nvout, (int32_t)res->hr_timeout, "timeout");
 	nv_add_string(nvout, res->hr_exec, "exec");
+	nv_add_int32(nvout, (int32_t)res->hr_metaflush, "metaflush");
 	if (nv_error(nvout) != 0) {
 		nv_free(nvout);
 		pjdlog_error("Unable to allocate header for reload message.");
@@ -467,11 +476,15 @@ hastd_reload(void)
 	struct hastd_config *newcfg;
 	struct hast_resource *nres, *cres, *tres;
 	struct hastd_listen *nlst, *clst;
+	struct pidfh *newpfh;
 	unsigned int nlisten;
 	uint8_t role;
+	pid_t otherpid;
 
 	pjdlog_info("Reloading configuration...");
 
+	newpfh = NULL;
+
 	newcfg = yy_config_parse(cfgpath, false);
 	if (newcfg == NULL)
 		goto failed;
@@ -515,6 +528,31 @@ hastd_reload(void)
 		pjdlog_error("No addresses to listen on.");
 		goto failed;
 	}
+	/*
+	 * Check if pidfile's path has changed.
+	 */
+	if (strcmp(cfg->hc_pidfile, newcfg->hc_pidfile) != 0) {
+		newpfh = pidfile_open(newcfg->hc_pidfile, 0600, &otherpid);
+		if (newpfh == NULL) {
+			if (errno == EEXIST) {
+				pjdlog_errno(LOG_WARNING,
+				    "Another hastd is already running, pidfile: %s, pid: %jd.",
+				    newcfg->hc_pidfile, (intmax_t)otherpid);
+			} else {
+				pjdlog_errno(LOG_WARNING,
+				    "Unable to open or create pidfile %s",
+				    newcfg->hc_pidfile);
+			}
+		} else if (pidfile_write(newpfh) < 0) {
+			/* Write PID to a file. */
+			pjdlog_errno(LOG_WARNING,
+			    "Unable to write PID to file %s",
+			    newcfg->hc_pidfile);
+		} else {
+			pjdlog_debug(1, "PID stored in %s.",
+			    newcfg->hc_pidfile);
+		}
+	}
 
 	/* No failures from now on. */
 
@@ -531,6 +569,13 @@ hastd_reload(void)
 		    sizeof(cfg->hc_controladdr));
 	}
 	/*
+	 * Switch to new pidfile.
+	 */
+	(void)pidfile_remove(pfh);
+	pfh = newpfh;
+	(void)strlcpy(cfg->hc_pidfile, newcfg->hc_pidfile,
+	    sizeof(cfg->hc_pidfile));
+	/*
 	 * Switch to new listen addresses. Close all that were removed.
 	 */
 	while ((clst = TAILQ_FIRST(&cfg->hc_listen)) != NULL) {
@@ -591,12 +636,13 @@ hastd_reload(void)
 	 * recreating it.
 	 *
 	 * We do just reload (send SIGHUP to worker process) if we act as
-	 * PRIMARY, but only if remote address, replication mode, timeout or
-	 * execution path has changed. For those, there is no need to restart
-	 * worker process.
+	 * PRIMARY, but only if remote address, source address, replication
+	 * mode, timeout, execution path or metaflush has changed.
+	 * For those, there is no need to restart worker process.
 	 * If PRIMARY receives SIGHUP, it will reconnect if remote address or
-	 * replication mode has changed or simply set new timeout if only
-	 * timeout has changed.
+	 * source address has changed or it will set new timeout if only timeout
+	 * has changed or it will update metaflush if only metaflush has
+	 * changed.
 	 */
 	TAILQ_FOREACH_SAFE(nres, &newcfg->hc_resources, hr_next, tres) {
 		TAILQ_FOREACH(cres, &cfg->hc_resources, hr_next) {
@@ -627,6 +673,7 @@ hastd_reload(void)
 			cres->hr_timeout = nres->hr_timeout;
 			strlcpy(cres->hr_exec, nres->hr_exec,
 			    sizeof(cres->hr_exec));
+			cres->hr_metaflush = nres->hr_metaflush;
 			if (cres->hr_workerpid != 0)
 				resource_reload(cres);
 		}
@@ -655,6 +702,8 @@ failed:
 		}
 		yy_config_free(newcfg);
 	}
+	if (newpfh != NULL)
+		(void)pidfile_remove(newpfh);
 	pjdlog_warning("Configuration not reloaded.");
 }
 
@@ -1112,7 +1161,7 @@ main(int argc, char *argv[])
 
 	foreground = false;

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201041722.q04HMBe2088691>