Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/viro/vfs-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
  [patch 7/7] vfs: mountinfo: show dominating group id
  [patch 6/7] vfs: mountinfo: add /proc/<pid>/mountinfo
  [patch 5/7] vfs: mountinfo: allow using process root
  [patch 4/7] vfs: mountinfo: add mount peer group ID
  [patch 3/7] vfs: mountinfo: add mount ID
  [patch 2/7] vfs: mountinfo: add seq_file_root()
  [patch 1/7] vfs: mountinfo: add dentry_path()
  [PATCH] remove unused label in xattr.c (noise from ro-bind)
  • Loading branch information
Linus Torvalds committed Apr 23, 2008
2 parents b0d19a3 + 97e7e0f commit 79c1cb7
Show file tree
Hide file tree
Showing 12 changed files with 573 additions and 138 deletions.
38 changes: 38 additions & 0 deletions Documentation/filesystems/proc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Table of Contents
2.13 /proc/<pid>/oom_score - Display current oom-killer score
2.14 /proc/<pid>/io - Display the IO accounting fields
2.15 /proc/<pid>/coredump_filter - Core dump filtering settings
2.16 /proc/<pid>/mountinfo - Information about mounts

------------------------------------------------------------------------------
Preface
Expand Down Expand Up @@ -2348,4 +2349,41 @@ For example:
$ echo 0x7 > /proc/self/coredump_filter
$ ./some_program

2.16 /proc/<pid>/mountinfo - Information about mounts
--------------------------------------------------------

This file contains lines of the form:

36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
(1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11)

(1) mount ID: unique identifier of the mount (may be reused after umount)
(2) parent ID: ID of parent (or of self for the top of the mount tree)
(3) major:minor: value of st_dev for files on filesystem
(4) root: root of the mount within the filesystem
(5) mount point: mount point relative to the process's root
(6) mount options: per mount options
(7) optional fields: zero or more fields of the form "tag[:value]"
(8) separator: marks the end of the optional fields
(9) filesystem type: name of filesystem of the form "type[.subtype]"
(10) mount source: filesystem specific information or "none"
(11) super options: per super block options

Parsers should ignore all unrecognised optional fields. Currently the
possible optional fields are:

shared:X mount is shared in peer group X
master:X mount is slave to peer group X
propagate_from:X mount is slave and receives propagation from peer group X (*)
unbindable mount is unbindable

(*) X is the closest dominant peer group under the process's root. If
X is the immediate master of the mount, or if there's no dominant peer
group under the same root, then only the "master:X" field is present
and not the "propagate_from:X" field.

For more information on mount propagation see:

Documentation/filesystems/sharedsubtree.txt

------------------------------------------------------------------------------
114 changes: 82 additions & 32 deletions fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1746,12 +1746,21 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
goto shouldnt_be_hashed;
}

static int prepend(char **buffer, int *buflen, const char *str,
int namelen)
{
*buflen -= namelen;
if (*buflen < 0)
return -ENAMETOOLONG;
*buffer -= namelen;
memcpy(*buffer, str, namelen);
return 0;
}

/**
* d_path - return the path of a dentry
* @dentry: dentry to report
* @vfsmnt: vfsmnt to which the dentry belongs
* @root: root dentry
* @rootmnt: vfsmnt to which the root dentry belongs
* @path: the dentry/vfsmount to report
* @root: root vfsmnt/dentry (may be modified by this function)
* @buffer: buffer to return value in
* @buflen: buffer length
*
Expand All @@ -1761,23 +1770,22 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
* Returns the buffer or an error code if the path was too long.
*
* "buflen" should be positive. Caller holds the dcache_lock.
*
* If path is not reachable from the supplied root, then the value of
* root is changed (without modifying refcounts).
*/
static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
struct path *root, char *buffer, int buflen)
char *__d_path(const struct path *path, struct path *root,
char *buffer, int buflen)
{
struct dentry *dentry = path->dentry;
struct vfsmount *vfsmnt = path->mnt;
char * end = buffer+buflen;
char * retval;
int namelen;

*--end = '\0';
buflen--;
if (!IS_ROOT(dentry) && d_unhashed(dentry)) {
buflen -= 10;
end -= 10;
if (buflen < 0)

prepend(&end, &buflen, "\0", 1);
if (!IS_ROOT(dentry) && d_unhashed(dentry) &&
(prepend(&end, &buflen, " (deleted)", 10) != 0))
goto Elong;
memcpy(end, " (deleted)", 10);
}

if (buflen < 1)
goto Elong;
Expand All @@ -1804,26 +1812,23 @@ static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
}
parent = dentry->d_parent;
prefetch(parent);
namelen = dentry->d_name.len;
buflen -= namelen + 1;
if (buflen < 0)
if ((prepend(&end, &buflen, dentry->d_name.name,
dentry->d_name.len) != 0) ||
(prepend(&end, &buflen, "/", 1) != 0))
goto Elong;
end -= namelen;
memcpy(end, dentry->d_name.name, namelen);
*--end = '/';
retval = end;
dentry = parent;
}

return retval;

global_root:
namelen = dentry->d_name.len;
buflen -= namelen;
if (buflen < 0)
retval += 1; /* hit the slash */
if (prepend(&retval, &buflen, dentry->d_name.name,
dentry->d_name.len) != 0)
goto Elong;
retval -= namelen-1; /* hit the slash */
memcpy(retval, dentry->d_name.name, namelen);
root->mnt = vfsmnt;
root->dentry = dentry;
return retval;
Elong:
return ERR_PTR(-ENAMETOOLONG);
Expand All @@ -1846,6 +1851,7 @@ char *d_path(struct path *path, char *buf, int buflen)
{
char *res;
struct path root;
struct path tmp;

/*
* We have various synthetic filesystems that never get mounted. On
Expand All @@ -1859,10 +1865,11 @@ char *d_path(struct path *path, char *buf, int buflen)

read_lock(&current->fs->lock);
root = current->fs->root;
path_get(&current->fs->root);
path_get(&root);
read_unlock(&current->fs->lock);
spin_lock(&dcache_lock);
res = __d_path(path->dentry, path->mnt, &root, buf, buflen);
tmp = root;
res = __d_path(path, &tmp, buf, buflen);
spin_unlock(&dcache_lock);
path_put(&root);
return res;
Expand All @@ -1889,6 +1896,48 @@ char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen,
return memcpy(buffer, temp, sz);
}

/*
* Write full pathname from the root of the filesystem into the buffer.
*/
char *dentry_path(struct dentry *dentry, char *buf, int buflen)
{
char *end = buf + buflen;
char *retval;

spin_lock(&dcache_lock);
prepend(&end, &buflen, "\0", 1);
if (!IS_ROOT(dentry) && d_unhashed(dentry) &&
(prepend(&end, &buflen, "//deleted", 9) != 0))
goto Elong;
if (buflen < 1)
goto Elong;
/* Get '/' right */
retval = end-1;
*retval = '/';

for (;;) {
struct dentry *parent;
if (IS_ROOT(dentry))
break;

parent = dentry->d_parent;
prefetch(parent);

if ((prepend(&end, &buflen, dentry->d_name.name,
dentry->d_name.len) != 0) ||
(prepend(&end, &buflen, "/", 1) != 0))
goto Elong;

retval = end;
dentry = parent;
}
spin_unlock(&dcache_lock);
return retval;
Elong:
spin_unlock(&dcache_lock);
return ERR_PTR(-ENAMETOOLONG);
}

/*
* NOTE! The user-level library version returns a
* character pointer. The kernel system call just
Expand Down Expand Up @@ -1918,19 +1967,20 @@ asmlinkage long sys_getcwd(char __user *buf, unsigned long size)

read_lock(&current->fs->lock);
pwd = current->fs->pwd;
path_get(&current->fs->pwd);
path_get(&pwd);
root = current->fs->root;
path_get(&current->fs->root);
path_get(&root);
read_unlock(&current->fs->lock);

error = -ENOENT;
/* Has the current directory has been unlinked? */
spin_lock(&dcache_lock);
if (pwd.dentry->d_parent == pwd.dentry || !d_unhashed(pwd.dentry)) {
unsigned long len;
struct path tmp = root;
char * cwd;

cwd = __d_path(pwd.dentry, pwd.mnt, &root, page, PAGE_SIZE);
cwd = __d_path(&pwd, &tmp, page, PAGE_SIZE);
spin_unlock(&dcache_lock);

error = PTR_ERR(cwd);
Expand Down
Loading

0 comments on commit 79c1cb7

Please sign in to comment.