From owner-svn-src-head@FreeBSD.ORG Mon Aug 30 00:31:31 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3AE7A10656B2; Mon, 30 Aug 2010 00:31:31 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1FD818FC23; Mon, 30 Aug 2010 00:31:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7U0VVjZ078939; Mon, 30 Aug 2010 00:31:31 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7U0VUHn078935; Mon, 30 Aug 2010 00:31:30 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201008300031.o7U0VUHn078935@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Mon, 30 Aug 2010 00:31:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211984 - head/sbin/hastd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2010 00:31:31 -0000 Author: pjd Date: Mon Aug 30 00:31:30 2010 New Revision: 211984 URL: http://svn.freebsd.org/changeset/base/211984 Log: Execute hook when connection between the nodes is established or lost. MFC after: 2 weeks Obtained from: Wheel Systems Sp. z o.o. http://www.wheelsystems.com Modified: head/sbin/hastd/hast.conf.5 head/sbin/hastd/primary.c head/sbin/hastd/secondary.c Modified: head/sbin/hastd/hast.conf.5 ============================================================================== --- head/sbin/hastd/hast.conf.5 Mon Aug 30 00:12:10 2010 (r211983) +++ head/sbin/hastd/hast.conf.5 Mon Aug 30 00:31:30 2010 (r211984) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 29, 2010 +.Dd August 30, 2010 .Dt HAST.CONF 5 .Os .Sh NAME @@ -212,6 +212,20 @@ Execute the given program on various HAS Below is the list of currently implemented events and arguments the given program is executed with: .Bl -tag -width ".Ic xxxx" +.It Ic " role " +.Pp +Executed on both primary and secondary nodes when resource role is changed. +.Pp +.It Ic " connect " +.Pp +Executed on both primary and secondary nodes when connection for the given +resource between the nodes is established. +.Pp +.It Ic " disconnect " +.Pp +Executed on both primary and secondary nodes when connection for the given +resource between the nodes is lost. +.Pp .It Ic " syncstart " .Pp Executed on primary node when synchronization process of secondary node is @@ -228,10 +242,6 @@ Executed on primary node when synchroniz interrupted, most likely due to secondary node outage or connection failure between the nodes. .Pp -.It Ic " role " -.Pp -Executed on both primary and secondary nodes when resource role is changed. -.Pp .It Ic " split-brain " .Pp Executed on both primary and secondary nodes when split-brain condition is Modified: head/sbin/hastd/primary.c ============================================================================== --- head/sbin/hastd/primary.c Mon Aug 30 00:12:10 2010 (r211983) +++ head/sbin/hastd/primary.c Mon Aug 30 00:31:30 2010 (r211984) @@ -672,6 +672,7 @@ init_remote(struct hast_resource *res, s res->hr_remotein = in; res->hr_remoteout = out; } + hook_exec(res->hr_exec, "connect", res->hr_name, NULL); return (true); close: if (errmsg != NULL && strcmp(errmsg, "Split-brain condition!") == 0) @@ -765,8 +766,6 @@ hastd_primary(struct hast_resource *res) pid_t pid; int error; - gres = res; - /* * Create communication channel between parent and child. */ @@ -788,6 +787,8 @@ hastd_primary(struct hast_resource *res) return; } + gres = res; + (void)pidfile_close(pfh); hook_fini(); @@ -894,6 +895,8 @@ remote_close(struct hast_resource *res, * Stop synchronization if in-progress. */ sync_stop(); + + hook_exec(res->hr_exec, "disconnect", res->hr_name, NULL); } /* Modified: head/sbin/hastd/secondary.c ============================================================================== --- head/sbin/hastd/secondary.c Mon Aug 30 00:12:10 2010 (r211983) +++ head/sbin/hastd/secondary.c Mon Aug 30 00:31:30 2010 (r211984) @@ -74,6 +74,8 @@ struct hio { TAILQ_ENTRY(hio) hio_next; }; +static struct hast_resource *gres; + /* * Free list holds unused structures. When free list is empty, we have to wait * until some in-progress requests are freed. @@ -360,6 +362,8 @@ hastd_secondary(struct hast_resource *re return; } + gres = res; + (void)pidfile_close(pfh); hook_fini(); @@ -378,6 +382,7 @@ hastd_secondary(struct hast_resource *re init_local(res); init_remote(res, nvin); init_environment(); + hook_exec(res->hr_exec, "connect", res->hr_name, NULL); error = pthread_create(&td, NULL, recv_thread, res); assert(error == 0); @@ -501,6 +506,19 @@ end: return (hio->hio_error); } +static void +secondary_exit(int exitcode, const char *fmt, ...) +{ + va_list ap; + + assert(exitcode != EX_OK); + va_start(ap, fmt); + pjdlogv_errno(LOG_ERR, fmt, ap); + va_end(ap); + hook_exec(gres->hr_exec, "disconnect", gres->hr_name, NULL); + exit(exitcode); +} + /* * Thread receives requests from the primary node. */ @@ -515,7 +533,7 @@ recv_thread(void *arg) QUEUE_TAKE(free, hio); pjdlog_debug(2, "recv: (%p) Got request.", hio); if (hast_proto_recv_hdr(res->hr_remotein, &hio->hio_nv) < 0) { - pjdlog_exit(EX_TEMPFAIL, + secondary_exit(EX_TEMPFAIL, "Unable to receive request header"); } if (requnpack(res, hio) != 0) { @@ -537,7 +555,7 @@ recv_thread(void *arg) } else if (hio->hio_cmd == HIO_WRITE) { if (hast_proto_recv_data(res, res->hr_remotein, hio->hio_nv, hio->hio_data, MAXPHYS) < 0) { - pjdlog_exit(EX_TEMPFAIL, + secondary_exit(EX_TEMPFAIL, "Unable to receive reply data"); } } @@ -693,7 +711,7 @@ send_thread(void *arg) nv_add_int16(nvout, hio->hio_error, "error"); if (hast_proto_send(res, res->hr_remoteout, nvout, data, length) < 0) { - pjdlog_exit(EX_TEMPFAIL, "Unable to send reply."); + secondary_exit(EX_TEMPFAIL, "Unable to send reply."); } nv_free(nvout); pjdlog_debug(2, "send: (%p) Moving request to the free queue.",