linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fabian Frederick <fabf@skynet.be>
To: tytso@mit.edu, Jan Kara <jack@suse.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	fabf@skynet.be
Subject: [PATCH 1/1 linux-next] ext4: add compatibility flag check
Date: Thu, 24 Nov 2016 20:47:41 +0100	[thread overview]
Message-ID: <1480016861-24432-1-git-send-email-fabf@skynet.be> (raw)

data=journal mount option should disable O_DIRECT access
(See Documentation/filesystems/ext4.txt) but open operations
using O_CREAT|O_RDWR|O_DIRECT|O_SYNC have no warning in return and file is being
created. This patch adds vfs super_operations compatibility flag function
returning -EPERM in such a case.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/ext4/super.c    | 10 ++++++++++
 fs/namei.c         | 12 ++++++++++++
 include/linux/fs.h |  1 +
 3 files changed, 23 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 72b459d..f2cd8e3 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1195,6 +1195,15 @@ static struct fscrypt_operations ext4_cryptops = {
 };
 #endif
 
+static int ext4_compat_flag_check(struct inode *inode, int openflag)
+{
+	if (openflag & O_DIRECT &&
+		test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
+		return -EPERM;
+
+	return 0;
+}
+
 #ifdef CONFIG_QUOTA
 static char *quotatypes[] = INITQFNAMES;
 #define QTYPE2NAME(t) (quotatypes[t])
@@ -1267,6 +1276,7 @@ static const struct super_operations ext4_sops = {
 	.get_dquots	= ext4_get_dquots,
 #endif
 	.bdev_try_to_free_page = bdev_try_to_free_page,
+	.compat_flag_check = ext4_compat_flag_check,
 };
 
 static const struct export_operations ext4_export_ops = {
diff --git a/fs/namei.c b/fs/namei.c
index 1669c93d..7edbfbb 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3493,6 +3493,18 @@ static struct file *path_openat(struct nameidata *nd,
 		put_filp(file);
 		return ERR_CAST(s);
 	}
+
+	if (unlikely(file->f_flags & O_DIRECT)) {
+		struct super_block *sb = nd->inode->i_sb;
+
+		if (unlikely(sb->s_op->compat_flag_check)) {
+			error = sb->s_op->compat_flag_check(nd->inode,
+							    op->open_flag);
+			if (error)
+				goto out2;
+		}
+	}
+
 	while (!(error = link_path_walk(s, nd)) &&
 		(error = do_last(nd, file, op, &opened)) > 0) {
 		nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 03a5a39..bba6c0b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1776,6 +1776,7 @@ struct super_operations {
 				  struct shrink_control *);
 	long (*free_cached_objects)(struct super_block *,
 				    struct shrink_control *);
+	int (*compat_flag_check)(struct inode *, int);
 };
 
 /*
-- 
2.7.4


             reply	other threads:[~2016-11-24 19:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-24 19:47 Fabian Frederick [this message]
2016-11-24 20:39 ` [PATCH 1/1 linux-next] ext4: add compatibility flag check Al Viro
2016-11-24 21:43   ` Fabian Frederick
2016-11-25  5:26 ` Theodore Ts'o
2016-11-25  6:14   ` Fabian Frederick

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=1480016861-24432-1-git-send-email-fabf@skynet.be \
    --to=fabf@skynet.be \
    --cc=jack@suse.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).