Linux-Fsdevel Archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] fs: Create anon_inode_getfile_fmode()
@ 2024-04-26  7:58 Dawid Osuchowski
  2024-04-26 16:05 ` Christian Brauner
  2024-05-08  1:48 ` Al Viro
  0 siblings, 2 replies; 6+ messages in thread
From: Dawid Osuchowski @ 2024-04-26  7:58 UTC (permalink / raw
  To: linux-fsdevel; +Cc: viro, brauner, jack, Dawid Osuchowski

Creates an anon_inode_getfile_fmode() function that works similarly to
anon_inode_getfile() with the addition of being able to set the fmode
member.

Signed-off-by: Dawid Osuchowski <linux@osuchow.ski>
---
Changes since v1:
* removed __anon_inode_create_getfile_fmode()
* streamlined if statement and got rid of goto
Changes since v2:
* changed unsigned int for f_mode into fmode_t in anon_inodes.h
* added <linux/types.h> header to anon_inodes.h
---
 fs/anon_inodes.c            | 33 +++++++++++++++++++++++++++++++++
 include/linux/anon_inodes.h |  5 +++++
 2 files changed, 38 insertions(+)

diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 0496cb5b6eab..42bd1cb7c9cd 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -148,6 +148,38 @@ struct file *anon_inode_getfile(const char *name,
 }
 EXPORT_SYMBOL_GPL(anon_inode_getfile);
 
+/**
+ * anon_inode_getfile_fmode - creates a new file instance by hooking it up to an
+ *                      anonymous inode, and a dentry that describe the "class"
+ *                      of the file
+ *
+ * @name:    [in]    name of the "class" of the new file
+ * @fops:    [in]    file operations for the new file
+ * @priv:    [in]    private data for the new file (will be file's private_data)
+ * @flags:   [in]    flags
+ * @f_mode:  [in]    fmode
+ *
+ * Creates a new file by hooking it on a single inode. This is useful for files
+ * that do not need to have a full-fledged inode in order to operate correctly.
+ * All the files created with anon_inode_getfile() will share a single inode,
+ * hence saving memory and avoiding code duplication for the file/inode/dentry
+ * setup. Allows setting the fmode. Returns the newly created file* or an error
+ * pointer.
+ */
+struct file *anon_inode_getfile_fmode(const char *name,
+				const struct file_operations *fops,
+				void *priv, int flags, fmode_t f_mode)
+{
+	struct file *file;
+
+	file = __anon_inode_getfile(name, fops, priv, flags, NULL, false);
+	if (!IS_ERR(file))
+		file->f_mode |= f_mode;
+
+	return file;
+}
+EXPORT_SYMBOL_GPL(anon_inode_getfile_fmode);
+
 /**
  * anon_inode_create_getfile - Like anon_inode_getfile(), but creates a new
  *                             !S_PRIVATE anon inode rather than reuse the
@@ -271,6 +303,7 @@ int anon_inode_create_getfd(const char *name, const struct file_operations *fops
 	return __anon_inode_getfd(name, fops, priv, flags, context_inode, true);
 }
 
+
 static int __init anon_inode_init(void)
 {
 	anon_inode_mnt = kern_mount(&anon_inode_fs_type);
diff --git a/include/linux/anon_inodes.h b/include/linux/anon_inodes.h
index 93a5f16d03f3..edef565c2a1a 100644
--- a/include/linux/anon_inodes.h
+++ b/include/linux/anon_inodes.h
@@ -9,12 +9,17 @@
 #ifndef _LINUX_ANON_INODES_H
 #define _LINUX_ANON_INODES_H
 
+#include <linux/types.h>
+
 struct file_operations;
 struct inode;
 
 struct file *anon_inode_getfile(const char *name,
 				const struct file_operations *fops,
 				void *priv, int flags);
+struct file *anon_inode_getfile_fmode(const char *name,
+				const struct file_operations *fops,
+				void *priv, int flags, fmode_t f_mode);
 struct file *anon_inode_create_getfile(const char *name,
 				       const struct file_operations *fops,
 				       void *priv, int flags,
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] fs: Create anon_inode_getfile_fmode()
  2024-04-26  7:58 [PATCH v3] fs: Create anon_inode_getfile_fmode() Dawid Osuchowski
@ 2024-04-26 16:05 ` Christian Brauner
  2024-05-08  0:41   ` Al Viro
  2024-05-08  1:48 ` Al Viro
  1 sibling, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2024-04-26 16:05 UTC (permalink / raw
  To: Dawid Osuchowski; +Cc: Christian Brauner, viro, jack, linux-fsdevel

On Fri, 26 Apr 2024 09:58:54 +0200, Dawid Osuchowski wrote:
> Creates an anon_inode_getfile_fmode() function that works similarly to
> anon_inode_getfile() with the addition of being able to set the fmode
> member.
> 
> 

Sorry, forgot that I picked this up.

---

Applied to the vfs.misc branch of the vfs/vfs.git tree.
Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/1] fs: Create anon_inode_getfile_fmode()
      https://git.kernel.org/vfs/vfs/c/55394d29c9e1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] fs: Create anon_inode_getfile_fmode()
  2024-04-26 16:05 ` Christian Brauner
@ 2024-05-08  0:41   ` Al Viro
  2024-05-08  0:46     ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2024-05-08  0:41 UTC (permalink / raw
  To: Christian Brauner; +Cc: Dawid Osuchowski, jack, linux-fsdevel

On Fri, Apr 26, 2024 at 06:05:15PM +0200, Christian Brauner wrote:
> On Fri, 26 Apr 2024 09:58:54 +0200, Dawid Osuchowski wrote:
> > Creates an anon_inode_getfile_fmode() function that works similarly to
> > anon_inode_getfile() with the addition of being able to set the fmode
> > member.
> > 
> > 
> 
> Sorry, forgot that I picked this up.
> 
> ---
> 
> Applied to the vfs.misc branch of the vfs/vfs.git tree.
> Patches in the vfs.misc branch should appear in linux-next soon.
> 
> Please report any outstanding bugs that were missed during review in a
> new review to the original patch series allowing us to drop it.
> 
> It's encouraged to provide Acked-bys and Reviewed-bys even though the
> patch has now been applied. If possible patch trailers will be updated.
> 
> Note that commit hashes shown below are subject to change due to rebase,
> trailer updates or similar. If in doubt, please check the listed branch.
> 
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
> branch: vfs.misc
> 
> [1/1] fs: Create anon_inode_getfile_fmode()
>       https://git.kernel.org/vfs/vfs/c/55394d29c9e1

Umm...  vfs.all contains 386831d0fb42a952afd4b0f862f335a09e911715
    Merge branch 'vfs.misc' into vfs.all
which merges e035af9f6ebacd98774b1be2af58a5afd6d0d291 into vfs.all.

55394d29c9e164f2e1991352f1dc8f973c4f1589 "fs: Create anon_inode_getfile_fmode()"
is e035af9f6ebacd98774b1be2af58a5afd6d0d291^^^ (and thus picked by the merge),
but your vfs.miss is 652efdeca5b142ee9c5197f45f64fc3d427d4b08, which is
e035af9f6ebacd98774b1be2af58a5afd6d0d291^^^^.

So it looks like you forgot to push vfs.misc as well...

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] fs: Create anon_inode_getfile_fmode()
  2024-05-08  0:41   ` Al Viro
@ 2024-05-08  0:46     ` Al Viro
  2024-05-08 11:37       ` Christian Brauner
  0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2024-05-08  0:46 UTC (permalink / raw
  To: Christian Brauner; +Cc: Dawid Osuchowski, jack, linux-fsdevel

On Wed, May 08, 2024 at 01:41:06AM +0100, Al Viro wrote:

> So it looks like you forgot to push vfs.misc as well...

BTW, IME it's useful to have all merges either go from tips of
named branches or from tags - easier to catch that kind of
SNAFU when one forgets to push the topical out.  You can
easily see it in e.g. gitk.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] fs: Create anon_inode_getfile_fmode()
  2024-04-26  7:58 [PATCH v3] fs: Create anon_inode_getfile_fmode() Dawid Osuchowski
  2024-04-26 16:05 ` Christian Brauner
@ 2024-05-08  1:48 ` Al Viro
  1 sibling, 0 replies; 6+ messages in thread
From: Al Viro @ 2024-05-08  1:48 UTC (permalink / raw
  To: Dawid Osuchowski; +Cc: linux-fsdevel, brauner, jack

On Fri, Apr 26, 2024 at 09:58:54AM +0200, Dawid Osuchowski wrote:
> Creates an anon_inode_getfile_fmode() function that works similarly to
> anon_inode_getfile() with the addition of being able to set the fmode
> member.

One note (followup commit fodder, probably in series with conversions to
that interface):

> + * @f_mode:  [in]    fmode

> + * setup. Allows setting the fmode. Returns the newly created file* or an error

is ambiguous - with no further information it reads as if we passed the value
to store in ->f_mode, which is not what's going on.

Something along the lines of

'f_mode' argument allows to set additional bits, on top of the ones set by
anon_inode_getfile() (FMODE_{OPENED,READ,WRITE,LSEEK,CAN_READ,CAN_WRITE}).
The caller should not pass those in 'f_mode' - they will be set according to
'flags' and 'fops' in all cases.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] fs: Create anon_inode_getfile_fmode()
  2024-05-08  0:46     ` Al Viro
@ 2024-05-08 11:37       ` Christian Brauner
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2024-05-08 11:37 UTC (permalink / raw
  To: Al Viro; +Cc: Dawid Osuchowski, jack, linux-fsdevel

On Wed, May 08, 2024 at 01:46:59AM +0100, Al Viro wrote:
> On Wed, May 08, 2024 at 01:41:06AM +0100, Al Viro wrote:
> 
> > So it looks like you forgot to push vfs.misc as well...
> 
> BTW, IME it's useful to have all merges either go from tips of
> named branches or from tags - easier to catch that kind of
> SNAFU when one forgets to push the topical out.  You can
> easily see it in e.g. gitk.

Yes, forgot to push vfs.misc. Fixed now!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-08 11:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26  7:58 [PATCH v3] fs: Create anon_inode_getfile_fmode() Dawid Osuchowski
2024-04-26 16:05 ` Christian Brauner
2024-05-08  0:41   ` Al Viro
2024-05-08  0:46     ` Al Viro
2024-05-08 11:37       ` Christian Brauner
2024-05-08  1:48 ` Al Viro

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 read-only IMAP folder(s) and NNTP newsgroup(s).