[Devel] [PATCH RH9 32/33] proc/net: proc_net_*() helpers introduced

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Sep 23 22:08:35 MSK 2021


From: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>

Will be used to make per-net sysfs files visible in CT.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>

Rebase to RHEL8 beta kernel notes:
  more helpers added: proc_net_{seq*,single*,net*}

TODO: rename helpers - proc_net_create_net() does not look good.
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>

(cherry picked from vz8 commit 22bdd5751b471489c5c71127abf63933c3d1dd2b)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 include/linux/proc_fs.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 069c7fd..e89d4bf 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -206,9 +206,67 @@ static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
 static inline struct proc_dir_entry *proc_net_mkdir(
 	struct net *net, const char *name, struct proc_dir_entry *parent)
 {
-	return _proc_mkdir(name, 0, parent, net, true);
+	return _proc_mkdir(name, S_IRUGO | S_IXUGO | S_ISVTX, parent, net, true);
 }
 
+static inline struct proc_dir_entry *proc_net_create_data(const char *name,
+				umode_t mode, struct proc_dir_entry *parent,
+				const struct file_operations *fops, void *data)
+{
+	return proc_create_data(name, S_ISVTX | mode, parent, fops, data);
+}
+
+static inline struct proc_dir_entry *proc_net_create(const char *name,
+				umode_t mode, struct proc_dir_entry *parent,
+				const struct file_operations *fops)
+{
+	return proc_net_create_data(name, mode, parent, fops, NULL);
+}
+
+static inline struct proc_dir_entry *proc_net_create_seq_private(
+		const char *name, umode_t mode,
+		struct proc_dir_entry *parent, const struct seq_operations *ops,
+		unsigned int state_size, void *data)
+{
+	return proc_create_seq_private(name, S_ISVTX | mode, parent, ops,
+				       state_size, data);
+}
+#define proc_net_create_seq_data(name, mode, parent, ops, data) \
+	proc_net_create_seq_private(name, mode, parent, ops, 0, data)
+#define proc_net_create_seq(name, mode, parent, ops) \
+	proc_net_create_seq_private(name, mode, parent, ops, 0, NULL)
+
+static inline struct proc_dir_entry *proc_net_create_net_data(
+		const char *name, umode_t mode,
+		struct proc_dir_entry *parent, const struct seq_operations *ops,
+		unsigned int state_size, void *data)
+{
+	return proc_create_net_data(name, S_ISVTX | mode, parent,
+				    ops, state_size, data);
+}
+#define proc_net_create_net(name, mode, parent, state_size, ops) \
+	proc_net_create_net_data(name, mode, parent, state_size, ops, NULL)
+
+static inline struct proc_dir_entry *proc_net_create_net_single(
+		const char *name, umode_t mode,
+		struct proc_dir_entry *parent,
+		int (*show)(struct seq_file *, void *), void *data)
+{
+	return proc_create_net_single(name, S_ISVTX | mode, parent,
+				      show, data);
+}
+
+static inline struct proc_dir_entry *proc_net_create_single_data(
+		const char *name, umode_t mode,
+		struct proc_dir_entry *parent,
+		int (*show)(struct seq_file *, void *), void *data)
+{
+	return proc_create_single_data(name, S_ISVTX | mode, parent,
+				       show, data);
+}
+#define proc_net_create_single(name, mode, parent, show) \
+	proc_net_create_single_data(name, mode, parent, show, NULL)
+
 struct ns_common;
 int open_related_ns(struct ns_common *ns,
 		   struct ns_common *(*get_ns)(struct ns_common *ns));
-- 
1.8.3.1



More information about the Devel mailing list