From owner-svn-src-all@freebsd.org Sun May 15 23:15:12 2016 Return-Path: Delivered-To: svn-src-all@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 0A7DFB3C556; Sun, 15 May 2016 23:15:12 +0000 (UTC) (envelope-from rmacklem@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 C112B1CD2; Sun, 15 May 2016 23:15:11 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4FNFAwG027132; Sun, 15 May 2016 23:15:10 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4FNFA1B027129; Sun, 15 May 2016 23:15:10 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201605152315.u4FNFA1B027129@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sun, 15 May 2016 23:15:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299872 - head/sys/fs/fuse X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 May 2016 23:15:12 -0000 Author: rmacklem Date: Sun May 15 23:15:10 2016 New Revision: 299872 URL: https://svnweb.freebsd.org/changeset/base/299872 Log: Fix fuse for "cp" of a mode 0444 file to the file system. When "cp" of a file with read-only (mode 0444) to a fuse mounted file system was attempted it would fail with EACCES. This was because fuse would attempt to open the file WRONLY and the open would fail. This patch changes the fuse_vnop_open() to test for an extant read-write open and use that, if it is available. This makes the "cp" of a read-only file to the fuse mounted file system work ok. There are simpler ways to fix this than adding the fuse_filehandle_validrw() function, but this function is useful for future patches related to exporting a fuse filesystem via NFS. MFC after: 2 weeks Modified: head/sys/fs/fuse/fuse_file.c head/sys/fs/fuse/fuse_file.h head/sys/fs/fuse/fuse_vnops.c Modified: head/sys/fs/fuse/fuse_file.c ============================================================================== --- head/sys/fs/fuse/fuse_file.c Sun May 15 22:36:55 2016 (r299871) +++ head/sys/fs/fuse/fuse_file.c Sun May 15 23:15:10 2016 (r299872) @@ -216,6 +216,28 @@ fuse_filehandle_valid(struct vnode *vp, return FUFH_IS_VALID(fufh); } +/* + * Check for a valid file handle, first the type requested, but if that + * isn't valid, try for FUFH_RDWR. + * Return the FUFH type that is valid or FUFH_INVALID if there are none. + * This is a variant of fuse_filehandle_vaild() analogous to + * fuse_filehandle_getrw(). + */ +fufh_type_t +fuse_filehandle_validrw(struct vnode *vp, fufh_type_t fufh_type) +{ + struct fuse_vnode_data *fvdat = VTOFUD(vp); + struct fuse_filehandle *fufh; + + fufh = &fvdat->fufh[fufh_type]; + if (FUFH_IS_VALID(fufh) != 0) + return (fufh_type); + fufh = &fvdat->fufh[FUFH_RDWR]; + if (FUFH_IS_VALID(fufh) != 0) + return (FUFH_RDWR); + return (FUFH_INVALID); +} + int fuse_filehandle_get(struct vnode *vp, fufh_type_t fufh_type, struct fuse_filehandle **fufhp) Modified: head/sys/fs/fuse/fuse_file.h ============================================================================== --- head/sys/fs/fuse/fuse_file.h Sun May 15 22:36:55 2016 (r299871) +++ head/sys/fs/fuse/fuse_file.h Sun May 15 23:15:10 2016 (r299872) @@ -137,6 +137,7 @@ fuse_filehandle_xlate_to_oflags(fufh_typ } int fuse_filehandle_valid(struct vnode *vp, fufh_type_t fufh_type); +fufh_type_t fuse_filehandle_validrw(struct vnode *vp, fufh_type_t fufh_type); int fuse_filehandle_get(struct vnode *vp, fufh_type_t fufh_type, struct fuse_filehandle **fufhp); int fuse_filehandle_getrw(struct vnode *vp, fufh_type_t fufh_type, Modified: head/sys/fs/fuse/fuse_vnops.c ============================================================================== --- head/sys/fs/fuse/fuse_vnops.c Sun May 15 22:36:55 2016 (r299871) +++ head/sys/fs/fuse/fuse_vnops.c Sun May 15 23:15:10 2016 (r299872) @@ -1153,7 +1153,7 @@ fuse_vnop_open(struct vop_open_args *ap) fuse_open_flags = FOPEN_DIRECT_IO; } - if (fuse_filehandle_valid(vp, fufh_type)) { + if (fuse_filehandle_validrw(vp, fufh_type) != FUFH_INVALID) { fuse_vnode_open(vp, fuse_open_flags, td); return 0; }