Blame view
fs/nfs/namespace.c
7.35 KB
55a975937 NFS: Ensure the c... |
1 2 3 4 |
/* * linux/fs/nfs/namespace.c * * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com> |
54ceac451 NFS: Share NFS su... |
5 |
* - Modified by David Howells <dhowells@redhat.com> |
55a975937 NFS: Ensure the c... |
6 7 8 |
* * NFS namespace */ |
ddda8e0aa NFS: Convert v2 i... |
9 |
#include <linux/module.h> |
55a975937 NFS: Ensure the c... |
10 |
#include <linux/dcache.h> |
5a0e3ad6a include cleanup: ... |
11 |
#include <linux/gfp.h> |
55a975937 NFS: Ensure the c... |
12 13 14 15 16 17 |
#include <linux/mount.h> #include <linux/namei.h> #include <linux/nfs_fs.h> #include <linux/string.h> #include <linux/sunrpc/clnt.h> #include <linux/vfs.h> |
7ebb93159 NFS: use secinfo ... |
18 |
#include <linux/sunrpc/gss_api.h> |
f7b422b17 NFS: Split fs/nfs... |
19 |
#include "internal.h" |
55a975937 NFS: Ensure the c... |
20 21 |
#define NFSDBG_FACILITY NFSDBG_VFS |
65f27f384 WorkStruct: Pass ... |
22 |
static void nfs_expire_automounts(struct work_struct *work); |
f7b422b17 NFS: Split fs/nfs... |
23 |
|
a3dab2935 make nfs_automoun... |
24 |
static LIST_HEAD(nfs_automount_list); |
65f27f384 WorkStruct: Pass ... |
25 |
static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); |
51d8fa6a1 NFS: Add timeout ... |
26 |
int nfs_mountpoint_expiry_timeout = 500 * HZ; |
55a975937 NFS: Ensure the c... |
27 |
/* |
f7b422b17 NFS: Split fs/nfs... |
28 |
* nfs_path - reconstruct the path given an arbitrary dentry |
b514f872f nfs: make nfs_pat... |
29 |
* @base - used to return pointer to the end of devname part of path |
f7b422b17 NFS: Split fs/nfs... |
30 31 32 |
* @dentry - pointer to dentry * @buffer - result buffer * @buflen - length of buffer |
97a548682 nfs: Show origina... |
33 |
* @flags - options (see below) |
f7b422b17 NFS: Split fs/nfs... |
34 |
* |
b514f872f nfs: make nfs_pat... |
35 36 |
* Helper function for constructing the server pathname * by arbitrary hashed dentry. |
f7b422b17 NFS: Split fs/nfs... |
37 38 |
* * This is mainly for use in figuring out the path on the |
b514f872f nfs: make nfs_pat... |
39 40 |
* server side when automounting on top of an existing partition * and in generating /proc/mounts and friends. |
97a548682 nfs: Show origina... |
41 42 43 44 45 |
* * Supported flags: * NFS_PATH_CANONICAL: ensure there is exactly one slash after * the original device (export) name * (if unset, the original name is returned verbatim) |
f7b422b17 NFS: Split fs/nfs... |
46 |
*/ |
97a548682 nfs: Show origina... |
47 48 |
char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen, unsigned flags) |
f7b422b17 NFS: Split fs/nfs... |
49 |
{ |
949854d02 fs: Use rename lo... |
50 |
char *end; |
f7b422b17 NFS: Split fs/nfs... |
51 |
int namelen; |
949854d02 fs: Use rename lo... |
52 |
unsigned seq; |
b514f872f nfs: make nfs_pat... |
53 |
const char *base; |
f7b422b17 NFS: Split fs/nfs... |
54 |
|
949854d02 fs: Use rename lo... |
55 56 |
rename_retry: end = buffer+buflen; |
f7b422b17 NFS: Split fs/nfs... |
57 58 |
*--end = '\0'; buflen--; |
949854d02 fs: Use rename lo... |
59 60 61 |
seq = read_seqbegin(&rename_lock); rcu_read_lock(); |
b514f872f nfs: make nfs_pat... |
62 63 64 65 |
while (1) { spin_lock(&dentry->d_lock); if (IS_ROOT(dentry)) break; |
f7b422b17 NFS: Split fs/nfs... |
66 67 68 |
namelen = dentry->d_name.len; buflen -= namelen + 1; if (buflen < 0) |
ce5101932 NFS: Release dcac... |
69 |
goto Elong_unlock; |
f7b422b17 NFS: Split fs/nfs... |
70 71 72 |
end -= namelen; memcpy(end, dentry->d_name.name, namelen); *--end = '/'; |
b514f872f nfs: make nfs_pat... |
73 |
spin_unlock(&dentry->d_lock); |
f7b422b17 NFS: Split fs/nfs... |
74 75 |
dentry = dentry->d_parent; } |
b514f872f nfs: make nfs_pat... |
76 77 78 |
if (read_seqretry(&rename_lock, seq)) { spin_unlock(&dentry->d_lock); rcu_read_unlock(); |
949854d02 fs: Use rename lo... |
79 |
goto rename_retry; |
b514f872f nfs: make nfs_pat... |
80 |
} |
97a548682 nfs: Show origina... |
81 |
if ((flags & NFS_PATH_CANONICAL) && *end != '/') { |
b514f872f nfs: make nfs_pat... |
82 83 84 |
if (--buflen < 0) { spin_unlock(&dentry->d_lock); rcu_read_unlock(); |
0b75b35c7 NFS: Fix nfs_path... |
85 |
goto Elong; |
b514f872f nfs: make nfs_pat... |
86 |
} |
0b75b35c7 NFS: Fix nfs_path... |
87 88 |
*--end = '/'; } |
b514f872f nfs: make nfs_pat... |
89 90 91 92 93 94 95 96 |
*p = end; base = dentry->d_fsdata; if (!base) { spin_unlock(&dentry->d_lock); rcu_read_unlock(); WARN_ON(1); return end; } |
f7b422b17 NFS: Split fs/nfs... |
97 |
namelen = strlen(base); |
97a548682 nfs: Show origina... |
98 99 100 101 102 |
if (flags & NFS_PATH_CANONICAL) { /* Strip off excess slashes in base string */ while (namelen > 0 && base[namelen - 1] == '/') namelen--; } |
f7b422b17 NFS: Split fs/nfs... |
103 |
buflen -= namelen; |
b514f872f nfs: make nfs_pat... |
104 |
if (buflen < 0) { |
1c34092ad nfs: lock() vs un... |
105 |
spin_unlock(&dentry->d_lock); |
b514f872f nfs: make nfs_pat... |
106 |
rcu_read_unlock(); |
f7b422b17 NFS: Split fs/nfs... |
107 |
goto Elong; |
b514f872f nfs: make nfs_pat... |
108 |
} |
f7b422b17 NFS: Split fs/nfs... |
109 110 |
end -= namelen; memcpy(end, base, namelen); |
b514f872f nfs: make nfs_pat... |
111 112 |
spin_unlock(&dentry->d_lock); rcu_read_unlock(); |
f7b422b17 NFS: Split fs/nfs... |
113 |
return end; |
ce5101932 NFS: Release dcac... |
114 |
Elong_unlock: |
1c34092ad nfs: lock() vs un... |
115 |
spin_unlock(&dentry->d_lock); |
949854d02 fs: Use rename lo... |
116 117 118 |
rcu_read_unlock(); if (read_seqretry(&rename_lock, seq)) goto rename_retry; |
f7b422b17 NFS: Split fs/nfs... |
119 120 121 |
Elong: return ERR_PTR(-ENAMETOOLONG); } |
89d77c8fa NFS: Convert v4 i... |
122 |
EXPORT_SYMBOL_GPL(nfs_path); |
f7b422b17 NFS: Split fs/nfs... |
123 124 |
/* |
36d43a437 NFS: Use d_automo... |
125 126 |
* nfs_d_automount - Handle crossing a mountpoint on the server * @path - The mountpoint |
55a975937 NFS: Ensure the c... |
127 128 129 130 131 132 133 134 135 |
* * When we encounter a mountpoint on the server, we want to set up * a mountpoint on the client too, to prevent inode numbers from * colliding, and to allow "df" to work properly. * On NFSv4, we also want to allow for the fact that different * filesystems may be migrated to different servers in a failover * situation, and that different filesystems may want to use * different security flavours. */ |
36d43a437 NFS: Use d_automo... |
136 |
struct vfsmount *nfs_d_automount(struct path *path) |
55a975937 NFS: Ensure the c... |
137 138 |
{ struct vfsmount *mnt; |
2b0143b5c VFS: normal files... |
139 |
struct nfs_server *server = NFS_SERVER(d_inode(path->dentry)); |
a4d7f1680 NFS: Reduce the s... |
140 141 |
struct nfs_fh *fh = NULL; struct nfs_fattr *fattr = NULL; |
55a975937 NFS: Ensure the c... |
142 |
|
36d43a437 NFS: Use d_automo... |
143 144 |
dprintk("--> nfs_d_automount() "); |
54ceac451 NFS: Share NFS su... |
145 |
|
36d43a437 NFS: Use d_automo... |
146 147 148 |
mnt = ERR_PTR(-ESTALE); if (IS_ROOT(path->dentry)) goto out_nofree; |
44d5759d3 nfs: BUG_ON in nf... |
149 |
|
36d43a437 NFS: Use d_automo... |
150 |
mnt = ERR_PTR(-ENOMEM); |
a4d7f1680 NFS: Reduce the s... |
151 152 153 |
fh = nfs_alloc_fhandle(); fattr = nfs_alloc_fattr(); if (fh == NULL || fattr == NULL) |
36d43a437 NFS: Use d_automo... |
154 |
goto out; |
a4d7f1680 NFS: Reduce the s... |
155 |
|
3110ff804 nfs: replace rema... |
156 157 |
dprintk("%s: enter ", __func__); |
54ceac451 NFS: Share NFS su... |
158 |
|
281cad46b NFS: Create a sub... |
159 |
mnt = server->nfs_client->rpc_ops->submount(server, path->dentry, fh, fattr); |
55a975937 NFS: Ensure the c... |
160 |
if (IS_ERR(mnt)) |
36d43a437 NFS: Use d_automo... |
161 |
goto out; |
55a975937 NFS: Ensure the c... |
162 |
|
ea5b778a8 Unexport do_add_m... |
163 164 165 166 167 |
dprintk("%s: done, success ", __func__); mntget(mnt); /* prevent immediate expiration */ mnt_set_expiry(mnt, &nfs_automount_list); schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
36d43a437 NFS: Use d_automo... |
168 |
|
55a975937 NFS: Ensure the c... |
169 |
out: |
a4d7f1680 NFS: Reduce the s... |
170 171 |
nfs_free_fattr(fattr); nfs_free_fhandle(fh); |
36d43a437 NFS: Use d_automo... |
172 |
out_nofree: |
d7c326750 nfs: Clean up deb... |
173 174 175 176 177 178 |
if (IS_ERR(mnt)) dprintk("<-- %s(): error %ld ", __func__, PTR_ERR(mnt)); else dprintk("<-- %s() = %p ", __func__, mnt); |
36d43a437 NFS: Use d_automo... |
179 |
return mnt; |
55a975937 NFS: Ensure the c... |
180 |
} |
ab2254178 NFS: Don't silent... |
181 182 183 |
static int nfs_namespace_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) { |
2b0143b5c VFS: normal files... |
184 |
if (NFS_FH(d_inode(dentry))->size != 0) |
ab2254178 NFS: Don't silent... |
185 |
return nfs_getattr(mnt, dentry, stat); |
2b0143b5c VFS: normal files... |
186 |
generic_fillattr(d_inode(dentry), stat); |
ab2254178 NFS: Don't silent... |
187 188 189 190 191 192 |
return 0; } static int nfs_namespace_setattr(struct dentry *dentry, struct iattr *attr) { |
2b0143b5c VFS: normal files... |
193 |
if (NFS_FH(d_inode(dentry))->size != 0) |
ab2254178 NFS: Don't silent... |
194 195 196 |
return nfs_setattr(dentry, attr); return -EACCES; } |
92e1d5be9 [PATCH] mark stru... |
197 |
const struct inode_operations nfs_mountpoint_inode_operations = { |
55a975937 NFS: Ensure the c... |
198 |
.getattr = nfs_getattr, |
ab2254178 NFS: Don't silent... |
199 |
.setattr = nfs_setattr, |
55a975937 NFS: Ensure the c... |
200 |
}; |
51d8fa6a1 NFS: Add timeout ... |
201 |
|
92e1d5be9 [PATCH] mark stru... |
202 |
const struct inode_operations nfs_referral_inode_operations = { |
ab2254178 NFS: Don't silent... |
203 204 |
.getattr = nfs_namespace_getattr, .setattr = nfs_namespace_setattr, |
6b97fd3da NFSv4: Follow a r... |
205 |
}; |
65f27f384 WorkStruct: Pass ... |
206 |
static void nfs_expire_automounts(struct work_struct *work) |
51d8fa6a1 NFS: Add timeout ... |
207 |
{ |
65f27f384 WorkStruct: Pass ... |
208 |
struct list_head *list = &nfs_automount_list; |
51d8fa6a1 NFS: Add timeout ... |
209 210 211 212 213 214 215 216 |
mark_mounts_for_expiry(list); if (!list_empty(list)) schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); } void nfs_release_automount_timer(void) { |
3d39c691f NFS: Replace flus... |
217 |
if (list_empty(&nfs_automount_list)) |
560aef745 NFS: Fix use of c... |
218 |
cancel_delayed_work(&nfs_automount_task); |
51d8fa6a1 NFS: Add timeout ... |
219 |
} |
f7b422b17 NFS: Split fs/nfs... |
220 221 222 223 |
/* * Clone a mountpoint of the appropriate type */ |
509de8111 NFS: Add extra co... |
224 225 |
static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server, const char *devname, |
f7b422b17 NFS: Split fs/nfs... |
226 227 |
struct nfs_clone_mount *mountdata) { |
54ceac451 NFS: Share NFS su... |
228 |
return vfs_kern_mount(&nfs_xdev_fs_type, 0, devname, mountdata); |
f7b422b17 NFS: Split fs/nfs... |
229 230 231 232 |
} /** * nfs_do_submount - set up mountpoint when crossing a filesystem boundary |
f7b422b17 NFS: Split fs/nfs... |
233 234 235 |
* @dentry - parent directory * @fh - filehandle for new root dentry * @fattr - attributes for new root inode |
7ebb93159 NFS: use secinfo ... |
236 |
* @authflavor - security flavor to use when performing the mount |
f7b422b17 NFS: Split fs/nfs... |
237 238 |
* */ |
281cad46b NFS: Create a sub... |
239 240 |
struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr, rpc_authflavor_t authflavor) |
f7b422b17 NFS: Split fs/nfs... |
241 242 |
{ struct nfs_clone_mount mountdata = { |
f8ad9c4ba nfs: nfs_do_{ref,... |
243 |
.sb = dentry->d_sb, |
f7b422b17 NFS: Split fs/nfs... |
244 245 246 |
.dentry = dentry, .fh = fh, .fattr = fattr, |
7ebb93159 NFS: use secinfo ... |
247 |
.authflavor = authflavor, |
f7b422b17 NFS: Split fs/nfs... |
248 249 250 251 |
}; struct vfsmount *mnt = ERR_PTR(-ENOMEM); char *page = (char *) __get_free_page(GFP_USER); char *devname; |
54ceac451 NFS: Share NFS su... |
252 253 |
dprintk("--> nfs_do_submount() "); |
6de1472f1 nfs: use %p[dD] i... |
254 255 256 |
dprintk("%s: submounting on %pd2 ", __func__, dentry); |
f7b422b17 NFS: Split fs/nfs... |
257 258 |
if (page == NULL) goto out; |
b514f872f nfs: make nfs_pat... |
259 |
devname = nfs_devname(dentry, page, PAGE_SIZE); |
f7b422b17 NFS: Split fs/nfs... |
260 261 262 |
mnt = (struct vfsmount *)devname; if (IS_ERR(devname)) goto free_page; |
f8ad9c4ba nfs: nfs_do_{ref,... |
263 |
mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata); |
f7b422b17 NFS: Split fs/nfs... |
264 265 266 |
free_page: free_page((unsigned long)page); out: |
3110ff804 nfs: replace rema... |
267 268 |
dprintk("%s: done ", __func__); |
54ceac451 NFS: Share NFS su... |
269 270 271 |
dprintk("<-- nfs_do_submount() = %p ", mnt); |
f7b422b17 NFS: Split fs/nfs... |
272 273 |
return mnt; } |
89d77c8fa NFS: Convert v4 i... |
274 |
EXPORT_SYMBOL_GPL(nfs_do_submount); |
281cad46b NFS: Create a sub... |
275 276 277 278 279 280 281 282 |
struct vfsmount *nfs_submount(struct nfs_server *server, struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr) { int err; struct dentry *parent = dget_parent(dentry); /* Look it up again to get its attributes */ |
2b0143b5c VFS: normal files... |
283 |
err = server->nfs_client->rpc_ops->lookup(d_inode(parent), &dentry->d_name, fh, fattr, NULL); |
281cad46b NFS: Create a sub... |
284 285 286 287 288 289 |
dput(parent); if (err != 0) return ERR_PTR(err); return nfs_do_submount(dentry, fh, fattr, server->client->cl_auth->au_flavor); } |
ddda8e0aa NFS: Convert v2 i... |
290 |
EXPORT_SYMBOL_GPL(nfs_submount); |