Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/nfs/namespace.c |
| 4 | * |
| 5 | * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com> |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 6 | * - Modified by David Howells <dhowells@redhat.com> |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 7 | * |
| 8 | * NFS namespace |
| 9 | */ |
| 10 | |
Bryan Schumaker | ddda8e0 | 2012-07-30 16:05:23 -0400 | [diff] [blame] | 11 | #include <linux/module.h> |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 12 | #include <linux/dcache.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/gfp.h> |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 14 | #include <linux/mount.h> |
| 15 | #include <linux/namei.h> |
| 16 | #include <linux/nfs_fs.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/sunrpc/clnt.h> |
| 19 | #include <linux/vfs.h> |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 20 | #include <linux/sunrpc/gss_api.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 21 | #include "internal.h" |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame^] | 22 | #include "nfs.h" |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 23 | |
| 24 | #define NFSDBG_FACILITY NFSDBG_VFS |
| 25 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 26 | static void nfs_expire_automounts(struct work_struct *work); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 27 | |
Adrian Bunk | a3dab29 | 2008-04-14 21:41:32 +0300 | [diff] [blame] | 28 | static LIST_HEAD(nfs_automount_list); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 29 | static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 30 | int nfs_mountpoint_expiry_timeout = 500 * HZ; |
| 31 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 32 | /* |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 33 | * nfs_path - reconstruct the path given an arbitrary dentry |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 34 | * @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] | 35 | * @dentry - pointer to dentry |
| 36 | * @buffer - result buffer |
| 37 | * @buflen - length of buffer |
Ben Hutchings | 97a5486 | 2012-10-21 19:23:52 +0100 | [diff] [blame] | 38 | * @flags - options (see below) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 39 | * |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 40 | * Helper function for constructing the server pathname |
| 41 | * by arbitrary hashed dentry. |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 42 | * |
| 43 | * This is mainly for use in figuring out the path on the |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 44 | * server side when automounting on top of an existing partition |
| 45 | * and in generating /proc/mounts and friends. |
Ben Hutchings | 97a5486 | 2012-10-21 19:23:52 +0100 | [diff] [blame] | 46 | * |
| 47 | * Supported flags: |
| 48 | * NFS_PATH_CANONICAL: ensure there is exactly one slash after |
| 49 | * the original device (export) name |
| 50 | * (if unset, the original name is returned verbatim) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 51 | */ |
Ben Hutchings | 97a5486 | 2012-10-21 19:23:52 +0100 | [diff] [blame] | 52 | char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen, |
| 53 | unsigned flags) |
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 | char *end; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 56 | int namelen; |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 57 | unsigned seq; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 58 | const char *base; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 59 | |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 60 | rename_retry: |
| 61 | end = buffer+buflen; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 62 | *--end = '\0'; |
| 63 | buflen--; |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 64 | |
| 65 | seq = read_seqbegin(&rename_lock); |
| 66 | rcu_read_lock(); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 67 | while (1) { |
| 68 | spin_lock(&dentry->d_lock); |
| 69 | if (IS_ROOT(dentry)) |
| 70 | break; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 71 | namelen = dentry->d_name.len; |
| 72 | buflen -= namelen + 1; |
| 73 | if (buflen < 0) |
Josh Triplett | ce51019 | 2006-07-24 16:30:00 -0700 | [diff] [blame] | 74 | goto Elong_unlock; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 75 | end -= namelen; |
| 76 | memcpy(end, dentry->d_name.name, namelen); |
| 77 | *--end = '/'; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 78 | spin_unlock(&dentry->d_lock); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 79 | dentry = dentry->d_parent; |
| 80 | } |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 81 | if (read_seqretry(&rename_lock, seq)) { |
| 82 | spin_unlock(&dentry->d_lock); |
| 83 | rcu_read_unlock(); |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 84 | goto rename_retry; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 85 | } |
Ben Hutchings | 97a5486 | 2012-10-21 19:23:52 +0100 | [diff] [blame] | 86 | if ((flags & NFS_PATH_CANONICAL) && *end != '/') { |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 87 | if (--buflen < 0) { |
| 88 | spin_unlock(&dentry->d_lock); |
| 89 | rcu_read_unlock(); |
Trond Myklebust | 0b75b35 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 90 | goto Elong; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 91 | } |
Trond Myklebust | 0b75b35 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 92 | *--end = '/'; |
| 93 | } |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 94 | *p = end; |
| 95 | base = dentry->d_fsdata; |
| 96 | if (!base) { |
| 97 | spin_unlock(&dentry->d_lock); |
| 98 | rcu_read_unlock(); |
| 99 | WARN_ON(1); |
| 100 | return end; |
| 101 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 102 | namelen = strlen(base); |
Benjamin Coddington | 86a6c21 | 2016-06-15 15:02:55 -0400 | [diff] [blame] | 103 | if (*end == '/') { |
Ben Hutchings | 97a5486 | 2012-10-21 19:23:52 +0100 | [diff] [blame] | 104 | /* Strip off excess slashes in base string */ |
| 105 | while (namelen > 0 && base[namelen - 1] == '/') |
| 106 | namelen--; |
| 107 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 108 | buflen -= namelen; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 109 | if (buflen < 0) { |
Dan Carpenter | 1c34092 | 2011-03-20 14:22:07 +0300 | [diff] [blame] | 110 | spin_unlock(&dentry->d_lock); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 111 | rcu_read_unlock(); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 112 | goto Elong; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 113 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 114 | end -= namelen; |
| 115 | memcpy(end, base, namelen); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 116 | spin_unlock(&dentry->d_lock); |
| 117 | rcu_read_unlock(); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 118 | return end; |
Josh Triplett | ce51019 | 2006-07-24 16:30:00 -0700 | [diff] [blame] | 119 | Elong_unlock: |
Dan Carpenter | 1c34092 | 2011-03-20 14:22:07 +0300 | [diff] [blame] | 120 | spin_unlock(&dentry->d_lock); |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 121 | rcu_read_unlock(); |
| 122 | if (read_seqretry(&rename_lock, seq)) |
| 123 | goto rename_retry; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 124 | Elong: |
| 125 | return ERR_PTR(-ENAMETOOLONG); |
| 126 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 127 | EXPORT_SYMBOL_GPL(nfs_path); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 128 | |
| 129 | /* |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 130 | * nfs_d_automount - Handle crossing a mountpoint on the server |
| 131 | * @path - The mountpoint |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 132 | * |
| 133 | * When we encounter a mountpoint on the server, we want to set up |
| 134 | * a mountpoint on the client too, to prevent inode numbers from |
| 135 | * colliding, and to allow "df" to work properly. |
| 136 | * On NFSv4, we also want to allow for the fact that different |
| 137 | * filesystems may be migrated to different servers in a failover |
| 138 | * situation, and that different filesystems may want to use |
| 139 | * different security flavours. |
| 140 | */ |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 141 | struct vfsmount *nfs_d_automount(struct path *path) |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 142 | { |
| 143 | struct vfsmount *mnt; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 144 | struct nfs_server *server = NFS_SERVER(d_inode(path->dentry)); |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 145 | struct nfs_fh *fh = NULL; |
| 146 | struct nfs_fattr *fattr = NULL; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 147 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 148 | if (IS_ROOT(path->dentry)) |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 149 | return ERR_PTR(-ESTALE); |
Denis V. Lunev | 44d5759 | 2008-08-11 12:02:34 +0400 | [diff] [blame] | 150 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 151 | mnt = ERR_PTR(-ENOMEM); |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 152 | fh = nfs_alloc_fhandle(); |
| 153 | fattr = nfs_alloc_fattr(); |
| 154 | if (fh == NULL || fattr == NULL) |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 155 | goto out; |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 156 | |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 157 | mnt = server->nfs_client->rpc_ops->submount(server, path->dentry, fh, fattr); |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 158 | if (IS_ERR(mnt)) |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 159 | goto out; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 160 | |
Trond Myklebust | 22a1ae9 | 2019-08-21 18:16:28 -0400 | [diff] [blame] | 161 | if (nfs_mountpoint_expiry_timeout < 0) |
| 162 | goto out; |
| 163 | |
David Howells | ea5b778 | 2011-01-14 19:10:03 +0000 | [diff] [blame] | 164 | mntget(mnt); /* prevent immediate expiration */ |
| 165 | mnt_set_expiry(mnt, &nfs_automount_list); |
| 166 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 167 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 168 | out: |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 169 | nfs_free_fattr(fattr); |
| 170 | nfs_free_fhandle(fh); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 171 | return mnt; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 174 | static int |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 175 | nfs_namespace_getattr(const struct path *path, struct kstat *stat, |
| 176 | u32 request_mask, unsigned int query_flags) |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 177 | { |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 178 | if (NFS_FH(d_inode(path->dentry))->size != 0) |
| 179 | return nfs_getattr(path, stat, request_mask, query_flags); |
| 180 | generic_fillattr(d_inode(path->dentry), stat); |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static int |
| 185 | nfs_namespace_setattr(struct dentry *dentry, struct iattr *attr) |
| 186 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 187 | if (NFS_FH(d_inode(dentry))->size != 0) |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 188 | return nfs_setattr(dentry, attr); |
| 189 | return -EACCES; |
| 190 | } |
| 191 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 192 | const struct inode_operations nfs_mountpoint_inode_operations = { |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 193 | .getattr = nfs_getattr, |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 194 | .setattr = nfs_setattr, |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 195 | }; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 196 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 197 | const struct inode_operations nfs_referral_inode_operations = { |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 198 | .getattr = nfs_namespace_getattr, |
| 199 | .setattr = nfs_namespace_setattr, |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 200 | }; |
| 201 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 202 | static void nfs_expire_automounts(struct work_struct *work) |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 203 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 204 | struct list_head *list = &nfs_automount_list; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 205 | |
| 206 | mark_mounts_for_expiry(list); |
| 207 | if (!list_empty(list)) |
| 208 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
| 209 | } |
| 210 | |
| 211 | void nfs_release_automount_timer(void) |
| 212 | { |
Trond Myklebust | 3d39c69 | 2007-08-07 15:28:33 -0400 | [diff] [blame] | 213 | if (list_empty(&nfs_automount_list)) |
Trond Myklebust | 560aef7 | 2007-08-27 09:14:56 -0400 | [diff] [blame] | 214 | cancel_delayed_work(&nfs_automount_task); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 215 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 216 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 217 | /** |
| 218 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 219 | * @dentry: parent directory |
| 220 | * @fh: filehandle for new root dentry |
| 221 | * @fattr: attributes for new root inode |
| 222 | * @authflavor: security flavor to use when performing the mount |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 223 | * |
| 224 | */ |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 225 | struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, |
| 226 | struct nfs_fattr *fattr, rpc_authflavor_t authflavor) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 227 | { |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame^] | 228 | struct super_block *sb = dentry->d_sb; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 229 | struct nfs_clone_mount mountdata = { |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame^] | 230 | .sb = sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 231 | .dentry = dentry, |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 232 | .authflavor = authflavor, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 233 | }; |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame^] | 234 | struct nfs_mount_info mount_info = { |
| 235 | .fill_super = nfs_clone_super, |
| 236 | .set_security = nfs_clone_sb_security, |
| 237 | .cloned = &mountdata, |
| 238 | .mntfh = fh, |
| 239 | }; |
| 240 | struct nfs_subversion *nfs_mod = NFS_SB(sb)->nfs_client->cl_nfs_mod; |
| 241 | struct nfs_server *server; |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 242 | struct vfsmount *mnt; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 243 | char *page = (char *) __get_free_page(GFP_USER); |
| 244 | char *devname; |
| 245 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 246 | if (page == NULL) |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 247 | return ERR_PTR(-ENOMEM); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 248 | |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame^] | 249 | server = nfs_mod->rpc_ops->clone_server(NFS_SB(sb), fh, |
| 250 | fattr, authflavor); |
| 251 | if (IS_ERR(server)) |
| 252 | return ERR_CAST(server); |
| 253 | |
| 254 | mount_info.server = server; |
| 255 | |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 256 | devname = nfs_devname(dentry, page, PAGE_SIZE); |
| 257 | if (IS_ERR(devname)) |
Kees Cook | fe3b81b | 2017-04-04 17:08:42 -0700 | [diff] [blame] | 258 | mnt = ERR_CAST(devname); |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 259 | else |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame^] | 260 | mnt = vfs_submount(dentry, &nfs_xdev_fs_type, devname, &mount_info); |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 261 | |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame^] | 262 | if (mount_info.server) |
| 263 | nfs_free_server(mount_info.server); |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 264 | free_page((unsigned long)page); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 265 | return mnt; |
| 266 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 267 | EXPORT_SYMBOL_GPL(nfs_do_submount); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 268 | |
| 269 | struct vfsmount *nfs_submount(struct nfs_server *server, struct dentry *dentry, |
| 270 | struct nfs_fh *fh, struct nfs_fattr *fattr) |
| 271 | { |
| 272 | int err; |
| 273 | struct dentry *parent = dget_parent(dentry); |
| 274 | |
| 275 | /* Look it up again to get its attributes */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 276 | err = server->nfs_client->rpc_ops->lookup(d_inode(parent), &dentry->d_name, fh, fattr, NULL); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 277 | dput(parent); |
| 278 | if (err != 0) |
| 279 | return ERR_PTR(err); |
| 280 | |
| 281 | return nfs_do_submount(dentry, fh, fattr, server->client->cl_auth->au_flavor); |
| 282 | } |
Bryan Schumaker | ddda8e0 | 2012-07-30 16:05:23 -0400 | [diff] [blame] | 283 | EXPORT_SYMBOL_GPL(nfs_submount); |