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 |
Ashish Sangwan | 247db73 | 2020-10-05 02:22:43 -0700 | [diff] [blame] | 35 | * @dentry_in - pointer to dentry |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 36 | * @buffer - result buffer |
Ashish Sangwan | 247db73 | 2020-10-05 02:22:43 -0700 | [diff] [blame] | 37 | * @buflen_in - 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 | */ |
Ashish Sangwan | 247db73 | 2020-10-05 02:22:43 -0700 | [diff] [blame] | 52 | char *nfs_path(char **p, struct dentry *dentry_in, char *buffer, |
| 53 | ssize_t buflen_in, 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; |
Ashish Sangwan | 247db73 | 2020-10-05 02:22:43 -0700 | [diff] [blame] | 59 | struct dentry *dentry; |
| 60 | ssize_t buflen; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 61 | |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 62 | rename_retry: |
Ashish Sangwan | 247db73 | 2020-10-05 02:22:43 -0700 | [diff] [blame] | 63 | buflen = buflen_in; |
| 64 | dentry = dentry_in; |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 65 | end = buffer+buflen; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 66 | *--end = '\0'; |
| 67 | buflen--; |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 68 | |
| 69 | seq = read_seqbegin(&rename_lock); |
| 70 | rcu_read_lock(); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 71 | while (1) { |
| 72 | spin_lock(&dentry->d_lock); |
| 73 | if (IS_ROOT(dentry)) |
| 74 | break; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 75 | namelen = dentry->d_name.len; |
| 76 | buflen -= namelen + 1; |
| 77 | if (buflen < 0) |
Josh Triplett | ce51019 | 2006-07-24 16:30:00 -0700 | [diff] [blame] | 78 | goto Elong_unlock; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 79 | end -= namelen; |
| 80 | memcpy(end, dentry->d_name.name, namelen); |
| 81 | *--end = '/'; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 82 | spin_unlock(&dentry->d_lock); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 83 | dentry = dentry->d_parent; |
| 84 | } |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 85 | if (read_seqretry(&rename_lock, seq)) { |
| 86 | spin_unlock(&dentry->d_lock); |
| 87 | rcu_read_unlock(); |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 88 | goto rename_retry; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 89 | } |
Ben Hutchings | 97a5486 | 2012-10-21 19:23:52 +0100 | [diff] [blame] | 90 | if ((flags & NFS_PATH_CANONICAL) && *end != '/') { |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 91 | if (--buflen < 0) { |
| 92 | spin_unlock(&dentry->d_lock); |
| 93 | rcu_read_unlock(); |
Trond Myklebust | 0b75b35 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 94 | goto Elong; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 95 | } |
Trond Myklebust | 0b75b35 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 96 | *--end = '/'; |
| 97 | } |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 98 | *p = end; |
| 99 | base = dentry->d_fsdata; |
| 100 | if (!base) { |
| 101 | spin_unlock(&dentry->d_lock); |
| 102 | rcu_read_unlock(); |
| 103 | WARN_ON(1); |
| 104 | return end; |
| 105 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 106 | namelen = strlen(base); |
Benjamin Coddington | 86a6c21 | 2016-06-15 15:02:55 -0400 | [diff] [blame] | 107 | if (*end == '/') { |
Ben Hutchings | 97a5486 | 2012-10-21 19:23:52 +0100 | [diff] [blame] | 108 | /* Strip off excess slashes in base string */ |
| 109 | while (namelen > 0 && base[namelen - 1] == '/') |
| 110 | namelen--; |
| 111 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 112 | buflen -= namelen; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 113 | if (buflen < 0) { |
Dan Carpenter | 1c34092 | 2011-03-20 14:22:07 +0300 | [diff] [blame] | 114 | spin_unlock(&dentry->d_lock); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 115 | rcu_read_unlock(); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 116 | goto Elong; |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 117 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 118 | end -= namelen; |
| 119 | memcpy(end, base, namelen); |
Al Viro | b514f87 | 2011-03-16 06:26:11 -0400 | [diff] [blame] | 120 | spin_unlock(&dentry->d_lock); |
| 121 | rcu_read_unlock(); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 122 | return end; |
Josh Triplett | ce51019 | 2006-07-24 16:30:00 -0700 | [diff] [blame] | 123 | Elong_unlock: |
Dan Carpenter | 1c34092 | 2011-03-20 14:22:07 +0300 | [diff] [blame] | 124 | spin_unlock(&dentry->d_lock); |
Nick Piggin | 949854d | 2011-01-07 17:49:37 +1100 | [diff] [blame] | 125 | rcu_read_unlock(); |
| 126 | if (read_seqretry(&rename_lock, seq)) |
| 127 | goto rename_retry; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 128 | Elong: |
| 129 | return ERR_PTR(-ENAMETOOLONG); |
| 130 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 131 | EXPORT_SYMBOL_GPL(nfs_path); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 132 | |
| 133 | /* |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 134 | * nfs_d_automount - Handle crossing a mountpoint on the server |
| 135 | * @path - The mountpoint |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 136 | * |
| 137 | * When we encounter a mountpoint on the server, we want to set up |
| 138 | * a mountpoint on the client too, to prevent inode numbers from |
| 139 | * colliding, and to allow "df" to work properly. |
| 140 | * On NFSv4, we also want to allow for the fact that different |
| 141 | * filesystems may be migrated to different servers in a failover |
| 142 | * situation, and that different filesystems may want to use |
| 143 | * different security flavours. |
| 144 | */ |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 145 | struct vfsmount *nfs_d_automount(struct path *path) |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 146 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 147 | struct nfs_fs_context *ctx; |
| 148 | struct fs_context *fc; |
| 149 | struct vfsmount *mnt = ERR_PTR(-ENOMEM); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 150 | struct nfs_server *server = NFS_SERVER(d_inode(path->dentry)); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 151 | struct nfs_client *client = server->nfs_client; |
Trond Myklebust | 75da985 | 2020-04-02 10:34:36 -0400 | [diff] [blame] | 152 | int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 153 | int ret; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 154 | |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 155 | if (IS_ROOT(path->dentry)) |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 156 | return ERR_PTR(-ESTALE); |
Denis V. Lunev | 44d5759 | 2008-08-11 12:02:34 +0400 | [diff] [blame] | 157 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 158 | /* Open a new filesystem context, transferring parameters from the |
| 159 | * parent superblock, including the network namespace. |
| 160 | */ |
Scott Mayhew | 1821b26 | 2020-02-20 08:06:20 -0500 | [diff] [blame] | 161 | 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] | 162 | if (IS_ERR(fc)) |
| 163 | return ERR_CAST(fc); |
Trond Myklebust | a4d7f16 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 164 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 165 | ctx = nfs_fc2context(fc); |
| 166 | ctx->clone_data.dentry = path->dentry; |
| 167 | ctx->clone_data.sb = path->dentry->d_sb; |
| 168 | ctx->clone_data.fattr = nfs_alloc_fattr(); |
| 169 | if (!ctx->clone_data.fattr) |
| 170 | goto out_fc; |
| 171 | |
| 172 | if (fc->net_ns != client->cl_net) { |
| 173 | put_net(fc->net_ns); |
| 174 | fc->net_ns = get_net(client->cl_net); |
| 175 | } |
| 176 | |
| 177 | /* for submounts we want the same server; referrals will reassign */ |
| 178 | memcpy(&ctx->nfs_server.address, &client->cl_addr, client->cl_addrlen); |
| 179 | ctx->nfs_server.addrlen = client->cl_addrlen; |
| 180 | ctx->nfs_server.port = server->port; |
| 181 | |
| 182 | ctx->version = client->rpc_ops->version; |
| 183 | ctx->minorversion = client->cl_minorversion; |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 184 | ctx->nfs_mod = client->cl_nfs_mod; |
| 185 | __module_get(ctx->nfs_mod->owner); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 186 | |
| 187 | ret = client->rpc_ops->submount(fc, server); |
| 188 | if (ret < 0) { |
| 189 | mnt = ERR_PTR(ret); |
| 190 | goto out_fc; |
| 191 | } |
| 192 | |
| 193 | up_write(&fc->root->d_sb->s_umount); |
| 194 | mnt = vfs_create_mount(fc); |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 195 | if (IS_ERR(mnt)) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 196 | goto out_fc; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 197 | |
Trond Myklebust | 75da985 | 2020-04-02 10:34:36 -0400 | [diff] [blame] | 198 | mntget(mnt); /* prevent immediate expiration */ |
| 199 | if (timeout <= 0) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 200 | goto out_fc; |
Trond Myklebust | 22a1ae9 | 2019-08-21 18:16:28 -0400 | [diff] [blame] | 201 | |
David Howells | ea5b778 | 2011-01-14 19:10:03 +0000 | [diff] [blame] | 202 | mnt_set_expiry(mnt, &nfs_automount_list); |
Trond Myklebust | 75da985 | 2020-04-02 10:34:36 -0400 | [diff] [blame] | 203 | schedule_delayed_work(&nfs_automount_task, timeout); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 204 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 205 | out_fc: |
| 206 | put_fs_context(fc); |
David Howells | 36d43a4 | 2011-01-14 18:45:42 +0000 | [diff] [blame] | 207 | return mnt; |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 210 | static int |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame^] | 211 | nfs_namespace_getattr(struct user_namespace *mnt_userns, |
| 212 | const struct path *path, struct kstat *stat, |
| 213 | u32 request_mask, unsigned int query_flags) |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 214 | { |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 215 | if (NFS_FH(d_inode(path->dentry))->size != 0) |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame^] | 216 | return nfs_getattr(mnt_userns, path, stat, request_mask, |
| 217 | query_flags); |
Christian Brauner | 0d56a45 | 2021-01-21 14:19:30 +0100 | [diff] [blame] | 218 | generic_fillattr(&init_user_ns, d_inode(path->dentry), stat); |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static int |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame^] | 223 | nfs_namespace_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, |
| 224 | struct iattr *attr) |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 225 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 226 | if (NFS_FH(d_inode(dentry))->size != 0) |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame^] | 227 | return nfs_setattr(mnt_userns, dentry, attr); |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 228 | return -EACCES; |
| 229 | } |
| 230 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 231 | const struct inode_operations nfs_mountpoint_inode_operations = { |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 232 | .getattr = nfs_getattr, |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 233 | .setattr = nfs_setattr, |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 234 | }; |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 235 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 236 | const struct inode_operations nfs_referral_inode_operations = { |
Trond Myklebust | ab22541 | 2013-01-22 00:17:06 -0500 | [diff] [blame] | 237 | .getattr = nfs_namespace_getattr, |
| 238 | .setattr = nfs_namespace_setattr, |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 239 | }; |
| 240 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 241 | static void nfs_expire_automounts(struct work_struct *work) |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 242 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 243 | struct list_head *list = &nfs_automount_list; |
Trond Myklebust | 75da985 | 2020-04-02 10:34:36 -0400 | [diff] [blame] | 244 | int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 245 | |
| 246 | mark_mounts_for_expiry(list); |
Trond Myklebust | 75da985 | 2020-04-02 10:34:36 -0400 | [diff] [blame] | 247 | if (!list_empty(list) && timeout > 0) |
| 248 | schedule_delayed_work(&nfs_automount_task, timeout); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void nfs_release_automount_timer(void) |
| 252 | { |
Trond Myklebust | 3d39c69 | 2007-08-07 15:28:33 -0400 | [diff] [blame] | 253 | if (list_empty(&nfs_automount_list)) |
Trond Myklebust | 560aef7 | 2007-08-27 09:14:56 -0400 | [diff] [blame] | 254 | cancel_delayed_work(&nfs_automount_task); |
Trond Myklebust | 51d8fa6 | 2006-06-09 09:34:20 -0400 | [diff] [blame] | 255 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 256 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 257 | /** |
| 258 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary |
Trond Myklebust | 3cab185 | 2020-03-16 11:37:31 -0400 | [diff] [blame] | 259 | * @fc: pointer to struct nfs_fs_context |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 260 | * |
| 261 | */ |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 262 | int nfs_do_submount(struct fs_context *fc) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 263 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 264 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 265 | struct dentry *dentry = ctx->clone_data.dentry; |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 266 | struct nfs_server *server; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 267 | char *buffer, *p; |
| 268 | int ret; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 269 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 270 | /* create a new volume representation */ |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 271 | server = ctx->nfs_mod->rpc_ops->clone_server(NFS_SB(ctx->clone_data.sb), |
| 272 | ctx->mntfh, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 273 | ctx->clone_data.fattr, |
| 274 | ctx->selected_flavor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 275 | |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 276 | if (IS_ERR(server)) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 277 | return PTR_ERR(server); |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 278 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 279 | ctx->server = server; |
Al Viro | 250d69f | 2019-12-10 07:30:55 -0500 | [diff] [blame] | 280 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 281 | buffer = kmalloc(4096, GFP_USER); |
| 282 | if (!buffer) |
| 283 | return -ENOMEM; |
Anna Schumaker | e36d48e | 2017-04-07 14:15:09 -0400 | [diff] [blame] | 284 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 285 | ctx->internal = true; |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 286 | ctx->clone_data.inherited_bsize = ctx->clone_data.sb->s_blocksize_bits; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 287 | |
| 288 | p = nfs_devname(dentry, buffer, 4096); |
| 289 | if (IS_ERR(p)) { |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 290 | nfs_errorf(fc, "NFS: Couldn't determine submount pathname"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 291 | ret = PTR_ERR(p); |
| 292 | } else { |
| 293 | ret = vfs_parse_fs_string(fc, "source", p, buffer + 4096 - p); |
| 294 | if (!ret) |
| 295 | ret = vfs_get_tree(fc); |
| 296 | } |
| 297 | kfree(buffer); |
| 298 | return ret; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 299 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 300 | EXPORT_SYMBOL_GPL(nfs_do_submount); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 301 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 302 | int nfs_submount(struct fs_context *fc, struct nfs_server *server) |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 303 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 304 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 305 | struct dentry *dentry = ctx->clone_data.dentry; |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 306 | struct dentry *parent = dget_parent(dentry); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 307 | int err; |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 308 | |
| 309 | /* Look it up again to get its attributes */ |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 310 | err = server->nfs_client->rpc_ops->lookup(d_inode(parent), dentry, |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 311 | ctx->mntfh, ctx->clone_data.fattr, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 312 | NULL); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 313 | dput(parent); |
| 314 | if (err != 0) |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 315 | return err; |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 316 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 317 | ctx->selected_flavor = server->client->cl_auth->au_flavor; |
| 318 | return nfs_do_submount(fc); |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 319 | } |
Bryan Schumaker | ddda8e0 | 2012-07-30 16:05:23 -0400 | [diff] [blame] | 320 | EXPORT_SYMBOL_GPL(nfs_submount); |
Trond Myklebust | f30a6ea | 2020-04-02 12:37:25 -0400 | [diff] [blame] | 321 | |
| 322 | static int param_set_nfs_timeout(const char *val, const struct kernel_param *kp) |
| 323 | { |
| 324 | long num; |
| 325 | int ret; |
| 326 | |
| 327 | if (!val) |
| 328 | return -EINVAL; |
| 329 | ret = kstrtol(val, 0, &num); |
| 330 | if (ret) |
| 331 | return -EINVAL; |
| 332 | if (num > 0) { |
| 333 | if (num >= INT_MAX / HZ) |
| 334 | num = INT_MAX; |
| 335 | else |
| 336 | num *= HZ; |
| 337 | *((int *)kp->arg) = num; |
| 338 | if (!list_empty(&nfs_automount_list)) |
| 339 | mod_delayed_work(system_wq, &nfs_automount_task, num); |
| 340 | } else { |
| 341 | *((int *)kp->arg) = -1*HZ; |
| 342 | cancel_delayed_work(&nfs_automount_task); |
| 343 | } |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int param_get_nfs_timeout(char *buffer, const struct kernel_param *kp) |
| 348 | { |
| 349 | long num = *((int *)kp->arg); |
| 350 | |
| 351 | if (num > 0) { |
| 352 | if (num >= INT_MAX - (HZ - 1)) |
| 353 | num = INT_MAX / HZ; |
| 354 | else |
| 355 | num = (num + (HZ - 1)) / HZ; |
| 356 | } else |
| 357 | num = -1; |
| 358 | return scnprintf(buffer, PAGE_SIZE, "%li\n", num); |
| 359 | } |
| 360 | |
| 361 | static const struct kernel_param_ops param_ops_nfs_timeout = { |
| 362 | .set = param_set_nfs_timeout, |
| 363 | .get = param_get_nfs_timeout, |
| 364 | }; |
| 365 | #define param_check_nfs_timeout(name, p) __param_check(name, p, int); |
| 366 | |
| 367 | module_param(nfs_mountpoint_expiry_timeout, nfs_timeout, 0644); |
| 368 | MODULE_PARM_DESC(nfs_mountpoint_expiry_timeout, |
| 369 | "Set the NFS automounted mountpoint timeout value (seconds)." |
| 370 | "Values <= 0 turn expiration off."); |