~apparmor-dev/apparmor/2_3

« back to all changes in this revision

Viewing changes to kernel-patches/for-mainline/d_namespace_path.diff

  • Committer: jrjohansen
  • Date: 2008-05-27 12:04:33 UTC
  • Revision ID: svn-v4:40609528-9d10-0410-9bd8-e926d5471da9:branches/2_3:1265
remove for-mainline dir from kernel patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From: Andreas Gruenbacher <agruen@suse.de>
2
 
Subject: Add d_namespace_path() to compute namespace relative pathnames
3
 
 
4
 
In AppArmor, we are interested in pathnames relative to the namespace root.
5
 
This is the same as d_path() except for the root where the search ends. Add
6
 
a function for computing the namespace-relative path.
7
 
 
8
 
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
9
 
Signed-off-by: John Johansen <jjohansen@suse.de>
10
 
 
11
 
---
12
 
 fs/dcache.c            |    6 +++---
13
 
 fs/namespace.c         |   27 +++++++++++++++++++++++++++
14
 
 include/linux/dcache.h |    2 ++
15
 
 include/linux/mount.h  |    2 ++
16
 
 4 files changed, 34 insertions(+), 3 deletions(-)
17
 
 
18
 
--- a/fs/dcache.c
19
 
+++ b/fs/dcache.c
20
 
@@ -1782,9 +1782,9 @@ shouldnt_be_hashed:
21
 
  *
22
 
  * Returns the buffer or an error code.
23
 
  */
24
 
-static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
25
 
-                     struct dentry *root, struct vfsmount *rootmnt,
26
 
-                     char *buffer, int buflen, int fail_deleted)
27
 
+char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
28
 
+              struct dentry *root, struct vfsmount *rootmnt,
29
 
+              char *buffer, int buflen, int fail_deleted)
30
 
 {
31
 
        int namelen, is_slash, vfsmount_locked = 0;
32
 
 
33
 
--- a/fs/namespace.c
34
 
+++ b/fs/namespace.c
35
 
@@ -1883,3 +1883,30 @@ void __put_mnt_ns(struct mnt_namespace *
36
 
        release_mounts(&umount_list);
37
 
        kfree(ns);
38
 
 }
39
 
+
40
 
+char *d_namespace_path(struct dentry *dentry, struct vfsmount *vfsmnt,
41
 
+                      char *buf, int buflen)
42
 
+{
43
 
+       struct vfsmount *rootmnt, *nsrootmnt = NULL;
44
 
+       struct dentry *root = NULL;
45
 
+       char *res;
46
 
+
47
 
+       read_lock(&current->fs->lock);
48
 
+       rootmnt = mntget(current->fs->rootmnt);
49
 
+       read_unlock(&current->fs->lock);
50
 
+       spin_lock(&vfsmount_lock);
51
 
+       if (rootmnt->mnt_ns)
52
 
+               nsrootmnt = mntget(rootmnt->mnt_ns->root);
53
 
+       spin_unlock(&vfsmount_lock);
54
 
+       mntput(rootmnt);
55
 
+       if (nsrootmnt)
56
 
+               root = dget(nsrootmnt->mnt_root);
57
 
+       res = __d_path(dentry, vfsmnt, root, nsrootmnt, buf, buflen, 1);
58
 
+       dput(root);
59
 
+       mntput(nsrootmnt);
60
 
+       /* Prevent empty path for lazily unmounted filesystems. */
61
 
+       if (!IS_ERR(res) && *res == '\0')
62
 
+               *--res = '.';
63
 
+       return res;
64
 
+}
65
 
+EXPORT_SYMBOL(d_namespace_path);
66
 
--- a/include/linux/dcache.h
67
 
+++ b/include/linux/dcache.h
68
 
@@ -300,6 +300,8 @@ extern int d_validate(struct dentry *, s
69
 
  */
70
 
 extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
71
 
 
72
 
+extern char *__d_path(struct dentry *, struct vfsmount *, struct dentry *,
73
 
+                     struct vfsmount *, char *, int, int);
74
 
 extern char * d_path(struct dentry *, struct vfsmount *, char *, int);
75
 
   
76
 
 /* Allocation counts.. */
77
 
--- a/include/linux/mount.h
78
 
+++ b/include/linux/mount.h
79
 
@@ -103,5 +103,7 @@ extern void shrink_submounts(struct vfsm
80
 
 extern spinlock_t vfsmount_lock;
81
 
 extern dev_t name_to_dev_t(char *name);
82
 
 
83
 
+extern char *d_namespace_path(struct dentry *, struct vfsmount *, char *, int);
84
 
+
85
 
 #endif
86
 
 #endif /* _LINUX_MOUNT_H */