svn commit: r204749 - user/lstewart/alq_varlen_head/sys/kern
Lawrence Stewart
lstewart at FreeBSD.org
Fri Mar 5 04:26:30 UTC 2010
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 at freebsd.org>
* Copyright (c) 2008-2009, Lawrence Stewart <lstewart at 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. */
More information about the svn-src-user
mailing list