Skip to contentSkip to conversation

proc: implement support for automounts in task directories

PATCH In review Alexey Dobriyan 3 participants 4 messages Jan 5, 2009 – Jan 6, 2009 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 proc: implement support for automounts in task directories

This is current version of /proc/net as separate file system patchset, rebased, etc. I'll put it into -next again when merge window closes.

Please, review.
----------------------------------------------------------------------

Quoted 1 line

From a934c391e19837e760592536c4cdd1b4f2432caa Mon Sep 17 00:00:00 2001

From: Eric W. Biederman <[email protected]>
Date: Wed, 19 Nov 2008 03:57:02 +0300
Subject: [PATCH 1/6] proc: implement support for automounts in task directories

This is a general mechanism that is capable of removing any unused mounts on /proc in any directory. As we flush the mounts when a processes dies this mechanism is tailored for flushing mounts in the per task and per task group directories.

---
 fs/proc/Makefile        |    1 +
 fs/proc/automount.c     |   28 ++++++++++++++++++++++++++++
 fs/proc/internal.h      |    2 ++
 include/linux/proc_fs.h |    5 +++++
 kernel/exit.c           |    2 +-
 5 files changed, 37 insertions(+), 1 deletions(-)
 create mode 100644 fs/proc/automount.c
fs/proc/Makefile +1 -0
index 63d9651..757f7c1 100644
@@ -9,6 +9,7 @@ proc-$(CONFIG_MMU)	:= mmu.o task_mmu.o
 
 proc-y       += inode.o root.o base.o generic.o array.o \
 		proc_tty.o
+proc-y	+= automount.o
 proc-y	+= cmdline.o
 proc-y	+= cpuinfo.o
 proc-y	+= devices.o
fs/proc/automount.c new file +28 -0
new file mode 100644
index 0000000..5d22b5a
@@ -0,0 +1,28 @@
+#include <linux/list.h>
+#include <linux/mount.h>
+#include <linux/workqueue.h>
+#include "internal.h"
+
+LIST_HEAD(proc_automounts);
+
+static void proc_expire_automounts(struct work_struct *work);
+
+static DECLARE_DELAYED_WORK(proc_automount_task, proc_expire_automounts);
+static int proc_automount_timeout = 500 * HZ;
+
+void proc_shrink_automounts(void)
+{
+	struct list_head *list = &proc_automounts;
+
+	mark_mounts_for_expiry(list);
+	mark_mounts_for_expiry(list);
+	if (list_empty(list))
+		return;
+
+	schedule_delayed_work(&proc_automount_task, proc_automount_timeout);
+}
+
+static void proc_expire_automounts(struct work_struct *work)
+{
+	proc_shrink_automounts();
+}
fs/proc/internal.h +2 -0
index 3e8aeb8..314c0d3 100644
@@ -93,3 +93,5 @@ struct pde_opener {
 	int (*release)(struct inode *, struct file *);
 	struct list_head lh;
 };
+
+extern struct list_head proc_automounts;
include/linux/proc_fs.h +5 -0
index b8bdb96..768e627 100644
@@ -101,6 +101,7 @@ extern spinlock_t proc_subdir_lock;
 
 extern void proc_root_init(void);
 
+void proc_shrink_automounts(void);
 void proc_flush_task(struct task_struct *task);
 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
 int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
@@ -207,6 +208,10 @@ static inline void proc_flush_task(struct task_struct *task)
 {
 }
 
+static inline void proc_shrink_automounts(void)
+{
+}
+
 static inline struct proc_dir_entry *create_proc_entry(const char *name,
 	mode_t mode, struct proc_dir_entry *parent) { return NULL; }
 static inline struct proc_dir_entry *proc_create(const char *name,
kernel/exit.c +1 -1
index c9e5a1c..640b3bb 100644
@@ -173,7 +173,7 @@ repeat:
 	/* don't need to get the RCU readlock here - the process is dead and
 	 * can't be modifying its own credentials */
 	atomic_dec(&__task_cred(p)->user->processes);
-
+	proc_shrink_automounts();
 	proc_flush_task(p);
 	write_lock_irq(&tasklist_lock);
 	tracehook_finish_release_task(p);
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 2 lines · Alexey Dobriyan

This is current version of /proc/net as separate file system patchset, rebased, etc. I'll put it into -next again when merge window closes.

Currently everything is at

git://git.kernel.org/pub/scm/linux/kernel/git/adobriyan/proc.git proc-wip

#2 lore raw
In reply to Alexey Dobriyan
Quoted 2 lines · Alexey Dobriyan

This is current version of /proc/net as separate file system patchset, rebased, etc. I'll put it into -next again when merge window closes.

I still don't see the point for that. Why not /proc/nets/<netid> with symlinks from /proc/<pid>/net into those?

#3 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Alexey Dobriyan

This is current version of /proc/net as separate file system patchset, rebased, etc. I'll put it into -next again when merge window closes.

I still don't see the point for that. Why not /proc/nets/<netid> with symlinks from /proc/<pid>/net into those?

Simple really.

/proc/nets/<netid> is the other possible viable solution. Where netid is some pid value that we assign to the network namespace during unshare or clone. While there is precedent of using a pid value to identify a process group or a session it is a bit of a stretch to have it cover a namespace.

When I talked it over with Al his preference was to for the current approach, and it happens to be my preference as well.

It gives more control of naming policy to user space allowing us to avoid the maintenance pain that is sysfs where user space depends upon a fixed kernel naming policy (which makes change hard).

It gives us a guarantee that we only have a single dentry tree for any given network namespace.

It allows us to eventually separate out maintenance of proc/generic and proc/net, as inherently they have nothing in common.

The only cost of this is that we actually use one of the rare but fully supported vfs features, on demand submounts.

Beyond that proc has wanted to be several filesystems for ages, and doing it this way allows us to actually start splitting proc up without breaking backwards compatibility with out existing user space.

Eric