Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Apr 2016 19:26:27 -0400 (EDT)
From:      Rick Macklem <rmacklem@uoguelph.ca>
To:        freebsd-fs <freebsd-fs@freebsd.org>
Subject:   review of 2 fuse patches
Message-ID:  <738276500.82484810.1461885987214.JavaMail.zimbra@uoguelph.ca>
In-Reply-To: <683515500.82484581.1461885974792.JavaMail.zimbra@uoguelph.ca>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
Hi,

I've attached two small patches for fuse. (They both are
in PR#206238.)
Is anyone willing to review these?

fuse-wronly.patch - Fixes a problem where the fuse interface has
    a file opened write-only and a write of a partial buffer cache
    block is done. At that point, the buffer cache code tries to
    read the block in and this fails, since the file isn't opened
    for reading. (The thread basically gets hung in the buffer cache
    code retrying the read over and over...)
    I could see two fixes for this:
    1 - Always open files read-write when write-only opens are specified.
        (The problem with this is that a user might have write, but not
         read access to the file.)
    2 - When files are opened write-only, force DirectIO, so that the
        buffer cache isn't used.
    *** This patch implements #2.

fuse-createio.patch - This simple patch fixes the code so that it
    obeys the fuse file system's request that an open/create uses
    DirectIO. (Without this patch, fuse ignores the flag in the file
    system's reply and does buffered I/O.) This is apparently needed
    by MooseFS. (This patch assumes that fuse-wronly.patch has already
    been applied.)

Thanks in advance for any review, rick
ps: If you want these in phabricator, let me know. However they seem
    pretty straightforward, except for "how to fix the first problem?".

[-- Attachment #2 --]
--- fs/fuse/fuse_vnops.c.sav5	2016-01-15 17:14:44.105194000 -0500
+++ fs/fuse/fuse_vnops.c	2016-01-15 17:14:49.723799000 -0500
@@ -1158,7 +1158,8 @@ fuse_vnop_open(struct vop_open_args *ap)
 		fufh_type = FUFH_RDONLY;
 	} else {
 		fufh_type = fuse_filehandle_xlate_from_fflags(mode);
-		if (fufh_type == FUFH_WRONLY)
+		if (fufh_type == FUFH_WRONLY ||
+		    (fvdat->flag & FN_DIRECTIO) != 0)
 			fuse_open_flags = FOPEN_DIRECT_IO;
 	}
 

[-- Attachment #3 --]
--- fs/fuse/fuse_file.c.xxx	2015-12-28 10:42:26.917855000 -0500
+++ fs/fuse/fuse_file.c	2015-12-28 11:46:56.909454000 -0500
@@ -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);
--- fs/fuse/fuse_vnops.c.xxx	2015-12-28 10:36:23.289297000 -0500
+++ fs/fuse/fuse_vnops.c	2015-12-28 10:42:06.264737000 -0500
@@ -1139,6 +1139,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);
 
@@ -1150,14 +1151,23 @@ 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)
+			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);
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?738276500.82484810.1461885987214.JavaMail.zimbra>