[PATCH 19/25] fsinfo: proc - add sb operation fsinfo() [ver #13]

From: David Howells
Date: Tue May 28 2019 - 11:17:14 EST


From: Ian Kent <raven@xxxxxxxxxx>

The new fsinfo() system call adds a new super block operation
->fsinfo() which is used by file systems to provide file
system specific information for fsinfo() requests.

The fsinfo() request FSINFO_ATTR_PARAMETERS provides the same
function as sb operation ->show_options() so it needs to be
implemented by any file system that provides ->show_options()
as a minimum.

Also add a simple FSINFO_ATTR_CAPABILITIES implementation.

Signed-off-by: Ian Kent <raven@xxxxxxxxxx>
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---

fs/proc/inode.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)

diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 5f8d215b3fd0..0f6c122d22f0 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -24,6 +24,7 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/mount.h>
+#include <linux/fsinfo.h>

#include <linux/uaccess.h>

@@ -115,6 +116,38 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root)
return 0;
}

+#ifdef CONFIG_FSINFO
+/*
+ * Get filesystem information.
+ */
+static int proc_fsinfo(struct path *path, struct fsinfo_kparams *params)
+{
+ struct super_block *sb = path->dentry->d_sb;
+ struct pid_namespace *pid = sb->s_fs_info;
+ struct fsinfo_capabilities *caps;
+
+ switch (params->request) {
+ case FSINFO_ATTR_CAPABILITIES:
+ caps = params->buffer;
+ fsinfo_set_cap(caps, FSINFO_CAP_IS_KERNEL_FS);
+ fsinfo_set_cap(caps, FSINFO_CAP_NOT_PERSISTENT);
+ return sizeof(*caps);
+
+ case FSINFO_ATTR_PARAMETERS:
+ if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID))
+ fsinfo_note_paramf(params, "gid", "%u",
+ from_kgid_munged(&init_user_ns, pid->pid_gid));
+ if (pid->hide_pid != HIDEPID_OFF)
+ fsinfo_note_paramf(params, "hidepid",
+ "%u", pid->hide_pid);
+ return params->usage;
+
+ default:
+ return generic_fsinfo(path, params);
+ }
+}
+#endif /* CONFIG_FSINFO */
+
const struct super_operations proc_sops = {
.alloc_inode = proc_alloc_inode,
.free_inode = proc_free_inode,
@@ -122,6 +155,9 @@ const struct super_operations proc_sops = {
.evict_inode = proc_evict_inode,
.statfs = simple_statfs,
.show_options = proc_show_options,
+#ifdef CONFIG_FSINFO
+ .fsinfo = proc_fsinfo,
+#endif
};

enum {BIAS = -1U<<31};