From owner-svn-src-stable-10@freebsd.org Thu Sep 22 10:44:57 2016 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B7518BE49DB; Thu, 22 Sep 2016 10:44:57 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6E20A1E47; Thu, 22 Sep 2016 10:44:57 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8MAiuLg054172; Thu, 22 Sep 2016 10:44:56 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8MAiuAq054171; Thu, 22 Sep 2016 10:44:56 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201609221044.u8MAiuAq054171@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 22 Sep 2016 10:44:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r306176 - stable/10/sys/ufs/ufs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2016 10:44:57 -0000 Author: kib Date: Thu Sep 22 10:44:56 2016 New Revision: 306176 URL: https://svnweb.freebsd.org/changeset/base/306176 Log: MFC r305593: There is no need to upgrade the last dvp lock on lookups for modifying operations. Instead of upgrading, assert that the lock is exclusive. Explain the cause in comments. Modified: stable/10/sys/ufs/ufs/ufs_lookup.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/ufs/ufs/ufs_lookup.c ============================================================================== --- stable/10/sys/ufs/ufs/ufs_lookup.c Thu Sep 22 10:42:40 2016 (r306175) +++ stable/10/sys/ufs/ufs/ufs_lookup.c Thu Sep 22 10:44:56 2016 (r306176) @@ -76,32 +76,6 @@ SYSCTL_INT(_debug, OID_AUTO, dircheck, C /* true if old FS format...*/ #define OFSFMT(vp) ((vp)->v_mount->mnt_maxsymlinklen <= 0) -#ifdef QUOTA -static int -ufs_lookup_upgrade_lock(struct vnode *vp) -{ - int error; - - ASSERT_VOP_LOCKED(vp, __FUNCTION__); - if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) - return (0); - - error = 0; - - /* - * Upgrade vnode lock, since getinoquota() - * requires exclusive lock to modify inode. - */ - vhold(vp); - vn_lock(vp, LK_UPGRADE | LK_RETRY); - VI_LOCK(vp); - if (vp->v_iflag & VI_DOOMED) - error = ENOENT; - vdropl(vp); - return (error); -} -#endif - static int ufs_delete_denied(struct vnode *vdp, struct vnode *tdp, struct ucred *cred, struct thread *td) @@ -259,12 +233,25 @@ ufs_lookup_ino(struct vnode *vdp, struct vnode_create_vobject(vdp, DIP(dp, i_size), cnp->cn_thread); bmask = VFSTOUFS(vdp->v_mount)->um_mountp->mnt_stat.f_iosize - 1; -#ifdef QUOTA - if ((nameiop == DELETE || nameiop == RENAME) && (flags & ISLASTCN)) { - error = ufs_lookup_upgrade_lock(vdp); - if (error != 0) - return (error); - } + +#ifdef DEBUG_VFS_LOCKS + /* + * Assert that the directory vnode is locked, and locked + * exclusively for the last component lookup for modifying + * operations. + * + * The directory-modifying operations need to save + * intermediate state in the inode between namei() call and + * actual directory manipulations. See fields in the struct + * inode marked as 'used during directory lookup'. We must + * ensure that upgrade in namei() does not happen, since + * upgrade might need to unlock vdp. If quotas are enabled, + * getinoquota() also requires exclusive lock to modify inode. + */ + ASSERT_VOP_LOCKED(vdp, "ufs_lookup1"); + if ((nameiop == CREATE || nameiop == DELETE || nameiop == RENAME) && + (flags & (LOCKPARENT | ISLASTCN)) == (LOCKPARENT | ISLASTCN)) + ASSERT_VOP_ELOCKED(vdp, "ufs_lookup2"); #endif restart: