head	1.6;
access;
symbols
	RELENG_8_4:1.6.0.2
	RELENG_9_1_0_RELEASE:1.4.2.2.2.2
	RELENG_9_1:1.4.2.2.0.2
	RELENG_9_1_BP:1.4.2.2
	RELENG_8_3_0_RELEASE:1.3.2.4.2.1
	RELENG_8_3:1.3.2.4.0.2
	RELENG_8_3_BP:1.3.2.4
	RELENG_9_0_0_RELEASE:1.4.2.1.2.1
	RELENG_9_0:1.4.2.1.0.2
	RELENG_9_0_BP:1.4.2.1
	RELENG_9:1.4.0.2
	RELENG_9_BP:1.4
	RELENG_8_2_0_RELEASE:1.3.2.2.4.1
	RELENG_8_2:1.3.2.2.0.4
	RELENG_8_2_BP:1.3.2.2
	RELENG_8_1_0_RELEASE:1.3.2.2.2.1
	RELENG_8_1:1.3.2.2.0.2
	RELENG_8_1_BP:1.3.2.2
	RELENG_8:1.3.0.2;
locks; strict;
comment	@# @;


1.6
date	2012.11.17.01.49.04;	author svnexp;	state Exp;
branches
	1.6.2.1;
next	1.5;

1.5
date	2012.01.14.02.18.41;	author dougb;	state Exp;
branches;
next	1.4;

1.4
date	2011.02.27.11.40.20;	author pjd;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2010.02.19.09.18.26;	author pjd;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2010.02.18.23.20.15;	author pjd;	state Exp;
branches;
next	1.1;

1.1
date	2010.02.18.23.16.19;	author pjd;	state Exp;
branches;
next	;

1.6.2.1
date	2012.11.17.01.49.04;	author svnexp;	state dead;
branches;
next	1.6.2.2;

1.6.2.2
date	2013.03.28.13.02.43;	author svnexp;	state Exp;
branches;
next	;

1.4.2.1
date	2011.09.23.00.51.37;	author kensmith;	state Exp;
branches
	1.4.2.1.2.1;
next	1.4.2.2;

1.4.2.2
date	2012.02.14.10.16.56;	author dougb;	state Exp;
branches
	1.4.2.2.2.1;
next	1.4.2.3;

1.4.2.3
date	2012.11.17.11.36.11;	author svnexp;	state Exp;
branches;
next	;

1.4.2.1.2.1
date	2011.11.11.04.20.22;	author kensmith;	state Exp;
branches;
next	1.4.2.1.2.2;

1.4.2.1.2.2
date	2012.11.17.08.36.11;	author svnexp;	state Exp;
branches;
next	;

1.4.2.2.2.1
date	2012.08.05.23.54.33;	author kensmith;	state Exp;
branches;
next	1.4.2.2.2.2;

1.4.2.2.2.2
date	2012.11.17.08.47.01;	author svnexp;	state Exp;
branches;
next	;

1.3.2.1
date	2010.04.18.21.14.49;	author pjd;	state dead;
branches;
next	1.3.2.2;

1.3.2.2
date	2010.04.18.21.14.49;	author pjd;	state Exp;
branches
	1.3.2.2.2.1
	1.3.2.2.4.1;
next	1.3.2.3;

1.3.2.3
date	2011.03.28.17.41.10;	author trociny;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	2012.02.14.10.17.14;	author dougb;	state Exp;
branches
	1.3.2.4.2.1;
next	1.3.2.5;

1.3.2.5
date	2012.11.17.10.35.56;	author svnexp;	state Exp;
branches;
next	;

1.3.2.2.2.1
date	2010.06.14.02.09.06;	author kensmith;	state Exp;
branches;
next	;

1.3.2.2.4.1
date	2010.12.21.17.09.25;	author kensmith;	state Exp;
branches;
next	;

1.3.2.4.2.1
date	2012.03.03.06.15.13;	author kensmith;	state Exp;
branches;
next	1.3.2.4.2.2;

1.3.2.4.2.2
date	2012.11.17.08.24.38;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Switching exporter and resync
@
text
@#!/bin/sh
#
# $FreeBSD: head/etc/rc.d/hastd 230099 2012-01-14 02:18:41Z dougb $
#

# PROVIDE: hastd
# REQUIRE: NETWORKING syslogd
# BEFORE:  DAEMON
# KEYWORD: nojail shutdown

. /etc/rc.subr

name="hastd"
rcvar="hastd_enable"
pidfile="/var/run/${name}.pid"
command="/sbin/${name}"
hastctl="/sbin/hastctl"
required_files="/etc/hast.conf"
stop_precmd="hastd_stop_precmd"
required_modules="geom_gate:g_gate"
extra_commands="reload"

hastd_stop_precmd()
{
	${hastctl} role init all
}

load_rc_config $name
run_rc_command "$1"
@


1.6.2.1
log
@file hastd was added on branch RELENG_8_4 on 2013-03-28 13:02:43 +0000
@
text
@d1 29
@


1.6.2.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/248810
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 29
#!/bin/sh
#
# $FreeBSD: releng/8.4/etc/rc.d/hastd 231655 2012-02-14 10:17:14Z dougb $
#

# PROVIDE: hastd
# REQUIRE: NETWORKING syslogd
# BEFORE:  DAEMON
# KEYWORD: nojail shutdown

. /etc/rc.subr

name="hastd"
rcvar="hastd_enable"
pidfile="/var/run/${name}.pid"
command="/sbin/${name}"
hastctl="/sbin/hastctl"
required_files="/etc/hast.conf"
stop_precmd="hastd_stop_precmd"
required_modules="geom_gate:g_gate"
extra_commands="reload"

hastd_stop_precmd()
{
	${hastctl} role init all
}

load_rc_config $name
run_rc_command "$1"
@


1.5
log
@SVN rev 230099 on 2012-01-14 02:18:41Z by dougb

Prepare for the removal of set_rcvar() by changing the rcvar=
assignments to the literal values it would have returned.

The concept of set_rcvar() was nice in theory, but the forks
it creates are a drag on the startup process, which is especially
noticeable on slower systems, such as embedded ones.

During the discussion on freebsd-rc@@ a preference was expressed for
using ${name}_enable instead of the literal values. However the
code portability concept doesn't really apply since there are so
many other places where the literal name has to be searched for
and replaced. Also, using the literal value is also a tiny bit
faster than dereferencing the variables, and every little bit helps.
@
text
@d3 1
a3 1
# $FreeBSD$
@


1.4
log
@SVN rev 219082 on 2011-02-27 11:40:20Z by pjd

Recognize 'reload' command, as hastd can be reloaded with the SIGHUP signal.

MFC after:	1 week
@
text
@d14 1
a14 1
rcvar=`set_rcvar`
@


1.4.2.1
log
@SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.4.2.2
log
@SVN rev 231653 on 2012-02-14 10:16:56Z by dougb

MFC r230099:

Change rcvar= assignments to the literal values set_rcvar
would have returned. This will slightly reduce boot time,
and help in diff reduction to HEAD.
@
text
@d14 1
a14 1
rcvar="hastd_enable"
@


1.4.2.3
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242902
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242902 | dteske | 2012-11-11 23:29:45 +0000 (Sun, 11 Nov 2012) | 10 lines
## SVN ##
## SVN ## Fix a regression introduced by SVN r211417 that saw the breakage of a feature
## SVN ## documented in usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## Reviewed by:	adrian (co-mentor)
## SVN ## Approved by:	adrian (co-mentor)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d3 1
a3 1
# $FreeBSD: stable/9/etc/rc.d/hastd 231653 2012-02-14 10:16:56Z dougb $
@


1.4.2.2.2.1
log
@SVN rev 239080 on 2012-08-05 23:54:33Z by kensmith

Copy stable/9 to releng/9.1 as part of the 9.1-RELEASE release process.

Approved by:	re (implicit)
@
text
@@


1.4.2.2.2.2
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: releng/9.1/etc/rc.d/hastd 231653 2012-02-14 10:16:56Z dougb $
@


1.4.2.1.2.1
log
@SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)
@
text
@@


1.4.2.1.2.2
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: releng/9.0/etc/rc.d/hastd 219587 2011-03-13 08:22:46Z dougb $
@


1.3
log
@SVN rev 204083 on 2010-02-19 09:18:26Z by pjd

Add missing KEYWORD line.

Pointed out by:	dougb
@
text
@d21 1
@


1.3.2.1
log
@file hastd was added on branch RELENG_8 on 2010-04-18 21:19:33 +0000
@
text
@d1 28
@


1.3.2.2
log
@SVN rev 206810 on 2010-04-18 21:14:49Z by pjd

MFC r204076,r204077,r204083,r205279:

r204076:

Please welcome HAST - Highly Avalable Storage.

HAST allows to transparently store data on two physically separated machines
connected over the TCP/IP network. HAST works in Primary-Secondary
(Master-Backup, Master-Slave) configuration, which means that only one of the
cluster nodes can be active at any given time. Only Primary node is able to
handle I/O requests to HAST-managed devices. Currently HAST is limited to two
cluster nodes in total.

HAST operates on block level - it provides disk-like devices in /dev/hast/
directory for use by file systems and/or applications. Working on block level
makes it transparent for file systems and applications. There in no difference
between using HAST-provided device and raw disk, partition, etc. All of them
are just regular GEOM providers in FreeBSD.

For more information please consult hastd(8), hastctl(8) and hast.conf(5)
manual pages, as well as http://wiki.FreeBSD.org/HAST.

Sponsored by:	FreeBSD Foundation
Sponsored by:	OMCnet Internet Service GmbH
Sponsored by:	TransIP BV

r204077:

Remove some lines left over by accident.

r204083:

Add missing KEYWORD line.

Pointed out by:	dougb

r205279 sys:

Simplify loops.
@
text
@a0 28
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: hastd
# REQUIRE: NETWORKING syslogd
# BEFORE:  DAEMON
# KEYWORD: nojail shutdown

. /etc/rc.subr

name="hastd"
rcvar=`set_rcvar`
pidfile="/var/run/${name}.pid"
command="/sbin/${name}"
hastctl="/sbin/hastctl"
required_files="/etc/hast.conf"
stop_precmd="hastd_stop_precmd"
required_modules="geom_gate:g_gate"

hastd_stop_precmd()
{
	${hastctl} role init all
}

load_rc_config $name
run_rc_command "$1"
@


1.3.2.3
log
@SVN rev 220104 on 2011-03-28 17:41:10Z by trociny

MFC r217729, r217730, r217731, r217732, r217737, r217784, r217958,
  r217961, r217962, r217964, r217965, r217966, r217967, r217969,
  r218040, r218041, r218042, r218043, r218044, r218045, r218048,
  r218049, r218119, r218132, r218138, r218139, r218147, r218148,
  r218158, r218185, r218191, r218192, r218193, r218194, r218201,
  r218214, r218215, r218217, r218218, r218370, r218373, r218374,
  r218375, r218376, r218464, r218465, r218474, r219082:

r217729 (pjd):

- On primary worker reload, update hr_exec field.
- Update comment.

r217730 (pjd):

Use int16 for error.

r217731 (pjd):

Use more consistent function name with the others (pjdlogv_prefix_set()
instead of pjdlog_prefix_setv()).

r217732 (pjd):

Add nv_assert() which allows to assert that the given name exists.

r217737 (pjd):

Add missing logs.

r217784 (pjd):

Don't open configuration file from worker process. Handle SIGHUP in the
master process only and pass changes to the worker processes over control
socket. This removes access to global namespace in preparation for capsicum
sandboxing.

r217958 (pjd):

Remove __dead2 from pjdlog_verify() prototype, it does return sometimes.

r217961 (pjd):

- Remove obvious NOTREACHED comment after abort() call.
- Remove redundant newline at the end of the file.

r217962 (pjd):

Add LOG_NDELAY flag to openlog(3) - we want descriptor to be immediately open
so there are no surprises once we start chrooting or using capsicum.

r217964 (pjd):

Use pjd copyright for 2011 work.

r217965 (pjd):

Add functions to initialize/finalize pjdlog. This allows to open/close log
file at will.

r217966 (pjd):

Extend pjdlog_verify() to support the following additional macros:
PJDLOG_RVERIFY() - always check expression and on false log the given message
        and exit.
PJDLOG_RASSERT() - check expression when NDEBUG is not defined and on false log
        given message and exit.
PJDLOG_ABORT() - log the given message and exit.

r217967 (pjd):

Close the control socket before exiting, so it will be unlinked.

r217969 (pjd):

Remember created control connection so on fork(2) we can close it in child.

r218040 (pjd):

Initialize all global variables on pjdlog_init().

r218041 (pjd):

Add function to close all unneeded descriptors after fork(2).

r218042 (pjd):

Add comments to places where we treat errors as ciritical, but it is possible
to handle them more gracefully.

r218043 (pjd):

Close all unneeded descriptors after fork(2).

r218044 (pjd):

Add function to assert that the only descriptors we have open are the ones
we expect to be open. Also assert that they point at expected type.

Because openlog(3) API is unable to tell us descriptor number it is using, we
have to close syslog socket, remember assert message in local buffer and if we
fail on assertion, reopen syslog socket and log the message.

r218045 (pjd):

Use newly added descriptors_assert() function to ensure only expected
descriptors are open.

r218046 (pjd), r218047 (pjd), r218119 (maxim):

Add 'hast' user and 'hast' group that will be used by hastd (and maybe hastctl)
to drop privileges.

r218048 (pjd):

Implement function that drops privileges by:
- chrooting to /var/empty (user hast home directory),
- setting groups to 'hast' (user hast primary group),
- setting real group id, effective group id and saved group id to 'hast',
- setting real user id, effective user id and saved user id to 'hast'.
At the end verify that those operations where successfull.

r218049 (pjd):

Drop privileges in worker processes.

Accepting connections and handshaking in secondary is still done before
dropping privileges. It should be implemented by only accepting connections in
privileged main process and passing connection descriptors to the worker, but
is not implemented yet.

r218132 (pjd):

Rename pjdlog_verify() to pjdlog_abort() as it better describes what the
the function does and mark it with __dead2.

r218138 (pjd):

- Use pjdlog for assertions and aborts as this will log assert/abort message
  to syslog if we run in background.
- Asserts in proto.c that method we want to call is implemented and remove
  dummy methods from protocols implementation that are only there to abort
  the program with nice message.

r218139 (pjd):

Implement two new functions for sending descriptor and receving descriptor
over UNIX domain sockets and socket pairs.
This is in preparation for capsicum.

r218147 (pjd), r218148 (pjd):

Fix build on ia64.

r218158 (pjd):

Do not set socket send and receive buffer. It will be auto-tuned.

Confirmed by:   rwatson

r218185 (pjd):

Be prepared that hp_client or hp_server might be NULL now.

r218191 (pjd):

Move protocol allocation and deallocation to separate functions.

r218192 (pjd), r218201 (bz):

Allow to specify connection timeout by the caller.

r218193 (pjd):

Add proto_connect_wait() to wait for connection to finish.
If timeout argument to proto_connect() is -1, then the caller needs to use
this new function to wait for connection.

This change is in preparation for capsicum, where sandboxed worker wants
to ask main process to connect in worker's behalf and pass descriptor
to the worker. Because we don't want the main process to wait for the
connection, it will start async connection and pass descriptor to the
worker who will be responsible for waiting for the connection to finish.

r218194 (pjd):

- Rename proto_descriptor_{send,recv}() functions to
  proto_connection_{send,recv} and change them to return proto_conn
  structure. We don't operate directly on descriptors, but on
  proto_conns.
- Add wrap method to wrap descriptor with proto_conn.
- Remove methods to send and receive descriptors and implement this
  functionality as additional argument to send and receive methods.

r218214 (pjd):

Let the caller log info about successful privilege drop.
We don't want to log this in hastctl.

r218215 (pjd):

Drop privileges after connecting to hastd, but before sending or receiving
anything.

r218217 (pjd):

Add missing locking after moving keepalive_send() to remote send thread
in r214692.

r218218 (pjd):

Setup another socketpair between parent and child, so that primary sandboxed
worker can ask the main privileged process to connect in worker's behalf
and then we can migrate descriptor using this socketpair to worker.
This is not really needed now, but will be needed once we start to use
capsicum for sandboxing.

r218370 (pjd):

Close more descriptors that can be open if the worker process for the given
resource is already running.

Submitted by:   Mikolaj Golub <to.my.trociny@@gmail.com>

r218373 (pjd):

Open syslog when logging sysconf(3) failure.

Reported by:    Mikolaj Golub <to.my.trociny@@gmail.com>

r218374 (pjd):

Treat fstat(2) failure (different than EBADF) as fatal error.

Reported by:    Mikolaj Golub <to.my.trociny@@gmail.com>

r218375 (pjd):

Add (void) cast before snprintf(3)s for which we are not interested in return
values.

r218376 (pjd):

Now that we break the loop on fstat(2) failure we no longer need to satisfy
gcc's imperfections.

r218464 (pjd):

Unlink UNIX domain socket file only if:
1. The descriptor is the one we are listening on (not the one when we connect
   as a client and not the one which is created on accept(2)).
2. Descriptor was created by us (PID matches with the PID stored on bind(2)).

Reported by:    Mikolaj Golub <to.my.trociny@@gmail.com>

r218465 (pjd):

Explicitly include <sys/types.h> as suggested by getpid(2) and don't rely on
<sys/un.h> including what's needed.

r218474 (pjd):

When we decide to unlink socket file, sun_path must be set. If it is set,
but there is problem unlinking the file, log a warning.

r219082 (pjd):

Recognize 'reload' command, as hastd can be reloaded with the SIGHUP signal.

Approved by:	pjd (mentor)
@
text
@a20 1
extra_commands="reload"
@


1.3.2.4
log
@SVN rev 231655 on 2012-02-14 10:17:14Z by dougb

MFC r230099:

Change rcvar= assignments to the literal values set_rcvar
would have returned. This will slightly reduce boot time,
and help in diff reduction to HEAD.
@
text
@d14 1
a14 1
rcvar="hastd_enable"
@


1.3.2.5
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242909
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242909 | dim | 2012-11-12 07:47:19 +0000 (Mon, 12 Nov 2012) | 20 lines
## SVN ##
## SVN ## MFC r242625:
## SVN ##
## SVN ## Remove duplicate const specifiers in many drivers (I hope I got all of
## SVN ## them, please let me know if not).  Most of these are of the form:
## SVN ##
## SVN ## static const struct bzzt_type {
## SVN ##       [...list of members...]
## SVN ## } const bzzt_devs[] = {
## SVN ##       [...list of initializers...]
## SVN ## };
## SVN ##
## SVN ## The second const is unnecessary, as arrays cannot be modified anyway,
## SVN ## and if the elements are const, the whole thing is const automatically
## SVN ## (e.g. it is placed in .rodata).
## SVN ##
## SVN ## I have verified this does not change the binary output of a full kernel
## SVN ## build (except for build timestamps embedded in the object files).
## SVN ##
## SVN ## Reviewed by:	yongari, marius
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d3 1
a3 1
# $FreeBSD: stable/8/etc/rc.d/hastd 231655 2012-02-14 10:17:14Z dougb $
@


1.3.2.4.2.1
log
@SVN rev 232438 on 2012-03-03 06:15:13Z by kensmith

Copy stable/8 to releng/8.3 as part of 8.3-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.3.2.4.2.2
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: releng/8.3/etc/rc.d/hastd 231655 2012-02-14 10:17:14Z dougb $
@


1.3.2.2.4.1
log
@SVN rev 216617 on 2010-12-21 17:09:25Z by kensmith

Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.

Approved by:	re (implicit)
@
text
@@


1.3.2.2.2.1
log
@SVN rev 209145 on 2010-06-14 02:09:06Z by kensmith

Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.

Approved by:	re (implicit)
@
text
@@


1.2
log
@SVN rev 204077 on 2010-02-18 23:20:15Z by pjd

Remove some lines left over by accident.
@
text
@d9 1
@


1.1
log
@SVN rev 204076 on 2010-02-18 23:16:19Z by pjd

Please welcome HAST - Highly Avalable Storage.

HAST allows to transparently store data on two physically separated machines
connected over the TCP/IP network. HAST works in Primary-Secondary
(Master-Backup, Master-Slave) configuration, which means that only one of the
cluster nodes can be active at any given time. Only Primary node is able to
handle I/O requests to HAST-managed devices. Currently HAST is limited to two
cluster nodes in total.

HAST operates on block level - it provides disk-like devices in /dev/hast/
directory for use by file systems and/or applications. Working on block level
makes it transparent for file systems and applications. There in no difference
between using HAST-provided device and raw disk, partition, etc. All of them
are just regular GEOM providers in FreeBSD.

For more information please consult hastd(8), hastctl(8) and hast.conf(5)
manual pages, as well as http://wiki.FreeBSD.org/HAST.

Sponsored by:	FreeBSD Foundation
Sponsored by:	OMCnet Internet Service GmbH
Sponsored by:	TransIP BV
@
text
@a20 4
sockfile="/var/run/syslogd.sockets"
evalargs="rc_flags=\"\`set_socketlist\` \$rc_flags\""
altlog_proglist="named"

@

