All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Avati <avati-+FkPdpiNhgJBDgjK7y7TUQ@public.gmane.org>
To: <miklos-sUDqSbJrdHQHWmgEVkV9KA@public.gmane.org>
Cc: <fuse-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	<linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	<linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Anand Avati <avati-+FkPdpiNhgJBDgjK7y7TUQ@public.gmane.org>
Subject: [PATCH v2 2/2] fuse: permit O_DIRECT flag in open()
Date: Wed, 27 Jul 2011 03:56:19 -0700	[thread overview]
Message-ID: <1311764179-20326-2-git-send-email-avati@gluster.com> (raw)
In-Reply-To: <1311764179-20326-1-git-send-email-avati-+FkPdpiNhgJBDgjK7y7TUQ@public.gmane.org>

FUSE currently disallows O_DIRECT flag in open(). It is tricky dealing with
setting/unsetting of O_DIRECT flag on an open file. There are applications
(primarily VMs and databases) which open files with O_DIRECT flag. These
applications do not work on FUSE due to this limitation.

The approach with this patch is to permit opens with O_DIRECT, but instead
disable setting/unsetting of the O_DIRECT flag no matter how the file was
opened. This limitation is for more practical than disallowing O_DIRECT
altogether.

Signed-off-by: Anand Avati <avati-+FkPdpiNhgJBDgjK7y7TUQ@public.gmane.org>
---
 fs/fuse/file.c |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 82a6646..355c30f 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -154,6 +154,27 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
 		return err;
 	}
 
+	if (file->f_flags & O_DIRECT) {
+		if (!(outarg.open_flags & FOPEN_DIRECT_IO)) {
+			/* filesystem process did not acknowledge the O_DIRECT
+			   flag with FOPEN_DIRECT_IO bit in ourarg. Hence
+			   we fail the open().
+
+			   Notify the filesystem process about the failed
+			   open with fuse_sync_release right here itself as
+			   file->private_data is not yet set up for release
+			   notification.
+			*/
+			fuse_sync_release(ff, file->f_flags);
+			return -EINVAL;
+		}
+
+		/* make VFS believe we don't support O_DIRECT till we
+		   implement a_ops->direct_IO
+		*/
+		file->f_flags &= ~O_DIRECT;
+	}
+
 	if (isdir)
 		outarg.open_flags &= ~FOPEN_DIRECT_IO;
 
@@ -193,10 +214,6 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
 	struct fuse_conn *fc = get_fuse_conn(inode);
 	int err;
 
-	/* VFS checks this, but only _after_ ->open() */
-	if (file->f_flags & O_DIRECT)
-		return -EINVAL;
-
 	err = generic_file_open(inode, file);
 	if (err)
 		return err;
@@ -2132,6 +2149,15 @@ int fuse_notify_poll_wakeup(struct fuse_conn *fc,
 	return 0;
 }
 
+
+static int fuse_check_flags(struct file *filp, int flags)
+{
+	if ((filp->f_flags ^ flags) & O_DIRECT)
+		return -EINVAL;
+	return 0;
+}
+
+
 static const struct file_operations fuse_file_operations = {
 	.llseek		= fuse_file_llseek,
 	.read		= do_sync_read,
@@ -2149,6 +2175,7 @@ static const struct file_operations fuse_file_operations = {
 	.unlocked_ioctl	= fuse_file_ioctl,
 	.compat_ioctl	= fuse_file_compat_ioctl,
 	.poll		= fuse_file_poll,
+	.check_flags	= fuse_check_flags,
 };
 
 static const struct file_operations fuse_direct_io_file_operations = {
@@ -2165,6 +2192,7 @@ static const struct file_operations fuse_direct_io_file_operations = {
 	.unlocked_ioctl	= fuse_file_ioctl,
 	.compat_ioctl	= fuse_file_compat_ioctl,
 	.poll		= fuse_file_poll,
+	.check_flags	= fuse_check_flags,
 	/* no splice_read */
 };
 
-- 
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Anand Avati <avati@gluster.com>
To: <miklos@szeredi.hu>
Cc: <fuse-devel@lists.sourceforge.net>,
	<linux-fsdevel@vger.kernel.org>, <linux-nfs@vger.kernel.org>,
	Anand Avati <avati@gluster.com>
Subject: [PATCH v2 2/2] fuse: permit O_DIRECT flag in open()
Date: Wed, 27 Jul 2011 03:56:19 -0700	[thread overview]
Message-ID: <1311764179-20326-2-git-send-email-avati@gluster.com> (raw)
In-Reply-To: <1311764179-20326-1-git-send-email-avati@gluster.com>

FUSE currently disallows O_DIRECT flag in open(). It is tricky dealing with
setting/unsetting of O_DIRECT flag on an open file. There are applications
(primarily VMs and databases) which open files with O_DIRECT flag. These
applications do not work on FUSE due to this limitation.

The approach with this patch is to permit opens with O_DIRECT, but instead
disable setting/unsetting of the O_DIRECT flag no matter how the file was
opened. This limitation is for more practical than disallowing O_DIRECT
altogether.

Signed-off-by: Anand Avati <avati@gluster.com>
---
 fs/fuse/file.c |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 82a6646..355c30f 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -154,6 +154,27 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
 		return err;
 	}
 
+	if (file->f_flags & O_DIRECT) {
+		if (!(outarg.open_flags & FOPEN_DIRECT_IO)) {
+			/* filesystem process did not acknowledge the O_DIRECT
+			   flag with FOPEN_DIRECT_IO bit in ourarg. Hence
+			   we fail the open().
+
+			   Notify the filesystem process about the failed
+			   open with fuse_sync_release right here itself as
+			   file->private_data is not yet set up for release
+			   notification.
+			*/
+			fuse_sync_release(ff, file->f_flags);
+			return -EINVAL;
+		}
+
+		/* make VFS believe we don't support O_DIRECT till we
+		   implement a_ops->direct_IO
+		*/
+		file->f_flags &= ~O_DIRECT;
+	}
+
 	if (isdir)
 		outarg.open_flags &= ~FOPEN_DIRECT_IO;
 
@@ -193,10 +214,6 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
 	struct fuse_conn *fc = get_fuse_conn(inode);
 	int err;
 
-	/* VFS checks this, but only _after_ ->open() */
-	if (file->f_flags & O_DIRECT)
-		return -EINVAL;
-
 	err = generic_file_open(inode, file);
 	if (err)
 		return err;
@@ -2132,6 +2149,15 @@ int fuse_notify_poll_wakeup(struct fuse_conn *fc,
 	return 0;
 }
 
+
+static int fuse_check_flags(struct file *filp, int flags)
+{
+	if ((filp->f_flags ^ flags) & O_DIRECT)
+		return -EINVAL;
+	return 0;
+}
+
+
 static const struct file_operations fuse_file_operations = {
 	.llseek		= fuse_file_llseek,
 	.read		= do_sync_read,
@@ -2149,6 +2175,7 @@ static const struct file_operations fuse_file_operations = {
 	.unlocked_ioctl	= fuse_file_ioctl,
 	.compat_ioctl	= fuse_file_compat_ioctl,
 	.poll		= fuse_file_poll,
+	.check_flags	= fuse_check_flags,
 };
 
 static const struct file_operations fuse_direct_io_file_operations = {
@@ -2165,6 +2192,7 @@ static const struct file_operations fuse_direct_io_file_operations = {
 	.unlocked_ioctl	= fuse_file_ioctl,
 	.compat_ioctl	= fuse_file_compat_ioctl,
 	.poll		= fuse_file_poll,
+	.check_flags	= fuse_check_flags,
 	/* no splice_read */
 };
 
-- 
1.7.4.4


  parent reply	other threads:[~2011-07-27 10:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-27 10:56 [PATCH v2 1/2] vfs: pass 'struct file *' as parameter to ->check_flags() methods Anand Avati
2011-07-27 10:56 ` Anand Avati
     [not found] ` <1311764179-20326-1-git-send-email-avati-+FkPdpiNhgJBDgjK7y7TUQ@public.gmane.org>
2011-07-27 10:56   ` Anand Avati [this message]
2011-07-27 10:56     ` [PATCH v2 2/2] fuse: permit O_DIRECT flag in open() Anand Avati
2011-07-27 21:05     ` Christoph Hellwig
2011-07-28  8:14       ` Anand Avati
2011-07-28 11:49         ` Christoph Hellwig
2011-07-28 18:12           ` Anand Avati

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311764179-20326-2-git-send-email-avati@gluster.com \
    --to=avati-+fkpdpinhgjbdgjk7y7tuq@public.gmane.org \
    --cc=fuse-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=miklos-sUDqSbJrdHQHWmgEVkV9KA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.