From owner-svn-src-all@freebsd.org Mon Oct 5 10:40:16 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C8CA99B14C2; Mon, 5 Oct 2015 10:40:16 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AF9903F4; Mon, 5 Oct 2015 10:40:16 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t95AeG1H069330; Mon, 5 Oct 2015 10:40:16 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t95AeFRB069327; Mon, 5 Oct 2015 10:40:15 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201510051040.t95AeFRB069327@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 5 Oct 2015 10:40:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r288773 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Oct 2015 10:40:16 -0000 Author: mav Date: Mon Oct 5 10:40:15 2015 New Revision: 288773 URL: https://svnweb.freebsd.org/changeset/base/288773 Log: MFC r287957: Kill HA link and shutdown the threads on shutdown. Modified: stable/10/sys/cam/ctl/ctl.c stable/10/sys/cam/ctl/ctl_ha.c stable/10/sys/cam/ctl/ctl_ha.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl.c ============================================================================== --- stable/10/sys/cam/ctl/ctl.c Mon Oct 5 10:39:21 2015 (r288772) +++ stable/10/sys/cam/ctl/ctl.c Mon Oct 5 10:40:15 2015 (r288773) @@ -1583,13 +1583,12 @@ ctl_shutdown(void) softc = (struct ctl_softc *)control_softc; if (softc->is_single == 0) { + ctl_ha_msg_shutdown(softc); if (ctl_ha_msg_deregister(CTL_HA_CHAN_CTL) - != CTL_HA_STATUS_SUCCESS) { - printf("ctl_shutdown: ctl_ha_msg_deregister failed.\n"); - } - if (ctl_ha_msg_shutdown(softc) != CTL_HA_STATUS_SUCCESS) { - printf("ctl_shutdown: ctl_ha_msg_shutdown failed.\n"); - } + != CTL_HA_STATUS_SUCCESS) + printf("%s: ctl_ha_msg_deregister failed.\n", __func__); + if (ctl_ha_msg_destroy(softc) != CTL_HA_STATUS_SUCCESS) + printf("%s: ctl_ha_msg_destroy failed.\n", __func__); ctl_frontend_deregister(&ha_frontend); } Modified: stable/10/sys/cam/ctl/ctl_ha.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_ha.c Mon Oct 5 10:39:21 2015 (r288772) +++ stable/10/sys/cam/ctl/ctl_ha.c Mon Oct 5 10:40:15 2015 (r288773) @@ -155,6 +155,8 @@ struct ha_softc { int ha_receiving; int ha_wakeup; int ha_disconnect; + int ha_shutdown; + eventhandler_tag ha_shutdown_eh; TAILQ_HEAD(, ctl_ha_dt_req) ha_dts; } ha_softc; @@ -568,10 +570,12 @@ ctl_ha_conn_thread(void *arg) int error; while (1) { - if (softc->ha_disconnect) { + if (softc->ha_disconnect || softc->ha_shutdown) { ctl_ha_close(softc); ctl_ha_lclose(softc); softc->ha_disconnect = 0; + if (softc->ha_shutdown) + break; } else if (softc->ha_so != NULL && (softc->ha_so->so_error || softc->ha_so->so_rcv.sb_state & SBS_CANTRCVMORE)) @@ -614,6 +618,11 @@ ctl_ha_conn_thread(void *arg) softc->ha_wakeup = 0; mtx_unlock(&softc->ha_lock); } + mtx_lock(&softc->ha_lock); + softc->ha_shutdown = 2; + wakeup(&softc->ha_wakeup); + mtx_unlock(&softc->ha_lock); + kthread_exit(); } static int @@ -936,6 +945,8 @@ ctl_ha_msg_init(struct ctl_softc *ctl_so mtx_destroy(&softc->ha_lock); return (CTL_HA_STATUS_ERROR); } + softc->ha_shutdown_eh = EVENTHANDLER_REGISTER(shutdown_pre_sync, + ctl_ha_msg_shutdown, ctl_softc, SHUTDOWN_PRI_FIRST); SYSCTL_ADD_PROC(&ctl_softc->sysctl_ctx, SYSCTL_CHILDREN(ctl_softc->sysctl_tree), OID_AUTO, "ha_peer", CTLTYPE_STRING | CTLFLAG_RWTUN, @@ -949,14 +960,40 @@ ctl_ha_msg_init(struct ctl_softc *ctl_so return (CTL_HA_STATUS_SUCCESS); }; -ctl_ha_status +void ctl_ha_msg_shutdown(struct ctl_softc *ctl_softc) { struct ha_softc *softc = &ha_softc; - if (ctl_ha_msg_deregister(CTL_HA_CHAN_DATA) != CTL_HA_STATUS_SUCCESS) { - printf("%s: ctl_ha_msg_deregister failed.\n", __func__); + /* Disconnect and shutdown threads. */ + mtx_lock(&softc->ha_lock); + if (softc->ha_shutdown < 2) { + softc->ha_shutdown = 1; + softc->ha_wakeup = 1; + wakeup(&softc->ha_wakeup); + while (softc->ha_shutdown < 2) { + msleep(&softc->ha_wakeup, &softc->ha_lock, 0, + "shutdown", hz); + } } + mtx_unlock(&softc->ha_lock); +}; + +ctl_ha_status +ctl_ha_msg_destroy(struct ctl_softc *ctl_softc) +{ + struct ha_softc *softc = &ha_softc; + + if (softc->ha_shutdown_eh != NULL) { + EVENTHANDLER_DEREGISTER(shutdown_pre_sync, + softc->ha_shutdown_eh); + softc->ha_shutdown_eh = NULL; + } + + ctl_ha_msg_shutdown(ctl_softc); /* Just in case. */ + + if (ctl_ha_msg_deregister(CTL_HA_CHAN_DATA) != CTL_HA_STATUS_SUCCESS) + printf("%s: ctl_ha_msg_deregister failed.\n", __func__); mtx_destroy(&softc->ha_lock); return (CTL_HA_STATUS_SUCCESS); Modified: stable/10/sys/cam/ctl/ctl_ha.h ============================================================================== --- stable/10/sys/cam/ctl/ctl_ha.h Mon Oct 5 10:39:21 2015 (r288772) +++ stable/10/sys/cam/ctl/ctl_ha.h Mon Oct 5 10:40:15 2015 (r288773) @@ -109,7 +109,8 @@ struct ctl_ha_dt_req { struct ctl_softc; ctl_ha_status ctl_ha_msg_init(struct ctl_softc *softc); -ctl_ha_status ctl_ha_msg_shutdown(struct ctl_softc *softc); +void ctl_ha_msg_shutdown(struct ctl_softc *softc); +ctl_ha_status ctl_ha_msg_destroy(struct ctl_softc *softc); typedef void (*ctl_evt_handler)(ctl_ha_channel channel, ctl_ha_event event, int param);