From: Roland Dreier <rdreier@cisco.com>
To: Davide Libenzi <davidel@xmailserver.org>
Cc: linux-kernel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH] anonfd: Make file read-only if fops->write is not set
Date: Thu, 17 Dec 2009 21:46:11 -0800 [thread overview]
Message-ID: <adaws0k3kd8.fsf@roland-alpha.cisco.com> (raw)
It seems a couple places such as arch/ia64/kernel/perfmon.c and
drivers/infiniband/core/uverbs_main.c could use anon_inode_getfile()
instead of a private pseudo-fs + alloc_file(), if only there were a way
to get a read-only file. So provide this by having anon_inode_getfile()
create a read-only file if the fops->write passed in is NULL.
Signed-off-by: Roland Dreier <rolandd@cisco.com>
---
Hi Davide,
Would you consider a patch like this? I'm not sure if this is the most
elegant way to handle this -- perhaps extending the flags parameter to
say whether we want writable or not would be better. Let me know if you
would prefer that.
Thanks,
Roland
fs/anon_inodes.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 2c99459..097f91f 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -121,13 +121,13 @@ struct file *anon_inode_getfile(const char *name,
d_instantiate(path.dentry, anon_inode_inode);
error = -ENFILE;
- file = alloc_file(&path, FMODE_READ | FMODE_WRITE, fops);
+ file = alloc_file(&path, FMODE_READ | (fops->write ? FMODE_WRITE : 0), fops);
if (!file)
goto err_dput;
file->f_mapping = anon_inode_inode->i_mapping;
file->f_pos = 0;
- file->f_flags = O_RDWR | (flags & O_NONBLOCK);
+ file->f_flags = (fops->write ? O_RDWR : O_RDONLY) | (flags & O_NONBLOCK);
file->f_version = 0;
file->private_data = priv;
next reply other threads:[~2009-12-18 5:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-18 5:46 Roland Dreier [this message]
2009-12-18 6:10 ` [PATCH] anonfd: Make file read-only if fops->write is not set Al Viro
2009-12-18 17:12 ` Davide Libenzi
2009-12-18 17:41 ` [PATCH v2] " Roland Dreier
2009-12-18 18:59 ` Davide Libenzi
2009-12-18 19:14 ` Al Viro
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=adaws0k3kd8.fsf@roland-alpha.cisco.com \
--to=rdreier@cisco.com \
--cc=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
--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