Ejemplo n.º 1
0
/*
 * Main code to turn off disk quotas for a filesystem. Does not change
 * flags.
 */
static int
quotaoff1(struct thread *td, struct mount *mp, int type)
{
    struct vnode *vp;
    struct vnode *qvp, *mvp;
    struct ufsmount *ump;
    struct dquot *dq;
    struct inode *ip;
    struct ucred *cr;
    int error;

    ump = VFSTOUFS(mp);

    UFS_LOCK(ump);
    KASSERT((ump->um_qflags[type] & QTF_CLOSING) != 0,
            ("quotaoff1: flags are invalid"));
    if ((qvp = ump->um_quotas[type]) == NULLVP) {
        UFS_UNLOCK(ump);
        return (0);
    }
    cr = ump->um_cred[type];
    UFS_UNLOCK(ump);

    /*
     * Search vnodes associated with this mount point,
     * deleting any references to quota file being closed.
     */
again:
    MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
        if (vp->v_type == VNON) {
            VI_UNLOCK(vp);
            continue;
        }
        if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td)) {
            MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
            goto again;
        }
        ip = VTOI(vp);
        dq = ip->i_dquot[type];
        ip->i_dquot[type] = NODQUOT;
        dqrele(vp, dq);
        VOP_UNLOCK(vp, 0);
        vrele(vp);
    }

    error = dqflush(qvp);
    if (error != 0)
        return (error);

    /*
     * Clear um_quotas before closing the quota vnode to prevent
     * access to the closed vnode from dqget/dqsync
     */
    UFS_LOCK(ump);
    ump->um_quotas[type] = NULLVP;
    ump->um_cred[type] = NOCRED;
    UFS_UNLOCK(ump);

    vn_lock(qvp, LK_EXCLUSIVE | LK_RETRY);
    qvp->v_vflag &= ~VV_SYSTEM;
    VOP_UNLOCK(qvp, 0);
    error = vn_close(qvp, FREAD|FWRITE, td->td_ucred, td);
    crfree(cr);

    return (error);
}
Ejemplo n.º 2
0
/*
 * Q_QUOTAOFF - turn off disk quotas for a filesystem.
 */
int
quotaoff(struct lwp *l, struct mount *mp, int type)
{
	struct vnode *vp;
	struct vnode *qvp, *mvp;
	struct ufsmount *ump = VFSTOUFS(mp);
	struct dquot *dq;
	struct inode *ip;
	kauth_cred_t cred;
	int i, error;

	/* Allocate a marker vnode. */
	if ((mvp = vnalloc(mp)) == NULL)
		return ENOMEM;

	mutex_enter(&dqlock);
	while ((ump->um_qflags[type] & (QTF_CLOSING | QTF_OPENING)) != 0)
		cv_wait(&dqcv, &dqlock);
	if ((qvp = ump->um_quotas[type]) == NULLVP) {
		mutex_exit(&dqlock);
		vnfree(mvp);
		return (0);
	}
	ump->um_qflags[type] |= QTF_CLOSING;
	mutex_exit(&dqlock);
	/*
	 * Search vnodes associated with this mount point,
	 * deleting any references to quota file being closed.
	 */
	mutex_enter(&mntvnode_lock);
again:
	for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) {
		vmark(mvp, vp);
		mutex_enter(&vp->v_interlock);
		if (VTOI(vp) == NULL || vp->v_mount != mp || vismarker(vp) ||
		    vp->v_type == VNON ||
		    (vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0) {
			mutex_exit(&vp->v_interlock);
			continue;
		}
		mutex_exit(&mntvnode_lock);
		if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK)) {
			mutex_enter(&mntvnode_lock);
			(void)vunmark(mvp);
			goto again;
		}
		ip = VTOI(vp);
		dq = ip->i_dquot[type];
		ip->i_dquot[type] = NODQUOT;
		dqrele(vp, dq);
		vput(vp);
		mutex_enter(&mntvnode_lock);
	}
	mutex_exit(&mntvnode_lock);
#ifdef DIAGNOSTIC
	dqflush(qvp);
#endif
	qvp->v_vflag &= ~VV_SYSTEM;
	error = vn_close(qvp, FREAD|FWRITE, l->l_cred);
	mutex_enter(&dqlock);
	ump->um_quotas[type] = NULLVP;
	cred = ump->um_cred[type];
	ump->um_cred[type] = NOCRED;
	for (i = 0; i < MAXQUOTAS; i++)
		if (ump->um_quotas[i] != NULLVP)
			break;
	ump->um_qflags[type] &= ~QTF_CLOSING;
	cv_broadcast(&dqcv);
	mutex_exit(&dqlock);
	kauth_cred_free(cred);
	if (i == MAXQUOTAS)
		mp->mnt_flag &= ~MNT_QUOTA;
	return (error);
}