From owner-svn-src-stable@freebsd.org Sat May 28 22:42:58 2016 Return-Path: Delivered-To: svn-src-stable@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 64DF9B4E659; Sat, 28 May 2016 22:42:58 +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 08D5914EF; Sat, 28 May 2016 22:42:57 +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 u4SMgvh4031397; Sat, 28 May 2016 22:42:57 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4SMgvph031395; Sat, 28 May 2016 22:42:57 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201605282242.u4SMgvph031395@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sat, 28 May 2016 22:42:57 +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: r300916 - stable/10/sys/fs/fuse 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@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2016 22:42:58 -0000 Author: rmacklem Date: Sat May 28 22:42:56 2016 New Revision: 300916 URL: https://svnweb.freebsd.org/changeset/base/300916 Log: MFC: r299753 Fix fuse to use DIRECT_IO when required. When a file is opened write-only and a partial block was written, buffered I/O would try and read the whole block in. This would result in a hung thread, since there was no open (fuse filehandle) that allowed reading. This patch avoids the problem by forcing DIRECT_IO for this case. It also sets DIRECT_IO when the file system specifies the FN_DIRECTIO flag in its reply to the open. Modified: stable/10/sys/fs/fuse/fuse_file.c stable/10/sys/fs/fuse/fuse_vnops.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/fuse/fuse_file.c ============================================================================== --- stable/10/sys/fs/fuse/fuse_file.c Sat May 28 22:27:54 2016 (r300915) +++ stable/10/sys/fs/fuse/fuse_file.c Sat May 28 22:42:56 2016 (r300916) @@ -141,7 +141,17 @@ fuse_filehandle_open(struct vnode *vp, foo = fdi.answ; fuse_filehandle_init(vp, fufh_type, fufhp, foo->fh); - fuse_vnode_open(vp, foo->open_flags, td); + + /* + * For WRONLY opens, force DIRECT_IO. This is necessary + * since writing a partial block through the buffer cache + * will result in a read of the block and that read won't + * be allowed by the WRONLY open. + */ + if (fufh_type == FUFH_WRONLY) + fuse_vnode_open(vp, foo->open_flags | FOPEN_DIRECT_IO, td); + else + fuse_vnode_open(vp, foo->open_flags, td); out: fdisp_destroy(&fdi); Modified: stable/10/sys/fs/fuse/fuse_vnops.c ============================================================================== --- stable/10/sys/fs/fuse/fuse_vnops.c Sat May 28 22:27:54 2016 (r300915) +++ stable/10/sys/fs/fuse/fuse_vnops.c Sat May 28 22:42:56 2016 (r300916) @@ -1125,6 +1125,7 @@ fuse_vnop_open(struct vop_open_args *ap) struct fuse_vnode_data *fvdat; int error, isdir = 0; + int32_t fuse_open_flags; FS_DEBUG2G("inode=%ju mode=0x%x\n", (uintmax_t)VTOI(vp), mode); @@ -1136,14 +1137,24 @@ fuse_vnop_open(struct vop_open_args *ap) if (vnode_isdir(vp)) { isdir = 1; } + fuse_open_flags = 0; if (isdir) { fufh_type = FUFH_RDONLY; } else { fufh_type = fuse_filehandle_xlate_from_fflags(mode); + /* + * For WRONLY opens, force DIRECT_IO. This is necessary + * since writing a partial block through the buffer cache + * will result in a read of the block and that read won't + * be allowed by the WRONLY open. + */ + if (fufh_type == FUFH_WRONLY || + (fvdat->flag & FN_DIRECTIO) != 0) + fuse_open_flags = FOPEN_DIRECT_IO; } if (fuse_filehandle_valid(vp, fufh_type)) { - fuse_vnode_open(vp, 0, td); + fuse_vnode_open(vp, fuse_open_flags, td); return 0; } error = fuse_filehandle_open(vp, fufh_type, NULL, td, cred);