2 * Copyright (c) 1982, 1986, 1990, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Robert Elz at The University of Melbourne.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/namei.h>
44 #include <sys/malloc.h>
45 #include <sys/fcntl.h>
47 #include <sys/vnode.h>
48 #include <sys/mount.h>
49 #include <vm/vm_zone.h>
51 #include <ufs/ufs/quota.h>
52 #include <ufs/ufs/inode.h>
53 #include <ufs/ufs/ufsmount.h>
55 static MALLOC_DEFINE(M_DQUOT, "UFS quota", "UFS quota entries");
58 * Quota name to error message mapping.
60 static char *quotatypes[] = INITQFNAMES;
62 static int chkdqchg __P((struct inode *, long, struct ucred *, int));
63 static int chkiqchg __P((struct inode *, long, struct ucred *, int));
64 static int dqget __P((struct vnode *,
65 u_long, struct ufsmount *, int, struct dquot **));
66 static int dqsync __P((struct vnode *, struct dquot *));
67 static void dqflush __P((struct vnode *));
70 static void dqref __P((struct dquot *));
71 static void chkdquot __P((struct inode *));
75 * Set up the quotas for an inode.
77 * This routine completely defines the semantics of quotas.
78 * If other criterion want to be used to establish quotas, the
79 * MAXQUOTAS value in quotas.h should be increased, and the
80 * additional dquots set up here.
84 register struct inode *ip;
87 struct vnode *vp = ITOV(ip);
90 ump = VFSTOUFS(vp->v_mount);
92 * Set up the user quota based on file uid.
93 * EINVAL means that quotas are not enabled.
95 if (ip->i_dquot[USRQUOTA] == NODQUOT &&
97 dqget(vp, ip->i_uid, ump, USRQUOTA, &ip->i_dquot[USRQUOTA])) &&
101 * Set up the group quota based on file gid.
102 * EINVAL means that quotas are not enabled.
104 if (ip->i_dquot[GRPQUOTA] == NODQUOT &&
106 dqget(vp, ip->i_gid, ump, GRPQUOTA, &ip->i_dquot[GRPQUOTA])) &&
113 * Update disk usage, and take corrective action.
116 chkdq(ip, change, cred, flags)
117 register struct inode *ip;
122 register struct dquot *dq;
124 int ncurblocks, error;
127 if ((flags & CHOWN) == 0)
133 for (i = 0; i < MAXQUOTAS; i++) {
134 if ((dq = ip->i_dquot[i]) == NODQUOT)
136 while (dq->dq_flags & DQ_LOCK) {
137 dq->dq_flags |= DQ_WANT;
138 (void) tsleep((caddr_t)dq, PINOD+1, "chkdq1", 0);
140 ncurblocks = dq->dq_curblocks + change;
142 dq->dq_curblocks = ncurblocks;
144 dq->dq_curblocks = 0;
145 dq->dq_flags &= ~DQ_BLKS;
146 dq->dq_flags |= DQ_MOD;
150 if ((flags & FORCE) == 0 && cred->cr_uid != 0) {
151 for (i = 0; i < MAXQUOTAS; i++) {
152 if ((dq = ip->i_dquot[i]) == NODQUOT)
154 error = chkdqchg(ip, change, cred, i);
159 for (i = 0; i < MAXQUOTAS; i++) {
160 if ((dq = ip->i_dquot[i]) == NODQUOT)
162 while (dq->dq_flags & DQ_LOCK) {
163 dq->dq_flags |= DQ_WANT;
164 (void) tsleep((caddr_t)dq, PINOD+1, "chkdq2", 0);
166 dq->dq_curblocks += change;
167 dq->dq_flags |= DQ_MOD;
173 * Check for a valid change to a users allocation.
174 * Issue an error message if appropriate.
177 chkdqchg(ip, change, cred, type)
183 register struct dquot *dq = ip->i_dquot[type];
184 long ncurblocks = dq->dq_curblocks + change;
187 * If user would exceed their hard limit, disallow space allocation.
189 if (ncurblocks >= dq->dq_bhardlimit && dq->dq_bhardlimit) {
190 if ((dq->dq_flags & DQ_BLKS) == 0 &&
191 ip->i_uid == cred->cr_uid) {
192 uprintf("\n%s: write failed, %s disk limit reached\n",
193 ITOV(ip)->v_mount->mnt_stat.f_mntonname,
195 dq->dq_flags |= DQ_BLKS;
200 * If user is over their soft limit for too long, disallow space
201 * allocation. Reset time limit as they cross their soft limit.
203 if (ncurblocks >= dq->dq_bsoftlimit && dq->dq_bsoftlimit) {
204 if (dq->dq_curblocks < dq->dq_bsoftlimit) {
205 dq->dq_btime = time_second +
206 VFSTOUFS(ITOV(ip)->v_mount)->um_btime[type];
207 if (ip->i_uid == cred->cr_uid)
208 uprintf("\n%s: warning, %s %s\n",
209 ITOV(ip)->v_mount->mnt_stat.f_mntonname,
210 quotatypes[type], "disk quota exceeded");
213 if (time_second > dq->dq_btime) {
214 if ((dq->dq_flags & DQ_BLKS) == 0 &&
215 ip->i_uid == cred->cr_uid) {
216 uprintf("\n%s: write failed, %s %s\n",
217 ITOV(ip)->v_mount->mnt_stat.f_mntonname,
219 "disk quota exceeded for too long");
220 dq->dq_flags |= DQ_BLKS;
229 * Check the inode limit, applying corrective action.
232 chkiq(ip, change, cred, flags)
233 register struct inode *ip;
238 register struct dquot *dq;
240 int ncurinodes, error;
243 if ((flags & CHOWN) == 0)
249 for (i = 0; i < MAXQUOTAS; i++) {
250 if ((dq = ip->i_dquot[i]) == NODQUOT)
252 while (dq->dq_flags & DQ_LOCK) {
253 dq->dq_flags |= DQ_WANT;
254 (void) tsleep((caddr_t)dq, PINOD+1, "chkiq1", 0);
256 ncurinodes = dq->dq_curinodes + change;
258 dq->dq_curinodes = ncurinodes;
260 dq->dq_curinodes = 0;
261 dq->dq_flags &= ~DQ_INODS;
262 dq->dq_flags |= DQ_MOD;
266 if ((flags & FORCE) == 0 && cred->cr_uid != 0) {
267 for (i = 0; i < MAXQUOTAS; i++) {
268 if ((dq = ip->i_dquot[i]) == NODQUOT)
270 error = chkiqchg(ip, change, cred, i);
275 for (i = 0; i < MAXQUOTAS; i++) {
276 if ((dq = ip->i_dquot[i]) == NODQUOT)
278 while (dq->dq_flags & DQ_LOCK) {
279 dq->dq_flags |= DQ_WANT;
280 (void) tsleep((caddr_t)dq, PINOD+1, "chkiq2", 0);
282 dq->dq_curinodes += change;
283 dq->dq_flags |= DQ_MOD;
289 * Check for a valid change to a users allocation.
290 * Issue an error message if appropriate.
293 chkiqchg(ip, change, cred, type)
299 register struct dquot *dq = ip->i_dquot[type];
300 long ncurinodes = dq->dq_curinodes + change;
303 * If user would exceed their hard limit, disallow inode allocation.
305 if (ncurinodes >= dq->dq_ihardlimit && dq->dq_ihardlimit) {
306 if ((dq->dq_flags & DQ_INODS) == 0 &&
307 ip->i_uid == cred->cr_uid) {
308 uprintf("\n%s: write failed, %s inode limit reached\n",
309 ITOV(ip)->v_mount->mnt_stat.f_mntonname,
311 dq->dq_flags |= DQ_INODS;
316 * If user is over their soft limit for too long, disallow inode
317 * allocation. Reset time limit as they cross their soft limit.
319 if (ncurinodes >= dq->dq_isoftlimit && dq->dq_isoftlimit) {
320 if (dq->dq_curinodes < dq->dq_isoftlimit) {
321 dq->dq_itime = time_second +
322 VFSTOUFS(ITOV(ip)->v_mount)->um_itime[type];
323 if (ip->i_uid == cred->cr_uid)
324 uprintf("\n%s: warning, %s %s\n",
325 ITOV(ip)->v_mount->mnt_stat.f_mntonname,
326 quotatypes[type], "inode quota exceeded");
329 if (time_second > dq->dq_itime) {
330 if ((dq->dq_flags & DQ_INODS) == 0 &&
331 ip->i_uid == cred->cr_uid) {
332 uprintf("\n%s: write failed, %s %s\n",
333 ITOV(ip)->v_mount->mnt_stat.f_mntonname,
335 "inode quota exceeded for too long");
336 dq->dq_flags |= DQ_INODS;
346 * On filesystems with quotas enabled, it is an error for a file to change
347 * size and not to have a dquot structure associated with it.
351 register struct inode *ip;
353 struct ufsmount *ump = VFSTOUFS(ITOV(ip)->v_mount);
356 for (i = 0; i < MAXQUOTAS; i++) {
357 if (ump->um_quotas[i] == NULLVP ||
358 (ump->um_qflags[i] & (QTF_OPENING|QTF_CLOSING)))
360 if (ip->i_dquot[i] == NODQUOT) {
361 vprint("chkdquot: missing dquot", ITOV(ip));
362 panic("chkdquot: missing dquot");
369 * Code to process quotactl commands.
373 * Q_QUOTAON - set up a quota file for a particular file system.
376 quotaon(p, mp, type, fname)
382 struct ufsmount *ump = VFSTOUFS(mp);
383 struct vnode *vp, **vpp;
384 struct vnode *nextvp;
389 vpp = &ump->um_quotas[type];
390 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, fname, p);
391 error = vn_open(&nd, FREAD|FWRITE, 0);
394 NDFREE(&nd, NDF_ONLY_PNBUF);
396 VOP_UNLOCK(vp, 0, p);
397 if (vp->v_type != VREG) {
398 (void) vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
402 quotaoff(p, mp, type);
403 ump->um_qflags[type] |= QTF_OPENING;
404 mp->mnt_flag |= MNT_QUOTA;
405 vp->v_flag |= VSYSTEM;
408 * Save the credential of the process that turned on quotas.
409 * Set up the time limits for this quota.
412 ump->um_cred[type] = p->p_ucred;
413 ump->um_btime[type] = MAX_DQ_TIME;
414 ump->um_itime[type] = MAX_IQ_TIME;
415 if (dqget(NULLVP, 0, ump, type, &dq) == 0) {
416 if (dq->dq_btime > 0)
417 ump->um_btime[type] = dq->dq_btime;
418 if (dq->dq_itime > 0)
419 ump->um_itime[type] = dq->dq_itime;
423 * Search vnodes associated with this mount point,
424 * adding references to quota file being opened.
425 * NB: only need to add dquot's for inodes being modified.
428 for (vp = mp->mnt_vnodelist.lh_first; vp != NULL; vp = nextvp) {
429 nextvp = vp->v_mntvnodes.le_next;
430 if (vp->v_type == VNON || vp->v_writecount == 0)
432 if (vget(vp, LK_EXCLUSIVE, p))
434 error = getinoquota(VTOI(vp));
440 if (vp->v_mntvnodes.le_next != nextvp || vp->v_mount != mp)
443 ump->um_qflags[type] &= ~QTF_OPENING;
445 quotaoff(p, mp, type);
450 * Q_QUOTAOFF - turn off disk quotas for a filesystem.
453 quotaoff(p, mp, type)
459 struct vnode *qvp, *nextvp;
460 struct ufsmount *ump = VFSTOUFS(mp);
465 if ((qvp = ump->um_quotas[type]) == NULLVP)
467 ump->um_qflags[type] |= QTF_CLOSING;
469 * Search vnodes associated with this mount point,
470 * deleting any references to quota file being closed.
473 for (vp = mp->mnt_vnodelist.lh_first; vp != NULL; vp = nextvp) {
474 nextvp = vp->v_mntvnodes.le_next;
475 if (vp->v_type == VNON)
477 if (vget(vp, LK_EXCLUSIVE, p))
480 dq = ip->i_dquot[type];
481 ip->i_dquot[type] = NODQUOT;
484 if (vp->v_mntvnodes.le_next != nextvp || vp->v_mount != mp)
488 qvp->v_flag &= ~VSYSTEM;
489 error = vn_close(qvp, FREAD|FWRITE, p->p_ucred, p);
490 ump->um_quotas[type] = NULLVP;
491 crfree(ump->um_cred[type]);
492 ump->um_cred[type] = NOCRED;
493 ump->um_qflags[type] &= ~QTF_CLOSING;
494 for (type = 0; type < MAXQUOTAS; type++)
495 if (ump->um_quotas[type] != NULLVP)
497 if (type == MAXQUOTAS)
498 mp->mnt_flag &= ~MNT_QUOTA;
503 * Q_GETQUOTA - return current values in a dqblk structure.
506 getquota(mp, id, type, addr)
515 error = dqget(NULLVP, id, VFSTOUFS(mp), type, &dq);
518 error = copyout((caddr_t)&dq->dq_dqb, addr, sizeof (struct dqblk));
524 * Q_SETQUOTA - assign an entire dqblk structure.
527 setquota(mp, id, type, addr)
533 register struct dquot *dq;
535 struct ufsmount *ump = VFSTOUFS(mp);
539 error = copyin(addr, (caddr_t)&newlim, sizeof (struct dqblk));
542 error = dqget(NULLVP, id, ump, type, &ndq);
546 while (dq->dq_flags & DQ_LOCK) {
547 dq->dq_flags |= DQ_WANT;
548 (void) tsleep((caddr_t)dq, PINOD+1, "setqta", 0);
551 * Copy all but the current values.
552 * Reset time limit if previously had no soft limit or were
553 * under it, but now have a soft limit and are over it.
555 newlim.dqb_curblocks = dq->dq_curblocks;
556 newlim.dqb_curinodes = dq->dq_curinodes;
557 if (dq->dq_id != 0) {
558 newlim.dqb_btime = dq->dq_btime;
559 newlim.dqb_itime = dq->dq_itime;
561 if (newlim.dqb_bsoftlimit &&
562 dq->dq_curblocks >= newlim.dqb_bsoftlimit &&
563 (dq->dq_bsoftlimit == 0 || dq->dq_curblocks < dq->dq_bsoftlimit))
564 newlim.dqb_btime = time_second + ump->um_btime[type];
565 if (newlim.dqb_isoftlimit &&
566 dq->dq_curinodes >= newlim.dqb_isoftlimit &&
567 (dq->dq_isoftlimit == 0 || dq->dq_curinodes < dq->dq_isoftlimit))
568 newlim.dqb_itime = time_second + ump->um_itime[type];
570 if (dq->dq_curblocks < dq->dq_bsoftlimit)
571 dq->dq_flags &= ~DQ_BLKS;
572 if (dq->dq_curinodes < dq->dq_isoftlimit)
573 dq->dq_flags &= ~DQ_INODS;
574 if (dq->dq_isoftlimit == 0 && dq->dq_bsoftlimit == 0 &&
575 dq->dq_ihardlimit == 0 && dq->dq_bhardlimit == 0)
576 dq->dq_flags |= DQ_FAKE;
578 dq->dq_flags &= ~DQ_FAKE;
579 dq->dq_flags |= DQ_MOD;
585 * Q_SETUSE - set current inode and block usage.
588 setuse(mp, id, type, addr)
594 register struct dquot *dq;
595 struct ufsmount *ump = VFSTOUFS(mp);
600 error = copyin(addr, (caddr_t)&usage, sizeof (struct dqblk));
603 error = dqget(NULLVP, id, ump, type, &ndq);
607 while (dq->dq_flags & DQ_LOCK) {
608 dq->dq_flags |= DQ_WANT;
609 (void) tsleep((caddr_t)dq, PINOD+1, "setuse", 0);
612 * Reset time limit if have a soft limit and were
613 * previously under it, but are now over it.
615 if (dq->dq_bsoftlimit && dq->dq_curblocks < dq->dq_bsoftlimit &&
616 usage.dqb_curblocks >= dq->dq_bsoftlimit)
617 dq->dq_btime = time_second + ump->um_btime[type];
618 if (dq->dq_isoftlimit && dq->dq_curinodes < dq->dq_isoftlimit &&
619 usage.dqb_curinodes >= dq->dq_isoftlimit)
620 dq->dq_itime = time_second + ump->um_itime[type];
621 dq->dq_curblocks = usage.dqb_curblocks;
622 dq->dq_curinodes = usage.dqb_curinodes;
623 if (dq->dq_curblocks < dq->dq_bsoftlimit)
624 dq->dq_flags &= ~DQ_BLKS;
625 if (dq->dq_curinodes < dq->dq_isoftlimit)
626 dq->dq_flags &= ~DQ_INODS;
627 dq->dq_flags |= DQ_MOD;
633 * Q_SYNC - sync quota files to disk.
639 struct ufsmount *ump = VFSTOUFS(mp);
640 struct proc *p = curproc; /* XXX */
641 struct vnode *vp, *nextvp;
646 * Check if the mount point has any quotas.
647 * If not, simply return.
649 for (i = 0; i < MAXQUOTAS; i++)
650 if (ump->um_quotas[i] != NULLVP)
655 * Search vnodes associated with this mount point,
656 * synchronizing any modified dquot structures.
658 simple_lock(&mntvnode_slock);
660 for (vp = mp->mnt_vnodelist.lh_first; vp != NULL; vp = nextvp) {
661 if (vp->v_mount != mp)
663 nextvp = vp->v_mntvnodes.le_next;
664 if (vp->v_type == VNON)
666 simple_lock(&vp->v_interlock);
667 simple_unlock(&mntvnode_slock);
668 error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, p);
670 simple_lock(&mntvnode_slock);
675 for (i = 0; i < MAXQUOTAS; i++) {
676 dq = VTOI(vp)->i_dquot[i];
677 if (dq != NODQUOT && (dq->dq_flags & DQ_MOD))
681 simple_lock(&mntvnode_slock);
682 if (vp->v_mntvnodes.le_next != nextvp)
685 simple_unlock(&mntvnode_slock);
690 * Code pertaining to management of the in-core dquot data structures.
692 #define DQHASH(dqvp, id) \
693 (&dqhashtbl[((((intptr_t)(dqvp)) >> 8) + id) & dqhash])
694 static LIST_HEAD(dqhash, dquot) *dqhashtbl;
695 static u_long dqhash;
700 #define DQUOTINC 5 /* minimum free dquots desired */
701 static TAILQ_HEAD(dqfreelist, dquot) dqfreelist;
702 static long numdquot, desireddquot = DQUOTINC;
705 * Initialize the quota system.
711 dqhashtbl = hashinit(desiredvnodes, M_DQUOT, &dqhash);
712 TAILQ_INIT(&dqfreelist);
716 * Obtain a dquot structure for the specified identifier and quota file
717 * reading the information from the file if necessary.
720 dqget(vp, id, ump, type, dqp)
723 register struct ufsmount *ump;
727 struct proc *p = curproc; /* XXX */
735 dqvp = ump->um_quotas[type];
736 if (dqvp == NULLVP || (ump->um_qflags[type] & QTF_CLOSING)) {
741 * Check the cache first.
743 dqh = DQHASH(dqvp, id);
744 for (dq = dqh->lh_first; dq; dq = dq->dq_hash.le_next) {
745 if (dq->dq_id != id ||
746 dq->dq_ump->um_quotas[dq->dq_type] != dqvp)
749 * Cache hit with no references. Take
750 * the structure off the free list.
753 TAILQ_REMOVE(&dqfreelist, dq, dq_freelist);
759 * Not in cache, allocate a new one.
761 if (dqfreelist.tqh_first == NODQUOT &&
762 numdquot < MAXQUOTAS * desiredvnodes)
763 desireddquot += DQUOTINC;
764 if (numdquot < desireddquot) {
765 dq = (struct dquot *)malloc(sizeof *dq, M_DQUOT, M_WAITOK);
766 bzero((char *)dq, sizeof *dq);
769 if ((dq = dqfreelist.tqh_first) == NULL) {
774 if (dq->dq_cnt || (dq->dq_flags & DQ_MOD))
775 panic("dqget: free dquot isn't");
776 TAILQ_REMOVE(&dqfreelist, dq, dq_freelist);
777 LIST_REMOVE(dq, dq_hash);
780 * Initialize the contents of the dquot structure.
783 vn_lock(dqvp, LK_EXCLUSIVE | LK_RETRY, p);
784 LIST_INSERT_HEAD(dqh, dq, dq_hash);
786 dq->dq_flags = DQ_LOCK;
790 auio.uio_iov = &aiov;
792 aiov.iov_base = (caddr_t)&dq->dq_dqb;
793 aiov.iov_len = sizeof (struct dqblk);
794 auio.uio_resid = sizeof (struct dqblk);
795 auio.uio_offset = (off_t)(id * sizeof (struct dqblk));
796 auio.uio_segflg = UIO_SYSSPACE;
797 auio.uio_rw = UIO_READ;
798 auio.uio_procp = (struct proc *)0;
799 error = VOP_READ(dqvp, &auio, 0, ump->um_cred[type]);
800 if (auio.uio_resid == sizeof(struct dqblk) && error == 0)
801 bzero((caddr_t)&dq->dq_dqb, sizeof(struct dqblk));
803 VOP_UNLOCK(dqvp, 0, p);
804 if (dq->dq_flags & DQ_WANT)
808 * I/O error in reading quota file, release
809 * quota structure and reflect problem to caller.
812 LIST_REMOVE(dq, dq_hash);
818 * Check for no limit to enforce.
819 * Initialize time values if necessary.
821 if (dq->dq_isoftlimit == 0 && dq->dq_bsoftlimit == 0 &&
822 dq->dq_ihardlimit == 0 && dq->dq_bhardlimit == 0)
823 dq->dq_flags |= DQ_FAKE;
824 if (dq->dq_id != 0) {
825 if (dq->dq_btime == 0)
826 dq->dq_btime = time_second + ump->um_btime[type];
827 if (dq->dq_itime == 0)
828 dq->dq_itime = time_second + ump->um_itime[type];
836 * Obtain a reference to a dquot.
848 * Release a reference to a dquot.
853 register struct dquot *dq;
858 if (dq->dq_cnt > 1) {
862 if (dq->dq_flags & DQ_MOD)
863 (void) dqsync(vp, dq);
864 if (--dq->dq_cnt > 0)
866 TAILQ_INSERT_TAIL(&dqfreelist, dq, dq_freelist);
870 * Update the disk quota in the quota file.
877 struct proc *p = curproc; /* XXX */
884 panic("dqsync: dquot");
885 if ((dq->dq_flags & DQ_MOD) == 0)
887 if ((dqvp = dq->dq_ump->um_quotas[dq->dq_type]) == NULLVP)
888 panic("dqsync: file");
890 vn_lock(dqvp, LK_EXCLUSIVE | LK_RETRY, p);
891 while (dq->dq_flags & DQ_LOCK) {
892 dq->dq_flags |= DQ_WANT;
893 (void) tsleep((caddr_t)dq, PINOD+2, "dqsync", 0);
894 if ((dq->dq_flags & DQ_MOD) == 0) {
896 VOP_UNLOCK(dqvp, 0, p);
900 dq->dq_flags |= DQ_LOCK;
901 auio.uio_iov = &aiov;
903 aiov.iov_base = (caddr_t)&dq->dq_dqb;
904 aiov.iov_len = sizeof (struct dqblk);
905 auio.uio_resid = sizeof (struct dqblk);
906 auio.uio_offset = (off_t)(dq->dq_id * sizeof (struct dqblk));
907 auio.uio_segflg = UIO_SYSSPACE;
908 auio.uio_rw = UIO_WRITE;
909 auio.uio_procp = (struct proc *)0;
910 error = VOP_WRITE(dqvp, &auio, 0, dq->dq_ump->um_cred[dq->dq_type]);
911 if (auio.uio_resid && error == 0)
913 if (dq->dq_flags & DQ_WANT)
915 dq->dq_flags &= ~(DQ_MOD|DQ_LOCK|DQ_WANT);
917 VOP_UNLOCK(dqvp, 0, p);
922 * Flush all entries from the cache for a particular vnode.
926 register struct vnode *vp;
928 register struct dquot *dq, *nextdq;
932 * Move all dquot's that used to refer to this quota
933 * file off their hash chains (they will eventually
934 * fall off the head of the free list and be re-used).
936 for (dqh = &dqhashtbl[dqhash]; dqh >= dqhashtbl; dqh--) {
937 for (dq = dqh->lh_first; dq; dq = nextdq) {
938 nextdq = dq->dq_hash.le_next;
939 if (dq->dq_ump->um_quotas[dq->dq_type] != vp)
942 panic("dqflush: stray dquot");
943 LIST_REMOVE(dq, dq_hash);
944 dq->dq_ump = (struct ufsmount *)0;