X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/89b3af67bb32e691275bf6fa803d1834b2284115..935ed37a5c468c8a1c07408573c08b8b7ef80e8b:/bsd/vfs/vfs_quota.c diff --git a/bsd/vfs/vfs_quota.c b/bsd/vfs/vfs_quota.c index 4e95edaa0..91ffe8bce 100644 --- a/bsd/vfs/vfs_quota.c +++ b/bsd/vfs/vfs_quota.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2002-2006 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -130,16 +130,11 @@ static void qf_rele(struct quotafile *); /* - * Initialize the quota system. + * Initialize locks for the quota system. */ void -dqinit() +dqinit(void) { - - dqhashtbl = hashinit(desiredvnodes, M_DQUOT, &dqhash); - TAILQ_INIT(&dqfreelist); - TAILQ_INIT(&dqdirtylist); - /* * Allocate quota list lock group attribute and group */ @@ -169,6 +164,32 @@ dqinit() qf_lck_attr = lck_attr_alloc_init(); } +/* + * Report whether dqhashinit has been run. + */ +int +dqisinitialized(void) +{ + return (dqhashtbl != NULL); +} + +/* + * Initialize hash table for dquot structures. + */ +void +dqhashinit(void) +{ + dq_list_lock(); + if (dqisinitialized()) + goto out; + + TAILQ_INIT(&dqfreelist); + TAILQ_INIT(&dqdirtylist); + dqhashtbl = hashinit(desiredvnodes, M_DQUOT, &dqhash); +out: + dq_list_unlock(); +} + static volatile int dq_list_lock_cnt = 0; @@ -204,7 +225,7 @@ dq_lock_internal(struct dquot *dq) { while (dq->dq_lflags & DQ_LLOCK) { dq->dq_lflags |= DQ_LWANT; - msleep(&dq->dq_lflags, quota_list_mtx_lock, PVFS, "dq_lock_internal", 0); + msleep(&dq->dq_lflags, quota_list_mtx_lock, PVFS, "dq_lock_internal", NULL); } dq->dq_lflags |= DQ_LLOCK; } @@ -262,7 +283,7 @@ qf_get(struct quotafile *qfp, int type) } if ( (qfp->qf_qflags & QTF_CLOSING) ) { qfp->qf_qflags |= QTF_WANTED; - msleep(&qfp->qf_qflags, quota_list_mtx_lock, PVFS, "qf_get", 0); + msleep(&qfp->qf_qflags, quota_list_mtx_lock, PVFS, "qf_get", NULL); } } if (qfp->qf_vp != NULLVP) @@ -280,7 +301,7 @@ qf_get(struct quotafile *qfp, int type) while ( (qfp->qf_qflags & QTF_OPENING) || qfp->qf_refcnt ) { qfp->qf_qflags |= QTF_WANTED; - msleep(&qfp->qf_qflags, quota_list_mtx_lock, PVFS, "qf_get", 0); + msleep(&qfp->qf_qflags, quota_list_mtx_lock, PVFS, "qf_get", NULL); } if (qfp->qf_vp == NULLVP) { qfp->qf_qflags &= ~QTF_CLOSING; @@ -388,9 +409,7 @@ dqfileinit(struct quotafile *qfp) * must be called with the quota file lock held */ int -dqfileopen(qfp, type) - struct quotafile *qfp; - int type; +dqfileopen(struct quotafile *qfp, int type) { struct dqfilehdr header; struct vfs_context context; @@ -399,7 +418,7 @@ dqfileopen(qfp, type) int error = 0; char uio_buf[ UIO_SIZEOF(1) ]; - context.vc_proc = current_proc(); + context.vc_thread = current_thread(); context.vc_ucred = qfp->qf_cred; /* Obtain the file size */ @@ -458,7 +477,7 @@ dqfileclose(struct quotafile *qfp, __unused int type) &uio_buf[0], sizeof(uio_buf)); uio_addiov(auio, CAST_USER_ADDR_T(&header), sizeof (header)); - context.vc_proc = current_proc(); + context.vc_thread = current_thread(); context.vc_ucred = qfp->qf_cred; if (VNOP_READ(qfp->qf_vp, auio, 0, &context) == 0) { @@ -475,11 +494,7 @@ dqfileclose(struct quotafile *qfp, __unused int type) * reading the information from the file if necessary. */ int -dqget(id, qfp, type, dqp) - u_long id; - struct quotafile *qfp; - register int type; - struct dquot **dqp; +dqget(u_long id, struct quotafile *qfp, int type, struct dquot **dqp) { struct dquot *dq; struct dquot *ndq = NULL; @@ -489,6 +504,11 @@ dqget(id, qfp, type, dqp) int error = 0; int listlockval = 0; + if (!dqisinitialized()) { + *dqp = NODQUOT; + return (EINVAL); + } + if ( id == 0 || qfp->qf_vp == NULLVP ) { *dqp = NODQUOT; return (EINVAL); @@ -545,13 +565,6 @@ relookup: TAILQ_REMOVE(&dqdirtylist, dq, dq_freelist); else TAILQ_REMOVE(&dqfreelist, dq, dq_freelist); - } else if (dq->dq_cnt == 0) { - /* We've overflowed */ - --dq->dq_cnt; - dq_unlock_internal(dq); - dq_list_unlock(); - *dqp = NODQUOT; - return (EINVAL); } dq_unlock_internal(dq); @@ -771,11 +784,7 @@ relookup: * one is inserted. The actual hash table index is returned. */ static int -dqlookup(qfp, id, dqb, index) - struct quotafile *qfp; - u_long id; - struct dqblk *dqb; - u_int32_t *index; +dqlookup(struct quotafile *qfp, u_long id, struct dqblk *dqb, uint32_t *index) { struct vnode *dqvp; struct vfs_context context; @@ -790,7 +799,7 @@ dqlookup(qfp, id, dqb, index) dqvp = qfp->qf_vp; - context.vc_proc = current_proc(); + context.vc_thread = current_thread(); context.vc_ucred = qfp->qf_cred; mask = qfp->qf_maxentries - 1; @@ -805,11 +814,11 @@ dqlookup(qfp, id, dqb, index) uio_addiov(auio, CAST_USER_ADDR_T(dqb), sizeof (struct dqblk)); error = VNOP_READ(dqvp, auio, 0, &context); if (error) { - printf("dqlookup: error %d looking up id %d at index %d\n", error, id, i); + printf("dqlookup: error %d looking up id %lu at index %d\n", error, id, i); break; } else if (uio_resid(auio)) { error = EIO; - printf("dqlookup: error looking up id %d at index %d\n", id, i); + printf("dqlookup: error looking up id %lu at index %d\n", id, i); break; } /* @@ -886,7 +895,7 @@ dqrele(struct dquot *dq) * Release a reference to a dquot but don't do any I/O. */ void -dqreclaim(register struct dquot *dq) +dqreclaim(struct dquot *dq) { if (dq == NODQUOT) @@ -913,25 +922,17 @@ dqreclaim(register struct dquot *dq) * Update a quota file's orphaned disk quotas. */ void -dqsync_orphans(qfp) - struct quotafile *qfp; +dqsync_orphans(struct quotafile *qfp) { struct dquot *dq; - int listlockval = 0; - + dq_list_lock(); loop: - listlockval = dq_list_lock_val(); - TAILQ_FOREACH(dq, &dqdirtylist, dq_freelist) { if (dq->dq_qfile != qfp) continue; dq_lock_internal(dq); - if (dq_list_lock_changed(listlockval)) { - dq_unlock_internal(dq); - goto loop; - } if (dq->dq_qfile != qfp) { /* @@ -998,7 +999,6 @@ dqsync(struct dquot *dq) int dqsync_locked(struct dquot *dq) { - struct proc *p = current_proc(); /* XXX */ struct vfs_context context; struct vnode *dqvp; struct dqblk dqb, *dqblkp; @@ -1019,7 +1019,7 @@ dqsync_locked(struct dquot *dq) UIO_WRITE, &uio_buf[0], sizeof(uio_buf)); uio_addiov(auio, CAST_USER_ADDR_T(&dqb), sizeof (struct dqblk)); - context.vc_proc = p; + context.vc_thread = current_thread(); /* XXX */ context.vc_ucred = dq->dq_qfile->qf_cred; dqblkp = &dq->dq_dqb; @@ -1049,12 +1049,14 @@ dqsync_locked(struct dquot *dq) * Flush all entries from the cache for a particular vnode. */ void -dqflush(vp) - register struct vnode *vp; +dqflush(struct vnode *vp) { - register struct dquot *dq, *nextdq; + struct dquot *dq, *nextdq; struct dqhash *dqh; + if (!dqisinitialized()) + return; + /* * Move all dquot's that used to refer to this quota * file off their hash chains (they will eventually