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 | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 151 | static struct rpc_clnt *nfs_lookup_mountpoint(struct inode *dir, |
| 152 | struct qstr *name, |
| 153 | struct nfs_fh *fh, |
| 154 | struct nfs_fattr *fattr) |
| 155 | { |
| 156 | int err; |
| 157 | |
| 158 | if (NFS_PROTO(dir)->version == 4) |
| 159 | return nfs4_proc_lookup_mountpoint(dir, name, fh, fattr); |
| 160 | |
| 161 | err = NFS_PROTO(dir)->lookup(NFS_SERVER(dir)->client, dir, name, fh, fattr); |
| 162 | if (err) |
| 163 | return ERR_PTR(err); |
| 164 | return rpc_clone_client(NFS_SERVER(dir)->client); |
| 165 | } |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 166 | #else /* CONFIG_NFS_V4 */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 167 | static inline struct rpc_clnt *nfs_lookup_mountpoint(struct inode *dir, |
| 168 | struct qstr *name, |
| 169 | struct nfs_fh *fh, |
| 170 | struct nfs_fattr *fattr) |
| 171 | { |
| 172 | int err = NFS_PROTO(dir)->lookup(NFS_SERVER(dir)->client, dir, name, fh, fattr); |
| 173 | if (err) |
| 174 | return ERR_PTR(err); |
| 175 | return rpc_clone_client(NFS_SERVER(dir)->client); |
| 176 | } |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 177 | #endif /* CONFIG_NFS_V4 */ |
| 178 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 179 | /* |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 180 | * nfs_d_automount - Handle crossing a mountpoint on the server |
| 181 | * @path - The mountpoint |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 182 | * |
| 183 | * When we encounter a mountpoint on the server, we want to set up |
| 184 | * a mountpoint on the client too, to prevent inode numbers from |
| 185 | * colliding, and to allow "df" to work properly. |
| 186 | * On NFSv4, we also want to allow for the fact that different |
| 187 | * filesystems may be migrated to different servers in a failover |
| 188 | * situation, and that different filesystems may want to use |
| 189 | * different security flavours. |
| 190 | */ |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 191 | struct vfsmount *nfs_d_automount(struct path *path) |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 192 | { |
| 193 | struct vfsmount *mnt; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 194 | struct dentry *parent; |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 195 | struct nfs_fh *fh = NULL; |
| 196 | struct nfs_fattr *fattr = NULL; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 197 | struct rpc_clnt *client; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 198 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 199 | dprintk("--> nfs_d_automount()\n"); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 200 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 201 | mnt = ERR_PTR(-ESTALE); |
| 202 | if (IS_ROOT(path->dentry)) |
| 203 | goto out_nofree; |
Denis V. Lunev | 44d5759 | 2008-08-11 12:02:34 +0400 | [diff] [blame] | 204 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 205 | mnt = ERR_PTR(-ENOMEM); |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 206 | fh = nfs_alloc_fhandle(); |
| 207 | fattr = nfs_alloc_fattr(); |
| 208 | if (fh == NULL || fattr == NULL) |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 209 | goto out; |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 210 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 211 | dprintk("%s: enter\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 212 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 213 | /* Look it up again to get its attributes */ |
| 214 | parent = dget_parent(path->dentry); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 215 | client = nfs_lookup_mountpoint(parent->d_inode, &path->dentry->d_name, fh, fattr); |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 216 | dput(parent); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 217 | if (IS_ERR(client)) { |
| 218 | mnt = ERR_CAST(client); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 219 | goto out; |
| 220 | } |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 221 | |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 222 | if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 223 | mnt = nfs_do_refmount(client, path->dentry); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 224 | else |
Bryan Schumaker | 7e6eb68 | 2012-04-27 13:27:42 -0400 | [diff] [blame] | 225 | mnt = nfs_do_submount(path->dentry, fh, fattr, client->cl_auth->au_flavor); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 226 | rpc_shutdown_client(client); |
| 227 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 228 | if (IS_ERR(mnt)) |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 229 | goto out; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 230 | |
David Howells | ea5b778 | 2011-01-14 19:10:03 +0000 | [diff] [blame] | 231 | dprintk("%s: done, success\n", __func__); |
| 232 | mntget(mnt); /* prevent immediate expiration */ |
| 233 | mnt_set_expiry(mnt, &nfs_automount_list); |
| 234 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 235 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 236 | out: |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 237 | nfs_free_fattr(fattr); |
| 238 | nfs_free_fhandle(fh); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 239 | out_nofree: |
Chuck Lever | d7c3267 | 2012-02-15 16:35:17 -0500 | [diff] [blame] | 240 | if (IS_ERR(mnt)) |
| 241 | dprintk("<-- %s(): error %ld\n", __func__, PTR_ERR(mnt)); |
| 242 | else |
| 243 | dprintk("<-- %s() = %p\n", __func__, mnt); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 244 | return mnt; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 247 | const struct inode_operations nfs_mountpoint_inode_operations = { |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 248 | .getattr = nfs_getattr, |
| 249 | }; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 250 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 251 | const struct inode_operations nfs_referral_inode_operations = { |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 252 | }; |
| 253 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 254 | static void nfs_expire_automounts(struct work_struct *work) |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 255 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 256 | struct list_head *list = &nfs_automount_list; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 257 | |
| 258 | mark_mounts_for_expiry(list); |
| 259 | if (!list_empty(list)) |
| 260 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
| 261 | } |
| 262 | |
| 263 | void nfs_release_automount_timer(void) |
| 264 | { |
Trond Myklebust | 3d39c69 | 2007-08-07 15:28:33 -0400 | [diff] [blame] | 265 | if (list_empty(&nfs_automount_list)) |
Trond Myklebust | 560aef7 | 2007-08-27 09:14:56 -0400 | [diff] [blame] | 266 | cancel_delayed_work(&nfs_automount_task); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 267 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 268 | |
| 269 | /* |
| 270 | * Clone a mountpoint of the appropriate type |
| 271 | */ |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 272 | static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server, |
| 273 | const char *devname, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 274 | struct nfs_clone_mount *mountdata) |
| 275 | { |
| 276 | #ifdef CONFIG_NFS_V4 |
Denis V. Lunev | fd08d7e | 2008-07-31 09:38:55 +0400 | [diff] [blame] | 277 | struct vfsmount *mnt = ERR_PTR(-EINVAL); |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 278 | switch (server->nfs_client->rpc_ops->version) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 279 | case 2: |
| 280 | case 3: |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 281 | mnt = vfs_kern_mount(&nfs_xdev_fs_type, 0, devname, mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 282 | break; |
| 283 | case 4: |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 284 | mnt = vfs_kern_mount(&nfs4_xdev_fs_type, 0, devname, mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 285 | } |
| 286 | return mnt; |
| 287 | #else |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 288 | return vfs_kern_mount(&nfs_xdev_fs_type, 0, devname, mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 289 | #endif |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 294 | * @dentry - parent directory |
| 295 | * @fh - filehandle for new root dentry |
| 296 | * @fattr - attributes for new root inode |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 297 | * @authflavor - security flavor to use when performing the mount |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 298 | * |
| 299 | */ |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 300 | static struct vfsmount *nfs_do_submount(struct dentry *dentry, |
Adrian Bunk | 66f3750 | 2006-09-27 01:51:13 -0700 | [diff] [blame] | 301 | struct nfs_fh *fh, |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 302 | struct nfs_fattr *fattr, |
| 303 | rpc_authflavor_t authflavor) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 304 | { |
| 305 | struct nfs_clone_mount mountdata = { |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 306 | .sb = dentry->d_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 307 | .dentry = dentry, |
| 308 | .fh = fh, |
| 309 | .fattr = fattr, |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 310 | .authflavor = authflavor, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 311 | }; |
| 312 | struct vfsmount *mnt = ERR_PTR(-ENOMEM); |
| 313 | char *page = (char *) __get_free_page(GFP_USER); |
| 314 | char *devname; |
| 315 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 316 | dprintk("--> nfs_do_submount()\n"); |
| 317 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 318 | dprintk("%s: submounting on %s/%s\n", __func__, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 319 | dentry->d_parent->d_name.name, |
| 320 | dentry->d_name.name); |
| 321 | if (page == NULL) |
| 322 | goto out; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 323 | devname = nfs_devname(dentry, page, PAGE_SIZE); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 324 | mnt = (struct vfsmount *)devname; |
| 325 | if (IS_ERR(devname)) |
| 326 | goto free_page; |
Al Viro | f8ad9c4 | 2011-03-16 06:32:07 -0400 | [diff] [blame] | 327 | mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 328 | free_page: |
| 329 | free_page((unsigned long)page); |
| 330 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 331 | dprintk("%s: done\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 332 | |
| 333 | dprintk("<-- nfs_do_submount() = %p\n", mnt); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 334 | return mnt; |
| 335 | } |