Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/namespace.c |
| 3 | * |
| 4 | * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com> |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 5 | * - Modified by David Howells <dhowells@redhat.com> |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 6 | * |
| 7 | * NFS namespace |
| 8 | */ |
| 9 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 10 | #include <linux/dcache.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/gfp.h> |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 12 | #include <linux/mount.h> |
| 13 | #include <linux/namei.h> |
| 14 | #include <linux/nfs_fs.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/sunrpc/clnt.h> |
| 17 | #include <linux/vfs.h> |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 18 | #include <linux/sunrpc/gss_api.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 19 | #include "internal.h" |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 20 | |
| 21 | #define NFSDBG_FACILITY NFSDBG_VFS |
| 22 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 23 | static void nfs_expire_automounts(struct work_struct *work); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 24 | |
Adrian Bunk | a3dab29 | 2008-04-14 21:41:32 +0300 | [diff] [blame] | 25 | static LIST_HEAD(nfs_automount_list); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 26 | static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 27 | int nfs_mountpoint_expiry_timeout = 500 * HZ; |
| 28 | |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 29 | static struct vfsmount *nfs_do_submount(struct dentry *dentry, |
Adrian Bunk | 66f3750 | 2006-09-27 01:51:13 -0700 | [diff] [blame] | 30 | struct nfs_fh *fh, |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 31 | struct nfs_fattr *fattr, |
| 32 | rpc_authflavor_t authflavor); |
Adrian Bunk | 66f3750 | 2006-09-27 01:51:13 -0700 | [diff] [blame] | 33 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 34 | /* |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 35 | * nfs_path - reconstruct the path given an arbitrary dentry |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 36 | * @base - used to return pointer to the end of devname part of path |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 37 | * @dentry - pointer to dentry |
| 38 | * @buffer - result buffer |
| 39 | * @buflen - length of buffer |
| 40 | * |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 41 | * Helper function for constructing the server pathname |
| 42 | * by arbitrary hashed dentry. |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 43 | * |
| 44 | * This is mainly for use in figuring out the path on the |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 45 | * server side when automounting on top of an existing partition |
| 46 | * and in generating /proc/mounts and friends. |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 47 | */ |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 48 | char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 49 | { |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 50 | char *end; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 51 | int namelen; |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 52 | unsigned seq; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 53 | const char *base; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 54 | |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 55 | rename_retry: |
| 56 | end = buffer+buflen; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 57 | *--end = '\0'; |
| 58 | buflen--; |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 59 | |
| 60 | seq = read_seqbegin(&rename_lock); |
| 61 | rcu_read_lock(); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 62 | while (1) { |
| 63 | spin_lock(&dentry->d_lock); |
| 64 | if (IS_ROOT(dentry)) |
| 65 | break; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 66 | namelen = dentry->d_name.len; |
| 67 | buflen -= namelen + 1; |
| 68 | if (buflen < 0) |
Josh Triplett | ce51019 | 2006-07-24 16:30:00 -0700 | [diff] [blame] | 69 | goto Elong_unlock; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 70 | end -= namelen; |
| 71 | memcpy(end, dentry->d_name.name, namelen); |
| 72 | *--end = '/'; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 73 | spin_unlock(&dentry->d_lock); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 74 | dentry = dentry->d_parent; |
| 75 | } |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 76 | if (read_seqretry(&rename_lock, seq)) { |
| 77 | spin_unlock(&dentry->d_lock); |
| 78 | rcu_read_unlock(); |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 79 | goto rename_retry; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 80 | } |
Trond Myklebust | 0b75b35 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 81 | if (*end != '/') { |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 82 | if (--buflen < 0) { |
| 83 | spin_unlock(&dentry->d_lock); |
| 84 | rcu_read_unlock(); |
Trond Myklebust | 0b75b35 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 85 | goto Elong; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 86 | } |
Trond Myklebust | 0b75b35 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 87 | *--end = '/'; |
| 88 | } |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 89 | *p = end; |
| 90 | base = dentry->d_fsdata; |
| 91 | if (!base) { |
| 92 | spin_unlock(&dentry->d_lock); |
| 93 | rcu_read_unlock(); |
| 94 | WARN_ON(1); |
| 95 | return end; |
| 96 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 97 | namelen = strlen(base); |
| 98 | /* Strip off excess slashes in base string */ |
| 99 | while (namelen > 0 && base[namelen - 1] == '/') |
| 100 | namelen--; |
| 101 | buflen -= namelen; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 102 | if (buflen < 0) { |
Dan Carpenter | 1c34092 | 2011-03-20 14:22:07 +0300 | [diff] [blame] | 103 | spin_unlock(&dentry->d_lock); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 104 | rcu_read_unlock(); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 105 | goto Elong; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 106 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 107 | end -= namelen; |
| 108 | memcpy(end, base, namelen); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 109 | spin_unlock(&dentry->d_lock); |
| 110 | rcu_read_unlock(); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 111 | return end; |
Josh Triplett | ce51019 | 2006-07-24 16:30:00 -0700 | [diff] [blame] | 112 | Elong_unlock: |
Dan Carpenter | 1c34092 | 2011-03-20 14:22:07 +0300 | [diff] [blame] | 113 | spin_unlock(&dentry->d_lock); |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 114 | rcu_read_unlock(); |
| 115 | if (read_seqretry(&rename_lock, seq)) |
| 116 | goto rename_retry; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 117 | Elong: |
| 118 | return ERR_PTR(-ENAMETOOLONG); |
| 119 | } |
| 120 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 121 | #ifdef CONFIG_NFS_V4 |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 122 | rpc_authflavor_t nfs_find_best_sec(struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 123 | { |
| 124 | struct gss_api_mech *mech; |
| 125 | struct xdr_netobj oid; |
| 126 | int i; |
| 127 | rpc_authflavor_t pseudoflavor = RPC_AUTH_UNIX; |
| 128 | |
| 129 | for (i = 0; i < flavors->num_flavors; i++) { |
| 130 | struct nfs4_secinfo_flavor *flavor; |
| 131 | flavor = &flavors->flavors[i]; |
| 132 | |
| 133 | if (flavor->flavor == RPC_AUTH_NULL || flavor->flavor == RPC_AUTH_UNIX) { |
| 134 | pseudoflavor = flavor->flavor; |
| 135 | break; |
| 136 | } else if (flavor->flavor == RPC_AUTH_GSS) { |
| 137 | oid.len = flavor->gss.sec_oid4.len; |
| 138 | oid.data = flavor->gss.sec_oid4.data; |
| 139 | mech = gss_mech_get_by_OID(&oid); |
| 140 | if (!mech) |
| 141 | continue; |
| 142 | pseudoflavor = gss_svc_to_pseudoflavor(mech, flavor->gss.service); |
| 143 | gss_mech_put(mech); |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return pseudoflavor; |
| 149 | } |
| 150 | |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 151 | static int nfs_negotiate_security(const struct dentry *parent, |
| 152 | const struct dentry *dentry, |
| 153 | rpc_authflavor_t *flavor) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 155 | struct page *page; |
| 156 | struct nfs4_secinfo_flavors *flavors; |
| 157 | int (*secinfo)(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *); |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 158 | int ret = -EPERM; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 159 | |
| 160 | secinfo = NFS_PROTO(parent->d_inode)->secinfo; |
| 161 | if (secinfo != NULL) { |
| 162 | page = alloc_page(GFP_KERNEL); |
| 163 | if (!page) { |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 164 | ret = -ENOMEM; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 165 | goto out; |
| 166 | } |
| 167 | flavors = page_address(page); |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 168 | ret = secinfo(parent->d_inode, &dentry->d_name, flavors); |
Bryan Schumaker | 561f0b0 | 2011-04-12 08:47:15 -0400 | [diff] [blame] | 169 | *flavor = nfs_find_best_sec(flavors); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 170 | put_page(page); |
| 171 | } |
| 172 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 173 | out: |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 174 | return ret; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 177 | static int nfs_lookup_with_sec(struct nfs_server *server, struct dentry *parent, |
| 178 | struct dentry *dentry, struct path *path, |
| 179 | struct nfs_fh *fh, struct nfs_fattr *fattr, |
| 180 | rpc_authflavor_t *flavor) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 181 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 182 | struct rpc_clnt *clone; |
| 183 | struct rpc_auth *auth; |
| 184 | int err; |
| 185 | |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 186 | err = nfs_negotiate_security(parent, path->dentry, flavor); |
| 187 | if (err < 0) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 188 | goto out; |
| 189 | clone = rpc_clone_client(server->client); |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 190 | auth = rpcauth_create(*flavor, clone); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 191 | if (!auth) { |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 192 | err = -EIO; |
Trond Myklebust | a0e7e3c | 2011-03-26 02:24:35 -0400 | [diff] [blame] | 193 | goto out_shutdown; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 194 | } |
| 195 | err = server->nfs_client->rpc_ops->lookup(clone, parent->d_inode, |
| 196 | &path->dentry->d_name, |
| 197 | fh, fattr); |
Trond Myklebust | a0e7e3c | 2011-03-26 02:24:35 -0400 | [diff] [blame] | 198 | out_shutdown: |
| 199 | rpc_shutdown_client(clone); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 200 | out: |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 201 | return err; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 202 | } |
| 203 | #else /* CONFIG_NFS_V4 */ |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 204 | static inline int nfs_lookup_with_sec(struct nfs_server *server, |
| 205 | struct dentry *parent, struct dentry *dentry, |
| 206 | struct path *path, struct nfs_fh *fh, |
| 207 | struct nfs_fattr *fattr, |
| 208 | rpc_authflavor_t *flavor) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 209 | { |
| 210 | return -EPERM; |
| 211 | } |
| 212 | #endif /* CONFIG_NFS_V4 */ |
| 213 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 214 | /* |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 215 | * nfs_d_automount - Handle crossing a mountpoint on the server |
| 216 | * @path - The mountpoint |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 217 | * |
| 218 | * When we encounter a mountpoint on the server, we want to set up |
| 219 | * a mountpoint on the client too, to prevent inode numbers from |
| 220 | * colliding, and to allow "df" to work properly. |
| 221 | * On NFSv4, we also want to allow for the fact that different |
| 222 | * filesystems may be migrated to different servers in a failover |
| 223 | * situation, and that different filesystems may want to use |
| 224 | * different security flavours. |
| 225 | */ |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 226 | struct vfsmount *nfs_d_automount(struct path *path) |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 227 | { |
| 228 | struct vfsmount *mnt; |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 229 | struct nfs_server *server = NFS_SERVER(path->dentry->d_inode); |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 230 | struct dentry *parent; |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 231 | struct nfs_fh *fh = NULL; |
| 232 | struct nfs_fattr *fattr = NULL; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 233 | int err; |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 234 | rpc_authflavor_t flavor = RPC_AUTH_UNIX; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 235 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 236 | dprintk("--> nfs_d_automount()\n"); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 237 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 238 | mnt = ERR_PTR(-ESTALE); |
| 239 | if (IS_ROOT(path->dentry)) |
| 240 | goto out_nofree; |
Denis V. Lunev | 44d5759 | 2008-08-11 12:02:34 +0400 | [diff] [blame] | 241 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 242 | mnt = ERR_PTR(-ENOMEM); |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 243 | fh = nfs_alloc_fhandle(); |
| 244 | fattr = nfs_alloc_fattr(); |
| 245 | if (fh == NULL || fattr == NULL) |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 246 | goto out; |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 247 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 248 | dprintk("%s: enter\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 249 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 250 | /* Look it up again to get its attributes */ |
| 251 | parent = dget_parent(path->dentry); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 252 | err = server->nfs_client->rpc_ops->lookup(server->client, parent->d_inode, |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 253 | &path->dentry->d_name, |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 254 | fh, fattr); |
Bryan Schumaker | 4188759 | 2011-04-06 14:33:28 -0400 | [diff] [blame] | 255 | if (err == -EPERM && NFS_PROTO(parent->d_inode)->secinfo != NULL) |
| 256 | err = nfs_lookup_with_sec(server, parent, path->dentry, path, fh, fattr, &flavor); |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 257 | dput(parent); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 258 | if (err != 0) { |
| 259 | mnt = ERR_PTR(err); |
| 260 | goto out; |
| 261 | } |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 262 | |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 263 | if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 264 | mnt = nfs_do_refmount(path->dentry); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 265 | else |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 266 | mnt = nfs_do_submount(path->dentry, fh, fattr, flavor); |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 267 | if (IS_ERR(mnt)) |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 268 | goto out; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 269 | |
David Howells | ea5b778 | 2011-01-14 19:10:03 +0000 | [diff] [blame] | 270 | dprintk("%s: done, success\n", __func__); |
| 271 | mntget(mnt); /* prevent immediate expiration */ |
| 272 | mnt_set_expiry(mnt, &nfs_automount_list); |
| 273 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 274 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 275 | out: |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 276 | nfs_free_fattr(fattr); |
| 277 | nfs_free_fhandle(fh); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 278 | out_nofree: |
| 279 | dprintk("<-- nfs_follow_mountpoint() = %p\n", mnt); |
| 280 | return mnt; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 283 | const struct inode_operations nfs_mountpoint_inode_operations = { |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 284 | .getattr = nfs_getattr, |
| 285 | }; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 286 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 287 | const struct inode_operations nfs_referral_inode_operations = { |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 288 | }; |
| 289 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 290 | static void nfs_expire_automounts(struct work_struct *work) |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 291 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 292 | struct list_head *list = &nfs_automount_list; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 293 | |
| 294 | mark_mounts_for_expiry(list); |
| 295 | if (!list_empty(list)) |
| 296 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
| 297 | } |
| 298 | |
| 299 | void nfs_release_automount_timer(void) |
| 300 | { |
Trond Myklebust | 3d39c69 | 2007-08-07 15:28:33 -0400 | [diff] [blame] | 301 | if (list_empty(&nfs_automount_list)) |
Trond Myklebust | 560aef7 | 2007-08-27 09:14:56 -0400 | [diff] [blame] | 302 | cancel_delayed_work(&nfs_automount_task); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 303 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 304 | |
| 305 | /* |
| 306 | * Clone a mountpoint of the appropriate type |
| 307 | */ |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 308 | static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server, |
| 309 | const char *devname, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 310 | struct nfs_clone_mount *mountdata) |
| 311 | { |
| 312 | #ifdef CONFIG_NFS_V4 |
Denis V. Lunev | fd08d7e | 2008-07-31 09:38:55 +0400 | [diff] [blame] | 313 | struct vfsmount *mnt = ERR_PTR(-EINVAL); |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 314 | switch (server->nfs_client->rpc_ops->version) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 315 | case 2: |
| 316 | case 3: |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 317 | mnt = vfs_kern_mount(&nfs_xdev_fs_type, 0, devname, mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 318 | break; |
| 319 | case 4: |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 320 | mnt = vfs_kern_mount(&nfs4_xdev_fs_type, 0, devname, mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 321 | } |
| 322 | return mnt; |
| 323 | #else |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 324 | return vfs_kern_mount(&nfs_xdev_fs_type, 0, devname, mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 325 | #endif |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 330 | * @dentry - parent directory |
| 331 | * @fh - filehandle for new root dentry |
| 332 | * @fattr - attributes for new root inode |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 333 | * @authflavor - security flavor to use when performing the mount |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 334 | * |
| 335 | */ |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 336 | static struct vfsmount *nfs_do_submount(struct dentry *dentry, |
Adrian Bunk | 66f3750 | 2006-09-27 01:51:13 -0700 | [diff] [blame] | 337 | struct nfs_fh *fh, |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 338 | struct nfs_fattr *fattr, |
| 339 | rpc_authflavor_t authflavor) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 340 | { |
| 341 | struct nfs_clone_mount mountdata = { |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 342 | .sb = dentry->d_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 343 | .dentry = dentry, |
| 344 | .fh = fh, |
| 345 | .fattr = fattr, |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 346 | .authflavor = authflavor, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 347 | }; |
| 348 | struct vfsmount *mnt = ERR_PTR(-ENOMEM); |
| 349 | char *page = (char *) __get_free_page(GFP_USER); |
| 350 | char *devname; |
| 351 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 352 | dprintk("--> nfs_do_submount()\n"); |
| 353 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 354 | dprintk("%s: submounting on %s/%s\n", __func__, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 355 | dentry->d_parent->d_name.name, |
| 356 | dentry->d_name.name); |
| 357 | if (page == NULL) |
| 358 | goto out; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 359 | devname = nfs_devname(dentry, page, PAGE_SIZE); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 360 | mnt = (struct vfsmount *)devname; |
| 361 | if (IS_ERR(devname)) |
| 362 | goto free_page; |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 363 | mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 364 | free_page: |
| 365 | free_page((unsigned long)page); |
| 366 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 367 | dprintk("%s: done\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 368 | |
| 369 | dprintk("<-- nfs_do_submount() = %p\n", mnt); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 370 | return mnt; |
| 371 | } |