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 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 143 | struct nfs_fs_context *ctx; |
| 144 | struct fs_context *fc; |
| 145 | struct vfsmount *mnt = ERR_PTR(-ENOMEM); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 146 | struct nfs_server *server = NFS_SERVER(d_inode(path->dentry)); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 147 | struct nfs_client *client = server->nfs_client; |
| 148 | int ret; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 149 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 150 | if (IS_ROOT(path->dentry)) |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 151 | return ERR_PTR(-ESTALE); |
Denis V. Lunev | 44d5759 | 2008-08-11 12:02:34 +0400 | [diff] [blame] | 152 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 153 | /* Open a new filesystem context, transferring parameters from the |
| 154 | * parent superblock, including the network namespace. |
| 155 | */ |
Scott Mayhew | 1821b26 | 2020-02-20 08:06:20 -0500 | [diff] [blame] | 156 | fc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 157 | if (IS_ERR(fc)) |
| 158 | return ERR_CAST(fc); |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 159 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 160 | ctx = nfs_fc2context(fc); |
| 161 | ctx->clone_data.dentry = path->dentry; |
| 162 | ctx->clone_data.sb = path->dentry->d_sb; |
| 163 | ctx->clone_data.fattr = nfs_alloc_fattr(); |
| 164 | if (!ctx->clone_data.fattr) |
| 165 | goto out_fc; |
| 166 | |
| 167 | if (fc->net_ns != client->cl_net) { |
| 168 | put_net(fc->net_ns); |
| 169 | fc->net_ns = get_net(client->cl_net); |
| 170 | } |
| 171 | |
| 172 | /* for submounts we want the same server; referrals will reassign */ |
| 173 | memcpy(&ctx->nfs_server.address, &client->cl_addr, client->cl_addrlen); |
| 174 | ctx->nfs_server.addrlen = client->cl_addrlen; |
| 175 | ctx->nfs_server.port = server->port; |
| 176 | |
| 177 | ctx->version = client->rpc_ops->version; |
| 178 | ctx->minorversion = client->cl_minorversion; |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 179 | ctx->nfs_mod = client->cl_nfs_mod; |
| 180 | __module_get(ctx->nfs_mod->owner); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 181 | |
| 182 | ret = client->rpc_ops->submount(fc, server); |
| 183 | if (ret < 0) { |
| 184 | mnt = ERR_PTR(ret); |
| 185 | goto out_fc; |
| 186 | } |
| 187 | |
| 188 | up_write(&fc->root->d_sb->s_umount); |
| 189 | mnt = vfs_create_mount(fc); |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 190 | if (IS_ERR(mnt)) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 191 | goto out_fc; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 192 | |
Trond Myklebust | 22a1ae9 | 2019-08-21 18:16:28 -0400 | [diff] [blame] | 193 | if (nfs_mountpoint_expiry_timeout < 0) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 194 | goto out_fc; |
Trond Myklebust | 22a1ae9 | 2019-08-21 18:16:28 -0400 | [diff] [blame] | 195 | |
David Howells | ea5b778 | 2011-01-14 19:10:03 +0000 | [diff] [blame] | 196 | mntget(mnt); /* prevent immediate expiration */ |
| 197 | mnt_set_expiry(mnt, &nfs_automount_list); |
| 198 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 199 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 200 | out_fc: |
| 201 | put_fs_context(fc); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 202 | return mnt; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 203 | } |
| 204 | |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 205 | static int |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 206 | nfs_namespace_getattr(const struct path *path, struct kstat *stat, |
| 207 | u32 request_mask, unsigned int query_flags) |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 208 | { |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 209 | if (NFS_FH(d_inode(path->dentry))->size != 0) |
| 210 | return nfs_getattr(path, stat, request_mask, query_flags); |
| 211 | generic_fillattr(d_inode(path->dentry), stat); |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int |
| 216 | nfs_namespace_setattr(struct dentry *dentry, struct iattr *attr) |
| 217 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 218 | if (NFS_FH(d_inode(dentry))->size != 0) |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 219 | return nfs_setattr(dentry, attr); |
| 220 | return -EACCES; |
| 221 | } |
| 222 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 223 | const struct inode_operations nfs_mountpoint_inode_operations = { |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 224 | .getattr = nfs_getattr, |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 225 | .setattr = nfs_setattr, |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 226 | }; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 227 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 228 | const struct inode_operations nfs_referral_inode_operations = { |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 229 | .getattr = nfs_namespace_getattr, |
| 230 | .setattr = nfs_namespace_setattr, |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 231 | }; |
| 232 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 233 | static void nfs_expire_automounts(struct work_struct *work) |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 234 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 235 | struct list_head *list = &nfs_automount_list; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 236 | |
| 237 | mark_mounts_for_expiry(list); |
| 238 | if (!list_empty(list)) |
| 239 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
| 240 | } |
| 241 | |
| 242 | void nfs_release_automount_timer(void) |
| 243 | { |
Trond Myklebust | 3d39c69 | 2007-08-07 15:28:33 -0400 | [diff] [blame] | 244 | if (list_empty(&nfs_automount_list)) |
Trond Myklebust | 560aef7 | 2007-08-27 09:14:56 -0400 | [diff] [blame] | 245 | cancel_delayed_work(&nfs_automount_task); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 246 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 247 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 248 | /** |
| 249 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary |
Trond Myklebust | 3cab185 | 2020-03-16 11:37:31 -0400 | [diff] [blame] | 250 | * @fc: pointer to struct nfs_fs_context |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 251 | * |
| 252 | */ |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 253 | int nfs_do_submount(struct fs_context *fc) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 254 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 255 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 256 | struct dentry *dentry = ctx->clone_data.dentry; |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 257 | struct nfs_server *server; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 258 | char *buffer, *p; |
| 259 | int ret; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 260 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 261 | /* create a new volume representation */ |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 262 | server = ctx->nfs_mod->rpc_ops->clone_server(NFS_SB(ctx->clone_data.sb), |
| 263 | ctx->mntfh, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 264 | ctx->clone_data.fattr, |
| 265 | ctx->selected_flavor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 266 | |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 267 | if (IS_ERR(server)) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 268 | return PTR_ERR(server); |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 269 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 270 | ctx->server = server; |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 271 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 272 | buffer = kmalloc(4096, GFP_USER); |
| 273 | if (!buffer) |
| 274 | return -ENOMEM; |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 275 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 276 | ctx->internal = true; |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 277 | ctx->clone_data.inherited_bsize = ctx->clone_data.sb->s_blocksize_bits; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 278 | |
| 279 | p = nfs_devname(dentry, buffer, 4096); |
| 280 | if (IS_ERR(p)) { |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 281 | nfs_errorf(fc, "NFS: Couldn't determine submount pathname"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 282 | ret = PTR_ERR(p); |
| 283 | } else { |
| 284 | ret = vfs_parse_fs_string(fc, "source", p, buffer + 4096 - p); |
| 285 | if (!ret) |
| 286 | ret = vfs_get_tree(fc); |
| 287 | } |
| 288 | kfree(buffer); |
| 289 | return ret; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 290 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 291 | EXPORT_SYMBOL_GPL(nfs_do_submount); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 292 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 293 | int nfs_submount(struct fs_context *fc, struct nfs_server *server) |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 294 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 295 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 296 | struct dentry *dentry = ctx->clone_data.dentry; |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 297 | struct dentry *parent = dget_parent(dentry); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 298 | int err; |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 299 | |
| 300 | /* Look it up again to get its attributes */ |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 301 | err = server->nfs_client->rpc_ops->lookup(d_inode(parent), dentry, |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 302 | ctx->mntfh, ctx->clone_data.fattr, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 303 | NULL); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 304 | dput(parent); |
| 305 | if (err != 0) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 306 | return err; |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 307 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 308 | ctx->selected_flavor = server->client->cl_auth->au_flavor; |
| 309 | return nfs_do_submount(fc); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 310 | } |
Bryan Schumaker | ddda8e0 | 2012-07-30 16:05:23 -0400 | [diff] [blame] | 311 | EXPORT_SYMBOL_GPL(nfs_submount); |