kern_alq.c revision 116697
1103785Sjeff/*
2103785Sjeff * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
3103785Sjeff * All rights reserved.
4103785Sjeff *
5103785Sjeff * Redistribution and use in source and binary forms, with or without
6103785Sjeff * modification, are permitted provided that the following conditions
7103785Sjeff * are met:
8103785Sjeff * 1. Redistributions of source code must retain the above copyright
9103785Sjeff *    notice unmodified, this list of conditions, and the following
10103785Sjeff *    disclaimer.
11103785Sjeff * 2. Redistributions in binary form must reproduce the above copyright
12103785Sjeff *    notice, this list of conditions and the following disclaimer in the
13103785Sjeff *    documentation and/or other materials provided with the distribution.
14103785Sjeff *
15103785Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16103785Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17103785Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18103785Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19103785Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20103785Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21103785Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22103785Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23103785Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24103785Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25103785Sjeff */
26103785Sjeff
27116182Sobrien#include <sys/cdefs.h>
28116182Sobrien__FBSDID("$FreeBSD: head/sys/kern/kern_alq.c 116697 2003-06-22 22:28:56Z rwatson $");
29116182Sobrien
30103785Sjeff#include <sys/param.h>
31103785Sjeff#include <sys/systm.h>
32103785Sjeff#include <sys/kernel.h>
33103785Sjeff#include <sys/kthread.h>
34103785Sjeff#include <sys/lock.h>
35103785Sjeff#include <sys/mutex.h>
36103785Sjeff#include <sys/namei.h>
37103785Sjeff#include <sys/proc.h>
38103785Sjeff#include <sys/vnode.h>
39103785Sjeff#include <sys/alq.h>
40103785Sjeff#include <sys/malloc.h>
41103785Sjeff#include <sys/unistd.h>
42103785Sjeff#include <sys/fcntl.h>
43103785Sjeff#include <sys/eventhandler.h>
44103785Sjeff
45103785Sjeff/* Async. Logging Queue */
46103785Sjeffstruct alq {
47103785Sjeff	int	aq_entmax;		/* Max entries */
48103785Sjeff	int	aq_entlen;		/* Entry length */
49103785Sjeff	char	*aq_entbuf;		/* Buffer for stored entries */
50103785Sjeff	int	aq_flags;		/* Queue flags */
51103785Sjeff	struct mtx	aq_mtx;		/* Queue lock */
52103785Sjeff	struct vnode	*aq_vp;		/* Open vnode handle */
53103830Sjeff	struct ucred	*aq_cred;	/* Credentials of the opening thread */
54103785Sjeff	struct ale	*aq_first;	/* First ent */
55103785Sjeff	struct ale	*aq_entfree;	/* First free ent */
56103785Sjeff	struct ale	*aq_entvalid;	/* First ent valid for writing */
57103785Sjeff	LIST_ENTRY(alq)	aq_act;		/* List of active queues */
58103785Sjeff	LIST_ENTRY(alq)	aq_link;	/* List of all queues */
59103785Sjeff};
60103785Sjeff
61103785Sjeff#define	AQ_WANTED	0x0001		/* Wakeup sleeper when io is done */
62103785Sjeff#define	AQ_ACTIVE	0x0002		/* on the active list */
63103785Sjeff#define	AQ_FLUSHING	0x0004		/* doing IO */
64103785Sjeff#define	AQ_SHUTDOWN	0x0008		/* Queue no longer valid */
65103785Sjeff
66103785Sjeff#define	ALQ_LOCK(alq)	mtx_lock_spin(&(alq)->aq_mtx)
67103785Sjeff#define	ALQ_UNLOCK(alq)	mtx_unlock_spin(&(alq)->aq_mtx)
68103785Sjeff
69103785Sjeffstatic MALLOC_DEFINE(M_ALD, "ALD", "ALD");
70103785Sjeff
71103785Sjeff/*
72103785Sjeff * The ald_mtx protects the ald_queues list and the ald_active list.
73103785Sjeff */
74103785Sjeffstatic struct mtx ald_mtx;
75103785Sjeffstatic LIST_HEAD(, alq) ald_queues;
76103785Sjeffstatic LIST_HEAD(, alq) ald_active;
77103785Sjeffstatic int ald_shutingdown = 0;
78103995Sjeffstruct thread *ald_thread;
79103995Sjeffstatic struct proc *ald_proc;
80103785Sjeff
81103785Sjeff#define	ALD_LOCK()	mtx_lock(&ald_mtx)
82103785Sjeff#define	ALD_UNLOCK()	mtx_unlock(&ald_mtx)
83103785Sjeff
84103785Sjeff/* Daemon functions */
85103785Sjeffstatic int ald_add(struct alq *);
86103785Sjeffstatic int ald_rem(struct alq *);
87103785Sjeffstatic void ald_startup(void *);
88103785Sjeffstatic void ald_daemon(void);
89103785Sjeffstatic void ald_shutdown(void *, int);
90103785Sjeffstatic void ald_activate(struct alq *);
91103785Sjeffstatic void ald_deactivate(struct alq *);
92103785Sjeff
93103785Sjeff/* Internal queue functions */
94103785Sjeffstatic void alq_shutdown(struct alq *);
95103785Sjeffstatic int alq_doio(struct alq *);
96103785Sjeff
97103785Sjeff
98103785Sjeff/*
99103785Sjeff * Add a new queue to the global list.  Fail if we're shutting down.
100103785Sjeff */
101103785Sjeffstatic int
102103785Sjeffald_add(struct alq *alq)
103103785Sjeff{
104103785Sjeff	int error;
105103785Sjeff
106103785Sjeff	error = 0;
107103785Sjeff
108103785Sjeff	ALD_LOCK();
109103785Sjeff	if (ald_shutingdown) {
110103785Sjeff		error = EBUSY;
111103785Sjeff		goto done;
112103785Sjeff	}
113103785Sjeff	LIST_INSERT_HEAD(&ald_queues, alq, aq_link);
114103785Sjeffdone:
115103785Sjeff	ALD_UNLOCK();
116103785Sjeff	return (error);
117103785Sjeff}
118103785Sjeff
119103785Sjeff/*
120103785Sjeff * Remove a queue from the global list unless we're shutting down.  If so,
121103785Sjeff * the ald will take care of cleaning up it's resources.
122103785Sjeff */
123103785Sjeffstatic int
124103785Sjeffald_rem(struct alq *alq)
125103785Sjeff{
126103785Sjeff	int error;
127103785Sjeff
128103785Sjeff	error = 0;
129103785Sjeff
130103785Sjeff	ALD_LOCK();
131103785Sjeff	if (ald_shutingdown) {
132103785Sjeff		error = EBUSY;
133103785Sjeff		goto done;
134103785Sjeff	}
135103785Sjeff	LIST_REMOVE(alq, aq_link);
136103785Sjeffdone:
137103785Sjeff	ALD_UNLOCK();
138103785Sjeff	return (error);
139103785Sjeff}
140103785Sjeff
141103785Sjeff/*
142103785Sjeff * Put a queue on the active list.  This will schedule it for writing.
143103785Sjeff */
144103785Sjeffstatic void
145103785Sjeffald_activate(struct alq *alq)
146103785Sjeff{
147103785Sjeff	LIST_INSERT_HEAD(&ald_active, alq, aq_act);
148103785Sjeff	wakeup(&ald_active);
149103785Sjeff}
150103785Sjeff
151103785Sjeffstatic void
152103785Sjeffald_deactivate(struct alq *alq)
153103785Sjeff{
154103785Sjeff	LIST_REMOVE(alq, aq_act);
155103785Sjeff	alq->aq_flags &= ~AQ_ACTIVE;
156103785Sjeff}
157103785Sjeff
158103785Sjeffstatic void
159103785Sjeffald_startup(void *unused)
160103785Sjeff{
161103785Sjeff	mtx_init(&ald_mtx, "ALDmtx", NULL, MTX_DEF|MTX_QUIET);
162103785Sjeff	LIST_INIT(&ald_queues);
163103785Sjeff	LIST_INIT(&ald_active);
164103785Sjeff}
165103785Sjeff
166103785Sjeffstatic void
167103785Sjeffald_daemon(void)
168103785Sjeff{
169103785Sjeff	int needwakeup;
170103785Sjeff	struct alq *alq;
171103785Sjeff
172103785Sjeff	mtx_lock(&Giant);
173103785Sjeff
174103995Sjeff	ald_thread = FIRST_THREAD_IN_PROC(ald_proc);
175103995Sjeff
176103785Sjeff	EVENTHANDLER_REGISTER(shutdown_pre_sync, ald_shutdown, NULL,
177103785Sjeff	    SHUTDOWN_PRI_FIRST);
178103785Sjeff
179103785Sjeff	ALD_LOCK();
180103785Sjeff
181103785Sjeff	for (;;) {
182103785Sjeff		while ((alq = LIST_FIRST(&ald_active)) == NULL)
183103785Sjeff			msleep(&ald_active, &ald_mtx, PWAIT, "aldslp", 0);
184103785Sjeff
185103785Sjeff		ALQ_LOCK(alq);
186103785Sjeff		ald_deactivate(alq);
187103785Sjeff		ALD_UNLOCK();
188103785Sjeff		needwakeup = alq_doio(alq);
189103785Sjeff		ALQ_UNLOCK(alq);
190103785Sjeff		if (needwakeup)
191103785Sjeff			wakeup(alq);
192103785Sjeff		ALD_LOCK();
193103785Sjeff	}
194103785Sjeff}
195103785Sjeff
196103785Sjeffstatic void
197103785Sjeffald_shutdown(void *arg, int howto)
198103785Sjeff{
199103785Sjeff	struct alq *alq;
200103785Sjeff
201103785Sjeff	ALD_LOCK();
202103785Sjeff	ald_shutingdown = 1;
203103785Sjeff
204103785Sjeff	while ((alq = LIST_FIRST(&ald_queues)) != NULL) {
205103785Sjeff		LIST_REMOVE(alq, aq_link);
206103785Sjeff		ALD_UNLOCK();
207103785Sjeff		alq_shutdown(alq);
208103785Sjeff		ALD_LOCK();
209103785Sjeff	}
210103785Sjeff	ALD_UNLOCK();
211103785Sjeff}
212103785Sjeff
213103785Sjeffstatic void
214103785Sjeffalq_shutdown(struct alq *alq)
215103785Sjeff{
216103785Sjeff	ALQ_LOCK(alq);
217103785Sjeff
218103785Sjeff	/* Stop any new writers. */
219103785Sjeff	alq->aq_flags |= AQ_SHUTDOWN;
220103785Sjeff
221103785Sjeff	/* Drain IO */
222103785Sjeff	while (alq->aq_flags & (AQ_FLUSHING|AQ_ACTIVE)) {
223103785Sjeff		alq->aq_flags |= AQ_WANTED;
224103785Sjeff		ALQ_UNLOCK(alq);
225103785Sjeff		tsleep(alq, PWAIT, "aldclose", 0);
226103785Sjeff		ALQ_LOCK(alq);
227103785Sjeff	}
228103785Sjeff	ALQ_UNLOCK(alq);
229103785Sjeff
230103995Sjeff	vn_close(alq->aq_vp, FWRITE, alq->aq_cred,
231103830Sjeff	    curthread);
232103830Sjeff	crfree(alq->aq_cred);
233103785Sjeff}
234103785Sjeff
235103785Sjeff/*
236103785Sjeff * Flush all pending data to disk.  This operation will block.
237103785Sjeff */
238103785Sjeffstatic int
239103785Sjeffalq_doio(struct alq *alq)
240103785Sjeff{
241103785Sjeff	struct thread *td;
242103785Sjeff	struct mount *mp;
243103785Sjeff	struct vnode *vp;
244103785Sjeff	struct uio auio;
245103785Sjeff	struct iovec aiov[2];
246103785Sjeff	struct ale *ale;
247103785Sjeff	struct ale *alstart;
248103785Sjeff	int totlen;
249103785Sjeff	int iov;
250103785Sjeff
251103785Sjeff	vp = alq->aq_vp;
252103785Sjeff	td = curthread;
253103785Sjeff	totlen = 0;
254103785Sjeff	iov = 0;
255103785Sjeff
256103785Sjeff	alstart = ale = alq->aq_entvalid;
257103785Sjeff	alq->aq_entvalid = NULL;
258103785Sjeff
259103785Sjeff	bzero(&aiov, sizeof(aiov));
260103785Sjeff	bzero(&auio, sizeof(auio));
261103785Sjeff
262103785Sjeff	do {
263103785Sjeff		if (aiov[iov].iov_base == NULL)
264103785Sjeff			aiov[iov].iov_base = ale->ae_data;
265103785Sjeff		aiov[iov].iov_len += alq->aq_entlen;
266103785Sjeff		totlen += alq->aq_entlen;
267103785Sjeff		/* Check to see if we're wrapping the buffer */
268103785Sjeff		if (ale->ae_data + alq->aq_entlen != ale->ae_next->ae_data)
269103785Sjeff			iov++;
270103785Sjeff		ale->ae_flags &= ~AE_VALID;
271103785Sjeff		ale = ale->ae_next;
272103785Sjeff	} while (ale->ae_flags & AE_VALID);
273103785Sjeff
274103785Sjeff	alq->aq_flags |= AQ_FLUSHING;
275103785Sjeff	ALQ_UNLOCK(alq);
276103785Sjeff
277103785Sjeff	if (iov == 2 || aiov[iov].iov_base == NULL)
278103785Sjeff		iov--;
279103785Sjeff
280103785Sjeff	auio.uio_iov = &aiov[0];
281103785Sjeff	auio.uio_offset = 0;
282103785Sjeff	auio.uio_segflg = UIO_SYSSPACE;
283103785Sjeff	auio.uio_rw = UIO_WRITE;
284103785Sjeff	auio.uio_iovcnt = iov + 1;
285103785Sjeff	auio.uio_resid = totlen;
286103785Sjeff	auio.uio_td = td;
287103785Sjeff
288103785Sjeff	/*
289103785Sjeff	 * Do all of the junk required to write now.
290103785Sjeff	 */
291103785Sjeff	vn_start_write(vp, &mp, V_WAIT);
292103785Sjeff	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
293103830Sjeff	VOP_LEASE(vp, td, alq->aq_cred, LEASE_WRITE);
294103785Sjeff	/* XXX error ignored */
295103830Sjeff	VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, alq->aq_cred);
296103785Sjeff	VOP_UNLOCK(vp, 0, td);
297103785Sjeff	vn_finished_write(mp);
298103785Sjeff
299103785Sjeff	ALQ_LOCK(alq);
300103785Sjeff	alq->aq_flags &= ~AQ_FLUSHING;
301103785Sjeff
302103785Sjeff	if (alq->aq_entfree == NULL)
303103785Sjeff		alq->aq_entfree = alstart;
304103785Sjeff
305103785Sjeff	if (alq->aq_flags & AQ_WANTED) {
306103785Sjeff		alq->aq_flags &= ~AQ_WANTED;
307103785Sjeff		return (1);
308103785Sjeff	}
309103785Sjeff
310103785Sjeff	return(0);
311103785Sjeff}
312103785Sjeff
313103785Sjeffstatic struct kproc_desc ald_kp = {
314103785Sjeff        "ALQ Daemon",
315103785Sjeff        ald_daemon,
316103995Sjeff        &ald_proc
317103785Sjeff};
318103785Sjeff
319103785SjeffSYSINIT(aldthread, SI_SUB_KTHREAD_IDLE, SI_ORDER_ANY, kproc_start, &ald_kp)
320103785SjeffSYSINIT(ald, SI_SUB_LOCK, SI_ORDER_ANY, ald_startup, NULL)
321103785Sjeff
322103785Sjeff
323103785Sjeff/* User visible queue functions */
324103785Sjeff
325103785Sjeff/*
326103785Sjeff * Create the queue data structure, allocate the buffer, and open the file.
327103785Sjeff */
328103785Sjeffint
329116697Srwatsonalq_open(struct alq **alqp, const char *file, struct ucred *cred, int size,
330116697Srwatson    int count)
331103785Sjeff{
332103785Sjeff	struct thread *td;
333103785Sjeff	struct nameidata nd;
334103785Sjeff	struct ale *ale;
335103785Sjeff	struct ale *alp;
336103785Sjeff	struct alq *alq;
337103785Sjeff	char *bufp;
338103785Sjeff	int flags;
339103785Sjeff	int error;
340103785Sjeff	int i;
341103785Sjeff
342103785Sjeff	*alqp = NULL;
343103785Sjeff	td = curthread;
344103785Sjeff
345103785Sjeff	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, file, td);
346103995Sjeff	flags = FWRITE | O_NOFOLLOW | O_CREAT;
347103785Sjeff
348116697Srwatson	error = vn_open_cred(&nd, &flags, 0, cred);
349103785Sjeff	if (error)
350103785Sjeff		return (error);
351103785Sjeff
352103785Sjeff	NDFREE(&nd, NDF_ONLY_PNBUF);
353103785Sjeff	/* We just unlock so we hold a reference */
354103785Sjeff	VOP_UNLOCK(nd.ni_vp, 0, td);
355103785Sjeff
356111119Simp	alq = malloc(sizeof(*alq), M_ALD, M_WAITOK|M_ZERO);
357111119Simp	alq->aq_entbuf = malloc(count * size, M_ALD, M_WAITOK|M_ZERO);
358111119Simp	alq->aq_first = malloc(sizeof(*ale) * count, M_ALD, M_WAITOK|M_ZERO);
359103785Sjeff	alq->aq_vp = nd.ni_vp;
360116697Srwatson	alq->aq_cred = crhold(cred);
361103785Sjeff	alq->aq_entmax = count;
362103785Sjeff	alq->aq_entlen = size;
363103785Sjeff	alq->aq_entfree = alq->aq_first;
364103785Sjeff
365103785Sjeff	mtx_init(&alq->aq_mtx, "ALD Queue", NULL, MTX_SPIN|MTX_QUIET);
366103785Sjeff
367103785Sjeff	bufp = alq->aq_entbuf;
368103785Sjeff	ale = alq->aq_first;
369103785Sjeff	alp = NULL;
370103785Sjeff
371103785Sjeff	/* Match up entries with buffers */
372103785Sjeff	for (i = 0; i < count; i++) {
373103785Sjeff		if (alp)
374103785Sjeff			alp->ae_next = ale;
375103785Sjeff		ale->ae_data = bufp;
376103785Sjeff		alp = ale;
377103785Sjeff		ale++;
378103785Sjeff		bufp += size;
379103785Sjeff	}
380103785Sjeff
381103785Sjeff	alp->ae_next = alq->aq_first;
382103785Sjeff
383103785Sjeff	if ((error = ald_add(alq)) != 0)
384103785Sjeff		return (error);
385103785Sjeff	*alqp = alq;
386103785Sjeff
387103785Sjeff	return (0);
388103785Sjeff}
389103785Sjeff
390103785Sjeff/*
391103785Sjeff * Copy a new entry into the queue.  If the operation would block either
392103785Sjeff * wait or return an error depending on the value of waitok.
393103785Sjeff */
394103785Sjeffint
395103785Sjeffalq_write(struct alq *alq, void *data, int waitok)
396103785Sjeff{
397103785Sjeff	struct ale *ale;
398103785Sjeff
399103785Sjeff	if ((ale = alq_get(alq, waitok)) == NULL)
400103785Sjeff		return (EWOULDBLOCK);
401103785Sjeff
402103785Sjeff	bcopy(data, ale->ae_data, alq->aq_entlen);
403103785Sjeff	alq_post(alq, ale);
404103785Sjeff
405103785Sjeff	return (0);
406103785Sjeff}
407103785Sjeff
408103785Sjeffstruct ale *
409103785Sjeffalq_get(struct alq *alq, int waitok)
410103785Sjeff{
411103785Sjeff	struct ale *ale;
412103785Sjeff	struct ale *aln;
413103785Sjeff
414103785Sjeff	ale = NULL;
415103785Sjeff
416103785Sjeff	ALQ_LOCK(alq);
417103785Sjeff
418103785Sjeff	/* Loop until we get an entry or we're shutting down */
419103785Sjeff	while ((alq->aq_flags & AQ_SHUTDOWN) == 0 &&
420103785Sjeff	    (ale = alq->aq_entfree) == NULL &&
421103785Sjeff	    (waitok & ALQ_WAITOK)) {
422103785Sjeff		alq->aq_flags |= AQ_WANTED;
423103785Sjeff		ALQ_UNLOCK(alq);
424103785Sjeff		tsleep(alq, PWAIT, "alqget", 0);
425103785Sjeff		ALQ_LOCK(alq);
426103785Sjeff	}
427103785Sjeff
428103785Sjeff	if (ale != NULL) {
429103785Sjeff		aln = ale->ae_next;
430103785Sjeff		if ((aln->ae_flags & AE_VALID) == 0)
431103785Sjeff			alq->aq_entfree = aln;
432115308Sjeff		else
433115308Sjeff			alq->aq_entfree = NULL;
434103785Sjeff	} else
435103785Sjeff		ALQ_UNLOCK(alq);
436103785Sjeff
437103785Sjeff
438103785Sjeff	return (ale);
439103785Sjeff}
440103785Sjeff
441103785Sjeffvoid
442103785Sjeffalq_post(struct alq *alq, struct ale *ale)
443103785Sjeff{
444103785Sjeff	int activate;
445103785Sjeff
446103785Sjeff	ale->ae_flags |= AE_VALID;
447103785Sjeff
448103785Sjeff	if (alq->aq_entvalid == NULL)
449103785Sjeff		alq->aq_entvalid = ale;
450103785Sjeff
451103785Sjeff	if ((alq->aq_flags & AQ_ACTIVE) == 0) {
452103785Sjeff		alq->aq_flags |= AQ_ACTIVE;
453103785Sjeff		activate = 1;
454103785Sjeff	} else
455103785Sjeff		activate = 0;
456103785Sjeff
457103785Sjeff	ALQ_UNLOCK(alq);
458103785Sjeff	if (activate) {
459103785Sjeff		ALD_LOCK();
460103785Sjeff		ald_activate(alq);
461103785Sjeff		ALD_UNLOCK();
462103785Sjeff	}
463103785Sjeff}
464103785Sjeff
465103785Sjeffvoid
466103785Sjeffalq_flush(struct alq *alq)
467103785Sjeff{
468103785Sjeff	int needwakeup = 0;
469103785Sjeff
470103785Sjeff	ALD_LOCK();
471103785Sjeff	ALQ_LOCK(alq);
472103785Sjeff	if (alq->aq_flags & AQ_ACTIVE) {
473103785Sjeff		ald_deactivate(alq);
474103785Sjeff		ALD_UNLOCK();
475103785Sjeff		needwakeup = alq_doio(alq);
476103785Sjeff	} else
477103785Sjeff		ALD_UNLOCK();
478103785Sjeff	ALQ_UNLOCK(alq);
479103785Sjeff
480103785Sjeff	if (needwakeup)
481103785Sjeff		wakeup(alq);
482103785Sjeff}
483103785Sjeff
484103785Sjeff/*
485103785Sjeff * Flush remaining data, close the file and free all resources.
486103785Sjeff */
487103785Sjeffvoid
488103785Sjeffalq_close(struct alq *alq)
489103785Sjeff{
490103785Sjeff	/*
491103785Sjeff	 * If we're already shuting down someone else will flush and close
492103785Sjeff	 * the vnode.
493103785Sjeff	 */
494103785Sjeff	if (ald_rem(alq) != 0)
495103785Sjeff		return;
496103785Sjeff
497103785Sjeff	/*
498103785Sjeff	 * Drain all pending IO.
499103785Sjeff	 */
500103785Sjeff	alq_shutdown(alq);
501103785Sjeff
502103785Sjeff	mtx_destroy(&alq->aq_mtx);
503103785Sjeff	free(alq->aq_first, M_ALD);
504103785Sjeff	free(alq->aq_entbuf, M_ALD);
505103785Sjeff	free(alq, M_ALD);
506103785Sjeff}
507