This patch adds proc_ns_read method which provides IDs for /proc/pid/ns/* files. Based-on-patch-from: Pavel Emelyanov Signed-off-by: Cyrill Gorcunov CC: Glauber Costa CC: Andi Kleen CC: Tejun Heo CC: Matt Helsley CC: Pekka Enberg CC: Eric Dumazet CC: Vasiliy Kulikov CC: Andrew Morton --- Documentation/filesystems/proc.txt | 24 ++++++++++++++++++++++++ fs/proc/namespaces.c | 21 +++++++++++++++++++++ include/linux/mm.h | 1 + 3 files changed, 46 insertions(+) Index: linux-2.6.git/Documentation/filesystems/proc.txt =================================================================== --- linux-2.6.git.orig/Documentation/filesystems/proc.txt +++ linux-2.6.git/Documentation/filesystems/proc.txt @@ -40,6 +40,7 @@ Table of Contents 3.4 /proc//coredump_filter - Core dump filtering settings 3.5 /proc//mountinfo - Information about mounts 3.6 /proc//comm & /proc//task//comm + 3.7 /proc//ns - Information about namespaces ------------------------------------------------------------------------------ @@ -1545,3 +1546,26 @@ a task to set its own or one of its thre is limited in size compared to the cmdline value, so writing anything longer then the kernel's TASK_COMM_LEN (currently 16 chars) will result in a truncated comm value. + +3.7 /proc//ns - Information about namespaces +----------------------------------------------------- + +This directory consists of the following files "net", "uts", "ipc", +and depend if appropriate CONFIG_ entry is set, i.e. it's possible +to have only one, two or all three files here. + +Currently file contents provides that named "object id" number, which +is a number useful for the one purpose only -- to test if two differen + share the namespace. + +A typical format is + +id: 445332486300860161 + +i.e. "id" followed by a number. One should never assume the number +means something, it is only useful for "sameness" test with another number +obtained from another . + +Moreover, a safe approach is to remember it as a string, since format may +change in future and id would be not a long integer value, but something +else, say SHA1/2 or even uuid encoded stream. Index: linux-2.6.git/fs/proc/namespaces.c =================================================================== --- linux-2.6.git.orig/fs/proc/namespaces.c +++ linux-2.6.git/fs/proc/namespaces.c @@ -27,10 +27,31 @@ static const struct proc_ns_operations * #endif }; +#ifdef CONFIG_GENERIC_OBJECT_IDS +static ssize_t proc_ns_read(struct file *file, char __user *buf, + size_t len, loff_t *ppos) +{ + struct proc_inode *ei = PROC_I(file->f_dentry->d_inode); + char tmp[32]; + + snprintf(tmp, sizeof(tmp), "id:\t%lu\n", + gen_obj_id(ei->ns, GEN_OBJ_ID_NS)); + return simple_read_from_buffer(buf, len, ppos, tmp, strlen(tmp)); +} + +static const struct file_operations ns_file_operations = { + .llseek = no_llseek, + .read = proc_ns_read, +}; + +#else + static const struct file_operations ns_file_operations = { .llseek = no_llseek, }; +#endif /* CONFIG_GENERIC_OBJECT_IDS */ + static struct dentry *proc_ns_instantiate(struct inode *dir, struct dentry *dentry, struct task_struct *task, const void *ptr) { Index: linux-2.6.git/include/linux/mm.h =================================================================== --- linux-2.6.git.orig/include/linux/mm.h +++ linux-2.6.git/include/linux/mm.h @@ -1641,6 +1641,7 @@ extern void copy_user_huge_page(struct p #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */ enum { + GEN_OBJ_ID_NS, GEN_OBJ_ID_TYPES, }; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/