From owner-svn-src-stable-11@freebsd.org Thu Feb 23 09:41:34 2017 Return-Path: Delivered-To: svn-src-stable-11@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 6E3E7CE815B; Thu, 23 Feb 2017 09:41:34 +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 2C6EFE25; Thu, 23 Feb 2017 09:41:34 +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 v1N9fXKT078828; Thu, 23 Feb 2017 09:41:33 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1N9fXFO078826; Thu, 23 Feb 2017 09:41:33 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201702230941.v1N9fXFO078826@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 23 Feb 2017 09:41:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r314134 - in stable/11/sys: kern sys X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Feb 2017 09:41:34 -0000 Author: kib Date: Thu Feb 23 09:41:32 2017 New Revision: 314134 URL: https://svnweb.freebsd.org/changeset/base/314134 Log: MFC r313495: Do not establish advisory locks when doing open(O_EXLOCK) or open(O_SHLOCK) for files which do not have DTYPE_VNODE type. MFC r313549: Fix r313495. Modified: stable/11/sys/kern/vfs_vnops.c stable/11/sys/sys/file.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/vfs_vnops.c ============================================================================== --- stable/11/sys/kern/vfs_vnops.c Thu Feb 23 09:30:37 2017 (r314133) +++ stable/11/sys/kern/vfs_vnops.c Thu Feb 23 09:41:32 2017 (r314134) @@ -349,8 +349,12 @@ vn_open_vnode(struct vnode *vp, int fmod if ((error = VOP_OPEN(vp, fmode, cred, td, fp)) != 0) return (error); - if (fmode & (O_EXLOCK | O_SHLOCK)) { + while ((fmode & (O_EXLOCK | O_SHLOCK)) != 0) { KASSERT(fp != NULL, ("open with flock requires fp")); + if (fp->f_type != DTYPE_NONE && fp->f_type != DTYPE_VNODE) { + error = EOPNOTSUPP; + break; + } lock_flags = VOP_ISLOCKED(vp); VOP_UNLOCK(vp, 0); lf.l_whence = SEEK_SET; @@ -367,8 +371,12 @@ vn_open_vnode(struct vnode *vp, int fmod if (error == 0) fp->f_flag |= FHASLOCK; vn_lock(vp, lock_flags | LK_RETRY); - if (error == 0 && vp->v_iflag & VI_DOOMED) + if (error != 0) + break; + if ((vp->v_iflag & VI_DOOMED) != 0) { error = ENOENT; + break; + } /* * Another thread might have used this vnode as an @@ -376,20 +384,20 @@ vn_open_vnode(struct vnode *vp, int fmod * Ensure the vnode is still able to be opened for * writing after the lock has been obtained. */ - if (error == 0 && accmode & VWRITE) + if ((accmode & VWRITE) != 0) error = vn_writechk(vp); + break; + } - if (error != 0) { - fp->f_flag |= FOPENFAILED; - fp->f_vnode = vp; - if (fp->f_ops == &badfileops) { - fp->f_type = DTYPE_VNODE; - fp->f_ops = &vnops; - } - vref(vp); + if (error != 0) { + fp->f_flag |= FOPENFAILED; + fp->f_vnode = vp; + if (fp->f_ops == &badfileops) { + fp->f_type = DTYPE_VNODE; + fp->f_ops = &vnops; } - } - if (error == 0 && fmode & FWRITE) { + vref(vp); + } else if ((fmode & FWRITE) != 0) { VOP_ADD_WRITECOUNT(vp, 1); CTR3(KTR_VFS, "%s: vp %p v_writecount increased to %d", __func__, vp, vp->v_writecount); Modified: stable/11/sys/sys/file.h ============================================================================== --- stable/11/sys/sys/file.h Thu Feb 23 09:30:37 2017 (r314133) +++ stable/11/sys/sys/file.h Thu Feb 23 09:41:32 2017 (r314134) @@ -55,6 +55,7 @@ struct socket; #endif /* _KERNEL */ +#define DTYPE_NONE 0 /* not yet initialized */ #define DTYPE_VNODE 1 /* file */ #define DTYPE_SOCKET 2 /* communications endpoint */ #define DTYPE_PIPE 3 /* pipe */