From owner-freebsd-fs@freebsd.org Mon Dec 28 17:15:41 2015 Return-Path: Delivered-To: freebsd-fs@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 3094EA53B2A for ; Mon, 28 Dec 2015 17:15:41 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from esa-jnhn.mail.uoguelph.ca (esa-jnhn.mail.uoguelph.ca [131.104.91.44]) by mx1.freebsd.org (Postfix) with ESMTP id BE4C11AF4 for ; Mon, 28 Dec 2015 17:15:40 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) IronPort-PHdr: 9a23:QMW5JRLPmeDSnFEiRdmcpTZWNBhigK39O0sv0rFitYgULvTxwZ3uMQTl6Ol3ixeRBMOAu6wC07KempujcFJDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXsq3G/pQQfBg/4fVIsYL+lRMiK14ye7KObxd76W01wnj2zYLd/fl2djD76kY0ou7ZkMbs70RDTo3FFKKx8zGJsIk+PzV6nvp/jtM0rzyMFtegs+sRbXeD0ZOxsQ6ZVAT49PyU7/+XlrxTORxCDoHwGXTNFvABPBl3/7Rr5FrL4uSj+u+81jDOfNMb1Sb0xcSml4LpmTAfoziwOYW1quFrLg9B92foI6CmqoAZyltbZ X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CsBAB4bIFW/61jaINehAxtBohTtlYahXWBWhABAQEBAQEBAYEJgi2CDiNoASICDRkCWwQuiBSaOY9vkSkMIYEBhVWGO4JqEQGDO4FJBY4wiFaFQIlth26FMRSOJAI5K4IeggogNIM3OoEIAQEB X-IronPort-AV: E=Sophos;i="5.20,491,1444708800"; d="scan'208";a="258603905" Received: from nipigon.cs.uoguelph.ca (HELO zcs1.mail.uoguelph.ca) ([131.104.99.173]) by esa-jnhn.mail.uoguelph.ca with ESMTP; 28 Dec 2015 12:14:31 -0500 Received: from localhost (localhost [127.0.0.1]) by zcs1.mail.uoguelph.ca (Postfix) with ESMTP id 3246D15F55D for ; Mon, 28 Dec 2015 12:14:31 -0500 (EST) Received: from zcs1.mail.uoguelph.ca ([127.0.0.1]) by localhost (zcs1.mail.uoguelph.ca [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id NkLh8aZ7AVDi for ; Mon, 28 Dec 2015 12:14:30 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by zcs1.mail.uoguelph.ca (Postfix) with ESMTP id 9A08A15F565 for ; Mon, 28 Dec 2015 12:14:30 -0500 (EST) X-Virus-Scanned: amavisd-new at zcs1.mail.uoguelph.ca Received: from zcs1.mail.uoguelph.ca ([127.0.0.1]) by localhost (zcs1.mail.uoguelph.ca [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id a9nFcZsPnvaW for ; Mon, 28 Dec 2015 12:14:30 -0500 (EST) Received: from zcs1.mail.uoguelph.ca (zcs1.mail.uoguelph.ca [172.17.95.18]) by zcs1.mail.uoguelph.ca (Postfix) with ESMTP id 802CA15F55D for ; Mon, 28 Dec 2015 12:14:30 -0500 (EST) Date: Mon, 28 Dec 2015 12:14:30 -0500 (EST) From: Rick Macklem To: freebsd-fs Message-ID: <1044566436.145078070.1451322870420.JavaMail.zimbra@uoguelph.ca> Subject: fixing a Fuse bug when writing (PR#194293?) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [172.17.95.12] X-Mailer: Zimbra 8.0.9_GA_6191 (ZimbraWebClient - FF43 (Win)/8.0.9_GA_6191) Thread-Topic: fixing a Fuse bug when writing (PR#194293?) Thread-Index: 3l+My+eJ1EgHujqSUyq3l26tfcVQZg== X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Dec 2015 17:15:41 -0000 Hi, I sent a rather long email to a few people, but forgot to cc freebsd-fs@. Here's a shorter version: - When a file on a Fuse mounted fs is opened WRONLY and a partial block is written (when using the buffer cache, not DIRECT_IO), it gets wedged because the buffer cache code attempts to read in the whole block and the read isn't allowed. (I can reproduce this using GlusterFS and I think PR#194293 might be the same problem.) I can think of two ways to fix this: 1 - Make any WRONLY open actually do a RDWR open. The patch at the end of the email does that and fixes the problem for my test case. XXX - I think the problem is that if a process has write but not read access for the file, this RDWR open will fail and that won't make much sense, since it has write access. 2 - Make Fuse always do DIRECT_IO when a file is opened WRONLY. (This seems to happen for GlusterFS, since it seems to always set FOPEN_DIRECT_IO in the Fuse reply to the open for WRONLY, but I suspect other Fuse filesystems don't do this? I reproduced the problem by hacking the code to ignore the FOPEN_DIRECT_IO in the reply for GlusterFS.) I have coded #1 but not #2. However I am now thinking #2 is the better solution, given (XXX) above. Any other ideas or opinions w.r.t. how to fix this? Thanks, rick ps: Here's the patch I came up with for #1: --- fs/fuse/fuse_file.h.xxx 2015-12-27 16:02:53.241174000 -0500 +++ fs/fuse/fuse_file.h 2015-12-27 15:25:01.865156000 -0500 @@ -101,6 +101,9 @@ fuse_filehandle_xlate_from_fflags(int ff if ((fflags & FREAD) && (fflags & FWRITE)) { return FUFH_RDWR; } else if (fflags & (FWRITE)) { + /* See comment in fuse_vnop_open() w.r.t. why FUFH_RDWR is needed. */ + if (datacache != 0) + return FUFH_RDWR; return FUFH_WRONLY; } else if (fflags & (FREAD)) { return FUFH_RDONLY; --- fs/fuse/fuse_vnops.c.sav 2015-12-16 16:24:43.577000000 -0500 +++ fs/fuse/fuse_vnops.c 2015-12-27 16:07:06.683806000 -0500 @@ -276,7 +276,8 @@ fuse_vnop_close(struct vop_close_args *a if (fflag & IO_NDELAY) { return 0; } - fufh_type = fuse_filehandle_xlate_from_fflags(fflag); + fufh_type = fuse_filehandle_xlate_from_fflags(fflag, + fsess_opt_datacache(vnode_mount(vp))); if (!fuse_filehandle_valid(vp, fufh_type)) { int i; @@ -1139,7 +1140,8 @@ fuse_vnop_open(struct vop_open_args *ap) if (isdir) { fufh_type = FUFH_RDONLY; } else { - fufh_type = fuse_filehandle_xlate_from_fflags(mode); + fufh_type = fuse_filehandle_xlate_from_fflags(mode, + fsess_opt_datacache(vnode_mount(vp))); } if (fuse_filehandle_valid(vp, fufh_type)) {