Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Mar 2010 04:26:30 +0000 (UTC)
From:      Lawrence Stewart <lstewart@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r204749 - user/lstewart/alq_varlen_head/sys/kern
Message-ID:  <201003050426.o254QUn0087894@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <jeff@freebsd.org>
  * Copyright (c) 2008-2009, Lawrence Stewart <lstewart@freebsd.org>
- * 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. */



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