/*
- * 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@
*
/*
- * 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
*/
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;
{
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;
}
}
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)
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;
* 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;
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 */
&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) {
* 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;
int error = 0;
int listlockval = 0;
+ if (!dqisinitialized()) {
+ *dqp = NODQUOT;
+ return (EINVAL);
+ }
+
if ( id == 0 || qfp->qf_vp == NULLVP ) {
*dqp = NODQUOT;
return (EINVAL);
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);
* 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;
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;
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;
}
/*
* 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)
* 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) {
/*
int
dqsync_locked(struct dquot *dq)
{
- struct proc *p = current_proc(); /* XXX */
struct vfs_context context;
struct vnode *dqvp;
struct dqblk dqb, *dqblkp;
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;
* 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