diff options
author | lstewart <lstewart@FreeBSD.org> | 2010-04-01 01:16:00 +0000 |
---|---|---|
committer | lstewart <lstewart@FreeBSD.org> | 2010-04-01 01:16:00 +0000 |
commit | 4aab292692d40ec1a2434f013498cf12da9a3e41 (patch) | |
tree | 9da55eeb0db8f23abd82369ab9148be19094ae26 | |
parent | c470b0d21d5c8a8b7ae21d1002b426d70563d49c (diff) | |
download | FreeBSD-src-4aab292692d40ec1a2434f013498cf12da9a3e41.zip FreeBSD-src-4aab292692d40ec1a2434f013498cf12da9a3e41.tar.gz |
- Factor code to destroy an ALQ out of alq_close() into a private alq_destroy().
- Use the new alq_destroy() to properly handle a failure case in alq_open().
Sponsored by: FreeBSD Foundation
Reviewed by: dwmalone, jeff, rpaulo, rwatson (as part of a larger patch)
Approved by: kmacy (mentor)
MFC after: 1 month
-rw-r--r-- | sys/kern/kern_alq.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/sys/kern/kern_alq.c b/sys/kern/kern_alq.c index 20d4fee..93d00c0 100644 --- a/sys/kern/kern_alq.c +++ b/sys/kern/kern_alq.c @@ -103,6 +103,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 *); @@ -263,6 +264,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. */ @@ -420,8 +433,11 @@ alq_open(struct alq **alqp, const char *file, struct ucred *cred, int cmode, 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); @@ -525,22 +541,9 @@ 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 |