From owner-svn-src-user@FreeBSD.ORG Fri Mar 5 04:26:30 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A34DA1065673; Fri, 5 Mar 2010 04:26:30 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 91FE28FC19; Fri, 5 Mar 2010 04:26:30 +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 o254QUGs087896; Fri, 5 Mar 2010 04:26:30 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o254QUn0087894; Fri, 5 Mar 2010 04:26:30 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201003050426.o254QUn0087894@svn.freebsd.org> From: Lawrence Stewart Date: Fri, 5 Mar 2010 04:26:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r204749 - user/lstewart/alq_varlen_head/sys/kern X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Mar 2010 04:26:30 -0000 Author: lstewart Date: Fri Mar 5 04:26:30 2010 New Revision: 204749 URL: http://svn.freebsd.org/changeset/base/204749 Log: A few niggling bits of cleanup: - Factor the ALQ destroy code out into a new function. - Ensure cleanup occurs if alq_open() fails to add the new ALQ to the ALD list. - Remove some gratuitous goto usage. - Ensure the module can't be forcibly unloaded if there are active ALQs. Sponsored by: FreeBSD Foundation Modified: user/lstewart/alq_varlen_head/sys/kern/kern_alq.c Modified: user/lstewart/alq_varlen_head/sys/kern/kern_alq.c ============================================================================== --- user/lstewart/alq_varlen_head/sys/kern/kern_alq.c Fri Mar 5 03:37:42 2010 (r204748) +++ user/lstewart/alq_varlen_head/sys/kern/kern_alq.c Fri Mar 5 04:26:30 2010 (r204749) @@ -1,7 +1,7 @@ /*- * Copyright (c) 2002, Jeffrey Roberson * Copyright (c) 2008-2009, Lawrence Stewart - * Copyright (c) 2009, The FreeBSD Foundation + * Copyright (c) 2009-2010, The FreeBSD Foundation * All rights reserved. * * Portions of this software were developed at the Centre for Advanced @@ -101,6 +101,7 @@ static void ald_deactivate(struct alq *) /* Internal queue functions */ static void alq_shutdown(struct alq *); +static void alq_destroy(struct alq *); static int alq_doio(struct alq *); @@ -113,14 +114,11 @@ ald_add(struct alq *alq) int error; error = 0; - ALD_LOCK(); - if (ald_shutingdown) { + if (ald_shutingdown) error = EBUSY; - goto done; - } - LIST_INSERT_HEAD(&ald_queues, alq, aq_link); -done: + else + LIST_INSERT_HEAD(&ald_queues, alq, aq_link); ALD_UNLOCK(); return (error); } @@ -135,14 +133,11 @@ ald_rem(struct alq *alq) int error; error = 0; - ALD_LOCK(); - if (ald_shutingdown) { + if (ald_shutingdown) error = EBUSY; - goto done; - } - LIST_REMOVE(alq, aq_link); -done: + else + LIST_REMOVE(alq, aq_link); ALD_UNLOCK(); return (error); } @@ -258,6 +253,18 @@ alq_shutdown(struct alq *alq) crfree(alq->aq_cred); } +void +alq_destroy(struct alq *alq) +{ + /* Drain all pending IO. */ + alq_shutdown(alq); + + mtx_destroy(&alq->aq_mtx); + free(alq->aq_first, M_ALD); + free(alq->aq_entbuf, M_ALD); + free(alq, M_ALD); +} + /* * Flush all pending data to disk. This operation will block. */ @@ -415,8 +422,11 @@ alq_open(struct alq **alqp, const char * alp->ae_next = alq->aq_first; - if ((error = ald_add(alq)) != 0) + if ((error = ald_add(alq)) != 0) { + alq_destroy(alq); return (error); + } + *alqp = alq; return (0); @@ -507,7 +517,9 @@ alq_post(struct alq *alq, struct ale *al void alq_flush(struct alq *alq) { - int needwakeup = 0; + int needwakeup; + + needwakeup = 0; ALD_LOCK(); ALQ_LOCK(alq); @@ -529,35 +541,24 @@ alq_flush(struct alq *alq) void alq_close(struct alq *alq) { - /* - * If we're already shuting down someone else will flush and close - * the vnode. - */ - if (ald_rem(alq) != 0) - return; - - /* - * Drain all pending IO. - */ - alq_shutdown(alq); - - mtx_destroy(&alq->aq_mtx); - free(alq->aq_first, M_ALD); - free(alq->aq_entbuf, M_ALD); - free(alq, M_ALD); + /* Only flush and destroy alq if not already shutting down. */ + if (ald_rem(alq) == 0) + alq_destroy(alq); } static int alq_load_handler(module_t mod, int what, void *arg) { - int ret = 0; + int ret; + + ret = 0; switch(what) { case MOD_LOAD: - case MOD_UNLOAD: case MOD_SHUTDOWN: break; - + + case MOD_UNLOAD: case MOD_QUIESCE: ALD_LOCK(); /* Only allow unload if there are no open queues. */