kern_alq.c (f220f7afa67fcad6293d2a186d7c12c7f4400f34) kern_alq.c (33f19bee6fe93bbebb203968a7e7c4277218c8e1)
1/*-
2 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30#include "opt_mac.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/kthread.h>
36#include <sys/lock.h>
37#include <sys/mac.h>
1/*-
2 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30#include "opt_mac.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/kthread.h>
36#include <sys/lock.h>
37#include <sys/mac.h>
38#include <sys/mount.h>
38#include <sys/mutex.h>
39#include <sys/namei.h>
40#include <sys/proc.h>
41#include <sys/vnode.h>
42#include <sys/alq.h>
43#include <sys/malloc.h>
44#include <sys/unistd.h>
45#include <sys/fcntl.h>

--- 121 unchanged lines hidden (view full) ---

167}
168
169static void
170ald_daemon(void)
171{
172 int needwakeup;
173 struct alq *alq;
174
39#include <sys/mutex.h>
40#include <sys/namei.h>
41#include <sys/proc.h>
42#include <sys/vnode.h>
43#include <sys/alq.h>
44#include <sys/malloc.h>
45#include <sys/unistd.h>
46#include <sys/fcntl.h>

--- 121 unchanged lines hidden (view full) ---

168}
169
170static void
171ald_daemon(void)
172{
173 int needwakeup;
174 struct alq *alq;
175
175 mtx_lock(&Giant);
176
177 ald_thread = FIRST_THREAD_IN_PROC(ald_proc);
178
179 EVENTHANDLER_REGISTER(shutdown_pre_sync, ald_shutdown, NULL,
180 SHUTDOWN_PRI_FIRST);
181
182 ALD_LOCK();
183
184 for (;;) {

--- 60 unchanged lines hidden (view full) ---

245 struct mount *mp;
246 struct vnode *vp;
247 struct uio auio;
248 struct iovec aiov[2];
249 struct ale *ale;
250 struct ale *alstart;
251 int totlen;
252 int iov;
176 ald_thread = FIRST_THREAD_IN_PROC(ald_proc);
177
178 EVENTHANDLER_REGISTER(shutdown_pre_sync, ald_shutdown, NULL,
179 SHUTDOWN_PRI_FIRST);
180
181 ALD_LOCK();
182
183 for (;;) {

--- 60 unchanged lines hidden (view full) ---

244 struct mount *mp;
245 struct vnode *vp;
246 struct uio auio;
247 struct iovec aiov[2];
248 struct ale *ale;
249 struct ale *alstart;
250 int totlen;
251 int iov;
252 int vfslocked;
253
254 vp = alq->aq_vp;
255 td = curthread;
256 totlen = 0;
257 iov = 0;
258
259 alstart = ale = alq->aq_entvalid;
260 alq->aq_entvalid = NULL;

--- 25 unchanged lines hidden (view full) ---

286 auio.uio_rw = UIO_WRITE;
287 auio.uio_iovcnt = iov + 1;
288 auio.uio_resid = totlen;
289 auio.uio_td = td;
290
291 /*
292 * Do all of the junk required to write now.
293 */
253
254 vp = alq->aq_vp;
255 td = curthread;
256 totlen = 0;
257 iov = 0;
258
259 alstart = ale = alq->aq_entvalid;
260 alq->aq_entvalid = NULL;

--- 25 unchanged lines hidden (view full) ---

286 auio.uio_rw = UIO_WRITE;
287 auio.uio_iovcnt = iov + 1;
288 auio.uio_resid = totlen;
289 auio.uio_td = td;
290
291 /*
292 * Do all of the junk required to write now.
293 */
294 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
294 vn_start_write(vp, &mp, V_WAIT);
295 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
296 VOP_LEASE(vp, td, alq->aq_cred, LEASE_WRITE);
297 /*
298 * XXX: VOP_WRITE error checks are ignored.
299 */
300#ifdef MAC
301 if (mac_check_vnode_write(alq->aq_cred, NOCRED, vp) == 0)
302#endif
303 VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, alq->aq_cred);
304 VOP_UNLOCK(vp, 0, td);
305 vn_finished_write(mp);
295 vn_start_write(vp, &mp, V_WAIT);
296 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
297 VOP_LEASE(vp, td, alq->aq_cred, LEASE_WRITE);
298 /*
299 * XXX: VOP_WRITE error checks are ignored.
300 */
301#ifdef MAC
302 if (mac_check_vnode_write(alq->aq_cred, NOCRED, vp) == 0)
303#endif
304 VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, alq->aq_cred);
305 VOP_UNLOCK(vp, 0, td);
306 vn_finished_write(mp);
307 VFS_UNLOCK_GIANT(vfslocked);
306
307 ALQ_LOCK(alq);
308 alq->aq_flags &= ~AQ_FLUSHING;
309
310 if (alq->aq_entfree == NULL)
311 alq->aq_entfree = alstart;
312
313 if (alq->aq_flags & AQ_WANTED) {

--- 26 unchanged lines hidden (view full) ---

340 struct thread *td;
341 struct nameidata nd;
342 struct ale *ale;
343 struct ale *alp;
344 struct alq *alq;
345 char *bufp;
346 int flags;
347 int error;
308
309 ALQ_LOCK(alq);
310 alq->aq_flags &= ~AQ_FLUSHING;
311
312 if (alq->aq_entfree == NULL)
313 alq->aq_entfree = alstart;
314
315 if (alq->aq_flags & AQ_WANTED) {

--- 26 unchanged lines hidden (view full) ---

342 struct thread *td;
343 struct nameidata nd;
344 struct ale *ale;
345 struct ale *alp;
346 struct alq *alq;
347 char *bufp;
348 int flags;
349 int error;
348 int i;
350 int i, vfslocked;
349
350 *alqp = NULL;
351 td = curthread;
352
351
352 *alqp = NULL;
353 td = curthread;
354
353 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, file, td);
355 NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, file, td);
354 flags = FWRITE | O_NOFOLLOW | O_CREAT;
355
356 error = vn_open_cred(&nd, &flags, cmode, cred, -1);
357 if (error)
358 return (error);
359
356 flags = FWRITE | O_NOFOLLOW | O_CREAT;
357
358 error = vn_open_cred(&nd, &flags, cmode, cred, -1);
359 if (error)
360 return (error);
361
362 vfslocked = NDHASGIANT(&nd);
360 NDFREE(&nd, NDF_ONLY_PNBUF);
361 /* We just unlock so we hold a reference */
362 VOP_UNLOCK(nd.ni_vp, 0, td);
363 NDFREE(&nd, NDF_ONLY_PNBUF);
364 /* We just unlock so we hold a reference */
365 VOP_UNLOCK(nd.ni_vp, 0, td);
366 VFS_UNLOCK_GIANT(vfslocked);
363
364 alq = malloc(sizeof(*alq), M_ALD, M_WAITOK|M_ZERO);
365 alq->aq_entbuf = malloc(count * size, M_ALD, M_WAITOK|M_ZERO);
366 alq->aq_first = malloc(sizeof(*ale) * count, M_ALD, M_WAITOK|M_ZERO);
367 alq->aq_vp = nd.ni_vp;
368 alq->aq_cred = crhold(cred);
369 alq->aq_entmax = count;
370 alq->aq_entlen = size;

--- 144 unchanged lines hidden ---
367
368 alq = malloc(sizeof(*alq), M_ALD, M_WAITOK|M_ZERO);
369 alq->aq_entbuf = malloc(count * size, M_ALD, M_WAITOK|M_ZERO);
370 alq->aq_first = malloc(sizeof(*ale) * count, M_ALD, M_WAITOK|M_ZERO);
371 alq->aq_vp = nd.ni_vp;
372 alq->aq_cred = crhold(cred);
373 alq->aq_entmax = count;
374 alq->aq_entlen = size;

--- 144 unchanged lines hidden ---