Blame view
fs/nfs/getroot.c
3.47 KB
54ceac451 NFS: Share NFS su... |
1 2 3 4 5 6 7 8 9 10 |
/* getroot.c: get the root dentry for an NFS mount * * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ |
54ceac451 NFS: Share NFS su... |
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <linux/module.h> #include <linux/init.h> #include <linux/time.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/string.h> #include <linux/stat.h> #include <linux/errno.h> #include <linux/unistd.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/stats.h> #include <linux/nfs_fs.h> #include <linux/nfs_mount.h> |
54ceac451 NFS: Share NFS su... |
25 |
#include <linux/lockd/bind.h> |
54ceac451 NFS: Share NFS su... |
26 27 |
#include <linux/seq_file.h> #include <linux/mount.h> |
54ceac451 NFS: Share NFS su... |
28 29 |
#include <linux/vfs.h> #include <linux/namei.h> |
738a35195 NFS: Secure the r... |
30 |
#include <linux/security.h> |
54ceac451 NFS: Share NFS su... |
31 |
|
7c0f6ba68 Replace <asm/uacc... |
32 |
#include <linux/uaccess.h> |
54ceac451 NFS: Share NFS su... |
33 |
|
4e437e95a nfs: include inte... |
34 |
#include "internal.h" |
54ceac451 NFS: Share NFS su... |
35 |
#define NFSDBG_FACILITY NFSDBG_CLIENT |
54ceac451 NFS: Share NFS su... |
36 37 |
/* |
b09b9417d NFS: Fix the usta... |
38 39 40 41 42 43 44 |
* Set the superblock root dentry. * Note that this function frees the inode in case of error. */ static int nfs_superblock_set_dummy_root(struct super_block *sb, struct inode *inode) { /* The mntroot acts as the dummy root dentry for this superblock */ if (sb->s_root == NULL) { |
48fde701a switch open-coded... |
45 46 |
sb->s_root = d_make_root(inode); if (sb->s_root == NULL) |
b09b9417d NFS: Fix the usta... |
47 |
return -ENOMEM; |
7de9c6ee3 new helper: ihold() |
48 |
ihold(inode); |
a10db50a4 NFS: Fix an Oops ... |
49 50 51 |
/* * Ensure that this dentry is invisible to d_find_alias(). * Otherwise, it may be spliced into the tree by |
41d28bca2 switch d_material... |
52 |
* d_splice_alias if a parent directory from the same |
a10db50a4 NFS: Fix an Oops ... |
53 54 55 56 |
* filesystem gets mounted at a later time. * This again causes shrink_dcache_for_umount_subtree() to * Oops, since the test for IS_ROOT() will fail. */ |
2b0143b5c VFS: normal files... |
57 |
spin_lock(&d_inode(sb->s_root)->i_lock); |
b23fb0a60 fs: scale inode a... |
58 |
spin_lock(&sb->s_root->d_lock); |
946e51f2b move d_rcu from o... |
59 |
hlist_del_init(&sb->s_root->d_u.d_alias); |
b23fb0a60 fs: scale inode a... |
60 |
spin_unlock(&sb->s_root->d_lock); |
2b0143b5c VFS: normal files... |
61 |
spin_unlock(&d_inode(sb->s_root)->i_lock); |
b09b9417d NFS: Fix the usta... |
62 63 64 65 66 |
} return 0; } /* |
54ceac451 NFS: Share NFS su... |
67 68 |
* get an NFS2/NFS3 root dentry from the root filehandle */ |
0d5839ad0 nfs: propagate de... |
69 70 |
struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh, const char *devname) |
54ceac451 NFS: Share NFS su... |
71 72 73 |
{ struct nfs_server *server = NFS_SB(sb); struct nfs_fsinfo fsinfo; |
8bac9db9c NFSv4: Reduce sta... |
74 |
struct dentry *ret; |
54ceac451 NFS: Share NFS su... |
75 |
struct inode *inode; |
b1942c5f8 nfs: store devnam... |
76 |
void *name = kstrdup(devname, GFP_KERNEL); |
54ceac451 NFS: Share NFS su... |
77 |
int error; |
b1942c5f8 nfs: store devnam... |
78 79 |
if (!name) return ERR_PTR(-ENOMEM); |
54ceac451 NFS: Share NFS su... |
80 |
/* get the actual root for this mount */ |
8bac9db9c NFSv4: Reduce sta... |
81 |
fsinfo.fattr = nfs_alloc_fattr(); |
b1942c5f8 nfs: store devnam... |
82 83 |
if (fsinfo.fattr == NULL) { kfree(name); |
8bac9db9c NFSv4: Reduce sta... |
84 |
return ERR_PTR(-ENOMEM); |
b1942c5f8 nfs: store devnam... |
85 |
} |
54ceac451 NFS: Share NFS su... |
86 87 88 89 90 |
error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo); if (error < 0) { dprintk("nfs_get_root: getattr error = %d ", -error); |
8bac9db9c NFSv4: Reduce sta... |
91 92 |
ret = ERR_PTR(error); goto out; |
54ceac451 NFS: Share NFS su... |
93 |
} |
1775fd3e8 NFS:Add labels to... |
94 |
inode = nfs_fhget(sb, mntfh, fsinfo.fattr, NULL); |
54ceac451 NFS: Share NFS su... |
95 96 97 |
if (IS_ERR(inode)) { dprintk("nfs_get_root: get root inode failed "); |
8bac9db9c NFSv4: Reduce sta... |
98 99 |
ret = ERR_CAST(inode); goto out; |
54ceac451 NFS: Share NFS su... |
100 |
} |
b09b9417d NFS: Fix the usta... |
101 |
error = nfs_superblock_set_dummy_root(sb, inode); |
8bac9db9c NFSv4: Reduce sta... |
102 103 104 105 |
if (error != 0) { ret = ERR_PTR(error); goto out; } |
b09b9417d NFS: Fix the usta... |
106 |
|
54ceac451 NFS: Share NFS su... |
107 108 109 110 |
/* root dentries normally start off anonymous and get spliced in later * if the dentry tree reaches them; however if the dentry already * exists, we'll pick it up at this point and use it as the root */ |
1a0a397e4 dcache: d_obtain_... |
111 |
ret = d_obtain_root(inode); |
8bac9db9c NFSv4: Reduce sta... |
112 |
if (IS_ERR(ret)) { |
54ceac451 NFS: Share NFS su... |
113 114 |
dprintk("nfs_get_root: get root dentry failed "); |
8bac9db9c NFSv4: Reduce sta... |
115 |
goto out; |
54ceac451 NFS: Share NFS su... |
116 |
} |
8bac9db9c NFSv4: Reduce sta... |
117 |
security_d_instantiate(ret, inode); |
b1942c5f8 nfs: store devnam... |
118 |
spin_lock(&ret->d_lock); |
4dfc7fdb9 NFS: Fix memroy l... |
119 120 |
if (IS_ROOT(ret) && !ret->d_fsdata && !(ret->d_flags & DCACHE_NFSFS_RENAMED)) { |
b1942c5f8 nfs: store devnam... |
121 122 123 124 |
ret->d_fsdata = name; name = NULL; } spin_unlock(&ret->d_lock); |
8bac9db9c NFSv4: Reduce sta... |
125 |
out: |
96aa1549a nfs: remove kfree... |
126 |
kfree(name); |
8bac9db9c NFSv4: Reduce sta... |
127 128 |
nfs_free_fattr(fsinfo.fattr); return ret; |
54ceac451 NFS: Share NFS su... |
129 |
} |