Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 56 | #include <linux/freezer.h> |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 57 | #include <linux/iversion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 69 | #include "nfs42.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 71 | #include "nfs4trace.h" |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 74 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 75 | #define NFS4_BITMASK_SZ 3 |
| 76 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 77 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 79 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 80 | /* file attributes which can be mapped to nfs attributes */ |
| 81 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 82 | | ATTR_UID \ |
| 83 | | ATTR_GID \ |
| 84 | | ATTR_SIZE \ |
| 85 | | ATTR_ATIME \ |
| 86 | | ATTR_MTIME \ |
| 87 | | ATTR_CTIME \ |
| 88 | | ATTR_ATIME_SET \ |
| 89 | | ATTR_MTIME_SET) |
| 90 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 91 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 92 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 94 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 95 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 96 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 97 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 98 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 99 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 100 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 101 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 102 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 103 | struct nfs4_slot *slot, |
| 104 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 105 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 106 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 107 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 108 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 109 | #endif |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 110 | static void nfs4_bitmask_adjust(__u32 *bitmask, struct inode *inode, |
| 111 | struct nfs_server *server, |
| 112 | struct nfs4_label *label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 113 | |
| 114 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 115 | static inline struct nfs4_label * |
| 116 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 117 | struct iattr *sattr, struct nfs4_label *label) |
| 118 | { |
| 119 | int err; |
| 120 | |
| 121 | if (label == NULL) |
| 122 | return NULL; |
| 123 | |
| 124 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 125 | return NULL; |
| 126 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 127 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 128 | &dentry->d_name, (void **)&label->label, &label->len); |
| 129 | if (err == 0) |
| 130 | return label; |
| 131 | |
| 132 | return NULL; |
| 133 | } |
| 134 | static inline void |
| 135 | nfs4_label_release_security(struct nfs4_label *label) |
| 136 | { |
| 137 | if (label) |
| 138 | security_release_secctx(label->label, label->len); |
| 139 | } |
| 140 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 141 | { |
| 142 | if (label) |
| 143 | return server->attr_bitmask; |
| 144 | |
| 145 | return server->attr_bitmask_nl; |
| 146 | } |
| 147 | #else |
| 148 | static inline struct nfs4_label * |
| 149 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 150 | struct iattr *sattr, struct nfs4_label *l) |
| 151 | { return NULL; } |
| 152 | static inline void |
| 153 | nfs4_label_release_security(struct nfs4_label *label) |
| 154 | { return; } |
| 155 | static inline u32 * |
| 156 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 157 | { return server->attr_bitmask; } |
| 158 | #endif |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 161 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 163 | if (err >= -1000) |
| 164 | return err; |
| 165 | switch (err) { |
| 166 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 167 | case -NFS4ERR_LAYOUTTRYLATER: |
| 168 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 169 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 170 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 171 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 172 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 173 | case -NFS4ERR_BADOWNER: |
| 174 | case -NFS4ERR_BADNAME: |
| 175 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 176 | case -NFS4ERR_SHARE_DENIED: |
| 177 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 178 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 179 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 180 | case -NFS4ERR_FILE_OPEN: |
| 181 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 182 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 184 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 185 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 187 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* |
| 191 | * This is our standard bitmap for GETATTR requests. |
| 192 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 193 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | FATTR4_WORD0_TYPE |
| 195 | | FATTR4_WORD0_CHANGE |
| 196 | | FATTR4_WORD0_SIZE |
| 197 | | FATTR4_WORD0_FSID |
| 198 | | FATTR4_WORD0_FILEID, |
| 199 | FATTR4_WORD1_MODE |
| 200 | | FATTR4_WORD1_NUMLINKS |
| 201 | | FATTR4_WORD1_OWNER |
| 202 | | FATTR4_WORD1_OWNER_GROUP |
| 203 | | FATTR4_WORD1_RAWDEV |
| 204 | | FATTR4_WORD1_SPACE_USED |
| 205 | | FATTR4_WORD1_TIME_ACCESS |
| 206 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 207 | | FATTR4_WORD1_TIME_MODIFY |
| 208 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 209 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 210 | FATTR4_WORD2_SECURITY_LABEL |
| 211 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 214 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 215 | FATTR4_WORD0_TYPE |
| 216 | | FATTR4_WORD0_CHANGE |
| 217 | | FATTR4_WORD0_SIZE |
| 218 | | FATTR4_WORD0_FSID |
| 219 | | FATTR4_WORD0_FILEID, |
| 220 | FATTR4_WORD1_MODE |
| 221 | | FATTR4_WORD1_NUMLINKS |
| 222 | | FATTR4_WORD1_OWNER |
| 223 | | FATTR4_WORD1_OWNER_GROUP |
| 224 | | FATTR4_WORD1_RAWDEV |
| 225 | | FATTR4_WORD1_SPACE_USED |
| 226 | | FATTR4_WORD1_TIME_ACCESS |
| 227 | | FATTR4_WORD1_TIME_METADATA |
| 228 | | FATTR4_WORD1_TIME_MODIFY, |
| 229 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 230 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 231 | | FATTR4_WORD2_SECURITY_LABEL |
| 232 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 233 | }; |
| 234 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 235 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 236 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 237 | | FATTR4_WORD0_FILEID, |
| 238 | }; |
| 239 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 240 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | FATTR4_WORD0_FILES_AVAIL |
| 242 | | FATTR4_WORD0_FILES_FREE |
| 243 | | FATTR4_WORD0_FILES_TOTAL, |
| 244 | FATTR4_WORD1_SPACE_AVAIL |
| 245 | | FATTR4_WORD1_SPACE_FREE |
| 246 | | FATTR4_WORD1_SPACE_TOTAL |
| 247 | }; |
| 248 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 249 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | FATTR4_WORD0_MAXLINK |
| 251 | | FATTR4_WORD0_MAXNAME, |
| 252 | 0 |
| 253 | }; |
| 254 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 255 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | | FATTR4_WORD0_MAXREAD |
| 257 | | FATTR4_WORD0_MAXWRITE |
| 258 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 259 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 260 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 261 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 262 | | FATTR4_WORD2_CLONE_BLKSIZE |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 263 | | FATTR4_WORD2_XATTR_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | }; |
| 265 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 266 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 267 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 268 | | FATTR4_WORD0_SIZE |
| 269 | | FATTR4_WORD0_FSID |
| 270 | | FATTR4_WORD0_FILEID |
| 271 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 272 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 273 | | FATTR4_WORD1_OWNER_GROUP |
| 274 | | FATTR4_WORD1_RAWDEV |
| 275 | | FATTR4_WORD1_SPACE_USED |
| 276 | | FATTR4_WORD1_TIME_ACCESS |
| 277 | | FATTR4_WORD1_TIME_METADATA |
| 278 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 279 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 280 | }; |
| 281 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 282 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 283 | struct inode *inode) |
| 284 | { |
| 285 | unsigned long cache_validity; |
| 286 | |
| 287 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 288 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 289 | return; |
| 290 | |
| 291 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 292 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 293 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 294 | | NFS_INO_INVALID_SIZE); |
| 295 | |
| 296 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 297 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 298 | |
| 299 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 300 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 301 | } |
| 302 | |
| 303 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 304 | const __u32 *src, struct inode *inode) |
| 305 | { |
| 306 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 307 | } |
| 308 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 309 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | struct nfs4_readdir_arg *readdir) |
| 311 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 312 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 313 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 316 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | readdir->cookie = 0; |
| 322 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 323 | if (cookie == 2) |
| 324 | return; |
| 325 | |
| 326 | /* |
| 327 | * NFSv4 servers do not return entries for '.' and '..' |
| 328 | * Therefore, we fake these entries here. We let '.' |
| 329 | * have cookie 0 and '..' have cookie 1. Note that |
| 330 | * when talking to the server, we always send cookie 0 |
| 331 | * instead of 1 or 2. |
| 332 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 333 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | if (cookie == 0) { |
| 336 | *p++ = xdr_one; /* next */ |
| 337 | *p++ = xdr_zero; /* cookie, first word */ |
| 338 | *p++ = xdr_one; /* cookie, second word */ |
| 339 | *p++ = xdr_one; /* entry len */ |
| 340 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 341 | p++; |
| 342 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 343 | *p++ = htonl(attrs); /* bitmap */ |
| 344 | *p++ = htonl(12); /* attribute buffer length */ |
| 345 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 346 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | *p++ = xdr_one; /* next */ |
| 350 | *p++ = xdr_zero; /* cookie, first word */ |
| 351 | *p++ = xdr_two; /* cookie, second word */ |
| 352 | *p++ = xdr_two; /* entry len */ |
| 353 | memcpy(p, "..\0\0", 4); /* entry */ |
| 354 | p++; |
| 355 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 356 | *p++ = htonl(attrs); /* bitmap */ |
| 357 | *p++ = htonl(12); /* attribute buffer length */ |
| 358 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 359 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | readdir->pgbase = (char *)p - (char *)start; |
| 362 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 363 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 366 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 367 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 368 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 369 | { |
| 370 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 371 | |
| 372 | ops->test_and_free_expired(server, stateid, cred); |
| 373 | } |
| 374 | |
| 375 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 376 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 377 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 378 | { |
| 379 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 380 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 381 | } |
| 382 | |
| 383 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 384 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 385 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 386 | { |
| 387 | nfs4_stateid tmp; |
| 388 | |
| 389 | nfs4_stateid_copy(&tmp, stateid); |
| 390 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 391 | } |
| 392 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 393 | static long nfs4_update_delay(long *timeout) |
| 394 | { |
| 395 | long ret; |
| 396 | if (!timeout) |
| 397 | return NFS4_POLL_RETRY_MAX; |
| 398 | if (*timeout <= 0) |
| 399 | *timeout = NFS4_POLL_RETRY_MIN; |
| 400 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 401 | *timeout = NFS4_POLL_RETRY_MAX; |
| 402 | ret = *timeout; |
| 403 | *timeout <<= 1; |
| 404 | return ret; |
| 405 | } |
| 406 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 407 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 408 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 409 | might_sleep(); |
| 410 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 411 | freezable_schedule_timeout_killable_unsafe( |
| 412 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 413 | if (!__fatal_signal_pending(current)) |
| 414 | return 0; |
| 415 | return -EINTR; |
| 416 | } |
| 417 | |
| 418 | static int nfs4_delay_interruptible(long *timeout) |
| 419 | { |
| 420 | might_sleep(); |
| 421 | |
He Zhe | 59679d9 | 2020-07-06 17:52:24 +0800 | [diff] [blame] | 422 | freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 423 | if (!signal_pending(current)) |
| 424 | return 0; |
| 425 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 426 | } |
| 427 | |
| 428 | static int nfs4_delay(long *timeout, bool interruptible) |
| 429 | { |
| 430 | if (interruptible) |
| 431 | return nfs4_delay_interruptible(timeout); |
| 432 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 433 | } |
| 434 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 435 | static const nfs4_stateid * |
| 436 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 437 | { |
| 438 | if (!stateid) |
| 439 | return NULL; |
| 440 | switch (stateid->type) { |
| 441 | case NFS4_OPEN_STATEID_TYPE: |
| 442 | case NFS4_LOCK_STATEID_TYPE: |
| 443 | case NFS4_DELEGATION_STATEID_TYPE: |
| 444 | return stateid; |
| 445 | default: |
| 446 | break; |
| 447 | } |
| 448 | return NULL; |
| 449 | } |
| 450 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 451 | /* This is the error handling routine for processes that are allowed |
| 452 | * to sleep. |
| 453 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 454 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 455 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 456 | { |
| 457 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 458 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 459 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 460 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | int ret = errorcode; |
| 462 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 463 | exception->delay = 0; |
| 464 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 465 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 466 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 467 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 468 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 469 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 470 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 471 | switch(errorcode) { |
| 472 | case 0: |
| 473 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 474 | case -NFS4ERR_BADHANDLE: |
| 475 | case -ESTALE: |
| 476 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 477 | pnfs_destroy_layout(NFS_I(inode)); |
| 478 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 479 | case -NFS4ERR_DELEG_REVOKED: |
| 480 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 481 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 482 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 483 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 484 | if (inode != NULL && stateid != NULL) { |
| 485 | nfs_inode_find_state_and_recover(inode, |
| 486 | stateid); |
| 487 | goto wait_on_recovery; |
| 488 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 489 | fallthrough; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 490 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 491 | if (inode) { |
| 492 | int err; |
| 493 | |
| 494 | err = nfs_async_inode_return_delegation(inode, |
| 495 | stateid); |
| 496 | if (err == 0) |
| 497 | goto wait_on_recovery; |
| 498 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 499 | exception->retry = 1; |
| 500 | break; |
| 501 | } |
| 502 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 503 | if (state == NULL) |
| 504 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 505 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 506 | if (ret < 0) |
| 507 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 508 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 509 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 510 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 511 | nfs4_schedule_lease_recovery(clp); |
| 512 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 513 | case -NFS4ERR_MOVED: |
| 514 | ret = nfs4_schedule_migration_recovery(server); |
| 515 | if (ret < 0) |
| 516 | break; |
| 517 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 518 | case -NFS4ERR_LEASE_MOVED: |
| 519 | nfs4_schedule_lease_moved_recovery(clp); |
| 520 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 521 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 522 | case -NFS4ERR_BADSESSION: |
| 523 | case -NFS4ERR_BADSLOT: |
| 524 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 525 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 526 | case -NFS4ERR_DEADSESSION: |
| 527 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 528 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 529 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 530 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 531 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 532 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 533 | if (exception->timeout > HZ) { |
| 534 | /* We have retried a decent amount, time to |
| 535 | * fail |
| 536 | */ |
| 537 | ret = -EBUSY; |
| 538 | break; |
| 539 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 540 | fallthrough; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 541 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 542 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 543 | fallthrough; |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 544 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 545 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 546 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 547 | exception->delay = 1; |
| 548 | return 0; |
| 549 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 550 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 551 | case -NFS4ERR_OLD_STATEID: |
| 552 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 553 | break; |
| 554 | case -NFS4ERR_BADOWNER: |
| 555 | /* The following works around a Linux server bug! */ |
| 556 | case -NFS4ERR_BADNAME: |
| 557 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 558 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 559 | exception->retry = 1; |
| 560 | printk(KERN_WARNING "NFS: v4 server %s " |
| 561 | "does not accept raw " |
| 562 | "uid/gids. " |
| 563 | "Reenabling the idmapper.\n", |
| 564 | server->nfs_client->cl_hostname); |
| 565 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 566 | } |
| 567 | /* We failed to handle the error */ |
| 568 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 569 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 570 | exception->recovering = 1; |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /* This is the error handling routine for processes that are allowed |
| 575 | * to sleep. |
| 576 | */ |
| 577 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 578 | { |
| 579 | struct nfs_client *clp = server->nfs_client; |
| 580 | int ret; |
| 581 | |
| 582 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 583 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 584 | ret = nfs4_delay(&exception->timeout, |
| 585 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 586 | goto out_retry; |
| 587 | } |
| 588 | if (exception->recovering) { |
| 589 | ret = nfs4_wait_clnt_recover(clp); |
| 590 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 591 | return -EIO; |
| 592 | goto out_retry; |
| 593 | } |
| 594 | return ret; |
| 595 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 596 | if (ret == 0) |
| 597 | exception->retry = 1; |
| 598 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 599 | } |
| 600 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 601 | static int |
| 602 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 603 | int errorcode, struct nfs4_exception *exception) |
| 604 | { |
| 605 | struct nfs_client *clp = server->nfs_client; |
| 606 | int ret; |
| 607 | |
| 608 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 609 | if (exception->delay) { |
| 610 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 611 | goto out_retry; |
| 612 | } |
| 613 | if (exception->recovering) { |
| 614 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 615 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 616 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 617 | goto out_retry; |
| 618 | } |
| 619 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 620 | ret = -EIO; |
| 621 | return ret; |
| 622 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 623 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 624 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 625 | /* |
| 626 | * For NFS4ERR_MOVED, the client transport will need to |
| 627 | * be recomputed after migration recovery has completed. |
| 628 | */ |
| 629 | if (errorcode == -NFS4ERR_MOVED) |
| 630 | rpc_task_release_transport(task); |
| 631 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 632 | return ret; |
| 633 | } |
| 634 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 635 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 636 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 637 | struct nfs4_state *state, long *timeout) |
| 638 | { |
| 639 | struct nfs4_exception exception = { |
| 640 | .state = state, |
| 641 | }; |
| 642 | |
| 643 | if (task->tk_status >= 0) |
| 644 | return 0; |
| 645 | if (timeout) |
| 646 | exception.timeout = *timeout; |
| 647 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 648 | task->tk_status, |
| 649 | &exception); |
| 650 | if (exception.delay && timeout) |
| 651 | *timeout = exception.timeout; |
| 652 | if (exception.retry) |
| 653 | return -EAGAIN; |
| 654 | return 0; |
| 655 | } |
| 656 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 657 | /* |
| 658 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 659 | * or 'false' otherwise. |
| 660 | */ |
| 661 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 662 | { |
| 663 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 664 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 665 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 666 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 667 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | spin_lock(&clp->cl_lock); |
| 670 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 671 | clp->cl_last_renewal = timestamp; |
| 672 | spin_unlock(&clp->cl_lock); |
| 673 | } |
| 674 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 675 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 676 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 677 | struct nfs_client *clp = server->nfs_client; |
| 678 | |
| 679 | if (!nfs4_has_session(clp)) |
| 680 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 681 | } |
| 682 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 683 | struct nfs4_call_sync_data { |
| 684 | const struct nfs_server *seq_server; |
| 685 | struct nfs4_sequence_args *seq_args; |
| 686 | struct nfs4_sequence_res *seq_res; |
| 687 | }; |
| 688 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 689 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 690 | struct nfs4_sequence_res *res, int cache_reply, |
| 691 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 692 | { |
| 693 | args->sa_slot = NULL; |
| 694 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 695 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 696 | |
| 697 | res->sr_slot = NULL; |
| 698 | } |
| 699 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 700 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 701 | { |
| 702 | struct nfs4_slot *slot = res->sr_slot; |
| 703 | struct nfs4_slot_table *tbl; |
| 704 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 705 | tbl = slot->table; |
| 706 | spin_lock(&tbl->slot_tbl_lock); |
| 707 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 708 | nfs4_free_slot(tbl, slot); |
| 709 | spin_unlock(&tbl->slot_tbl_lock); |
| 710 | |
| 711 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static int nfs40_sequence_done(struct rpc_task *task, |
| 715 | struct nfs4_sequence_res *res) |
| 716 | { |
| 717 | if (res->sr_slot != NULL) |
| 718 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 719 | return 1; |
| 720 | } |
| 721 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 722 | #if defined(CONFIG_NFS_V4_1) |
| 723 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 724 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 725 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 726 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 727 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 728 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 729 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 730 | if (!slot) |
| 731 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 732 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 733 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 734 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 735 | /* Bump the slot sequence number */ |
| 736 | if (slot->seq_done) |
| 737 | slot->seq_nr++; |
| 738 | slot->seq_done = 0; |
| 739 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 740 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 741 | /* Be nice to the server: try to ensure that the last transmitted |
| 742 | * value for highest_user_slotid <= target_highest_slotid |
| 743 | */ |
| 744 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 745 | send_new_highest_used_slotid = true; |
| 746 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 747 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 748 | send_new_highest_used_slotid = false; |
| 749 | goto out_unlock; |
| 750 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 751 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 752 | |
| 753 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 754 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 755 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 756 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 757 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 758 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 759 | if (waitqueue_active(&tbl->slot_waitq)) |
| 760 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 763 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 764 | { |
| 765 | nfs41_release_slot(res->sr_slot); |
| 766 | res->sr_slot = NULL; |
| 767 | } |
| 768 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 769 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 770 | u32 seqnr) |
| 771 | { |
| 772 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 773 | slot->seq_nr_highest_sent = seqnr; |
| 774 | } |
| 775 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 776 | u32 seqnr) |
| 777 | { |
| 778 | slot->seq_nr_highest_sent = seqnr; |
| 779 | slot->seq_nr_last_acked = seqnr; |
| 780 | } |
| 781 | |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 782 | static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
| 783 | struct nfs4_slot *slot) |
| 784 | { |
| 785 | struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
| 786 | if (!IS_ERR(task)) |
| 787 | rpc_put_task_async(task); |
| 788 | } |
| 789 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 790 | static int nfs41_sequence_process(struct rpc_task *task, |
| 791 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 792 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 793 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 794 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 795 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 796 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 797 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 798 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 799 | if (slot == NULL) |
| 800 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 801 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 802 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 803 | goto out; |
| 804 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 805 | session = slot->table->session; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 806 | clp = session->clp; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 807 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 808 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 809 | |
| 810 | status = res->sr_status; |
| 811 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 812 | status = -NFS4ERR_DEADSESSION; |
| 813 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 814 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 815 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 816 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 817 | /* Mark this sequence number as having been acked */ |
| 818 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 819 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 820 | slot->seq_done = 1; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 821 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 822 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 823 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 824 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 825 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 826 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 827 | case 1: |
| 828 | /* |
| 829 | * sr_status remains 1 if an RPC level error occurred. |
| 830 | * The server may or may not have processed the sequence |
| 831 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 832 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 833 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 834 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 835 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 836 | case -NFS4ERR_DELAY: |
| 837 | /* The server detected a resend of the RPC call and |
| 838 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 839 | * of RFC5661. |
| 840 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 841 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 842 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 843 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 844 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 845 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 846 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 847 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 848 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 849 | /* |
| 850 | * The server thinks we tried to replay a request. |
| 851 | * Retry the call after bumping the sequence ID. |
| 852 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 853 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 854 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 855 | case -NFS4ERR_BADSLOT: |
| 856 | /* |
| 857 | * The slot id we used was probably retired. Try again |
| 858 | * using a different slot id. |
| 859 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 860 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 861 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 862 | goto retry_nowait; |
| 863 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 864 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 865 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 866 | * Were one or more calls using this slot interrupted? |
| 867 | * If the server never received the request, then our |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 868 | * transmitted slot sequence number may be too high. However, |
| 869 | * if the server did receive the request then it might |
| 870 | * accidentally give us a reply with a mismatched operation. |
| 871 | * We can sort this out by sending a lone sequence operation |
| 872 | * to the server on the same slot. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 873 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 874 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 875 | slot->seq_nr--; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 876 | if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
| 877 | nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
| 878 | res->sr_slot = NULL; |
| 879 | } |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 880 | goto retry_nowait; |
| 881 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 882 | /* |
| 883 | * RFC5661: |
| 884 | * A retry might be sent while the original request is |
| 885 | * still in progress on the replier. The replier SHOULD |
| 886 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 887 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 888 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 889 | * |
| 890 | * Restart the search after a delay. |
| 891 | */ |
| 892 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 893 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 894 | case -NFS4ERR_BADSESSION: |
| 895 | case -NFS4ERR_DEADSESSION: |
| 896 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 897 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 898 | default: |
| 899 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 900 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 901 | } |
| 902 | out: |
| 903 | /* The session may be reset by one of the error handlers. */ |
| 904 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 905 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 906 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 907 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 908 | nfs4_schedule_session_recovery(session, status); |
| 909 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 910 | nfs41_sequence_free_slot(res); |
| 911 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 912 | retry_new_seq: |
| 913 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 914 | retry_nowait: |
| 915 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 916 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 917 | task->tk_status = 0; |
| 918 | ret = 0; |
| 919 | } |
| 920 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 921 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 922 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 923 | goto out; |
| 924 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 925 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 926 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 927 | |
| 928 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 929 | { |
| 930 | if (!nfs41_sequence_process(task, res)) |
| 931 | return 0; |
| 932 | if (res->sr_slot != NULL) |
| 933 | nfs41_sequence_free_slot(res); |
| 934 | return 1; |
| 935 | |
| 936 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 937 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 938 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 939 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 940 | { |
| 941 | if (res->sr_slot == NULL) |
| 942 | return 1; |
| 943 | if (res->sr_slot->table->session != NULL) |
| 944 | return nfs41_sequence_process(task, res); |
| 945 | return nfs40_sequence_done(task, res); |
| 946 | } |
| 947 | |
| 948 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 949 | { |
| 950 | if (res->sr_slot != NULL) { |
| 951 | if (res->sr_slot->table->session != NULL) |
| 952 | nfs41_sequence_free_slot(res); |
| 953 | else |
| 954 | nfs40_sequence_free_slot(res); |
| 955 | } |
| 956 | } |
| 957 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 958 | int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 959 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 960 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 961 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 962 | if (!res->sr_slot->table->session) |
| 963 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 964 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 965 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 966 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 967 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 968 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 969 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 970 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 971 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 972 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 973 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 974 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 975 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 976 | } |
| 977 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 978 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 979 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 980 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 981 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 982 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 983 | } |
| 984 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 985 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 986 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 987 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 988 | }; |
| 989 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 990 | #else /* !CONFIG_NFS_V4_1 */ |
| 991 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 992 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 993 | { |
| 994 | return nfs40_sequence_done(task, res); |
| 995 | } |
| 996 | |
| 997 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 998 | { |
| 999 | if (res->sr_slot != NULL) |
| 1000 | nfs40_sequence_free_slot(res); |
| 1001 | } |
| 1002 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1003 | int nfs4_sequence_done(struct rpc_task *task, |
| 1004 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1005 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1006 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1007 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1008 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1009 | |
| 1010 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1011 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1012 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 1013 | { |
| 1014 | res->sr_timestamp = jiffies; |
| 1015 | res->sr_status_flags = 0; |
| 1016 | res->sr_status = 1; |
| 1017 | } |
| 1018 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1019 | static |
| 1020 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1021 | struct nfs4_sequence_res *res, |
| 1022 | struct nfs4_slot *slot) |
| 1023 | { |
| 1024 | if (!slot) |
| 1025 | return; |
| 1026 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1027 | args->sa_slot = slot; |
| 1028 | |
| 1029 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1033 | struct nfs4_sequence_args *args, |
| 1034 | struct nfs4_sequence_res *res, |
| 1035 | struct rpc_task *task) |
| 1036 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1037 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1038 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1039 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1040 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1041 | /* slot already allocated? */ |
| 1042 | if (res->sr_slot != NULL) |
| 1043 | goto out_start; |
| 1044 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1045 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1046 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1047 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1048 | spin_lock(&tbl->slot_tbl_lock); |
| 1049 | /* The state manager will wait until the slot table is empty */ |
| 1050 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1051 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1052 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1053 | slot = nfs4_alloc_slot(tbl); |
| 1054 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1055 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1056 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1057 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1058 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1059 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1060 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1061 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1062 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1063 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1064 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1065 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1066 | rpc_call_start(task); |
| 1067 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1068 | out_sleep_timeout: |
| 1069 | /* Try again in 1/4 second */ |
| 1070 | if (args->sa_privileged) |
| 1071 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1072 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1073 | else |
| 1074 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1075 | NULL, jiffies + (HZ >> 2)); |
| 1076 | spin_unlock(&tbl->slot_tbl_lock); |
| 1077 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1078 | out_sleep: |
| 1079 | if (args->sa_privileged) |
| 1080 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1081 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1082 | else |
| 1083 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1084 | spin_unlock(&tbl->slot_tbl_lock); |
| 1085 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1086 | } |
| 1087 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1088 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1089 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1090 | { |
| 1091 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1092 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1093 | data->seq_args, data->seq_res, task); |
| 1094 | } |
| 1095 | |
| 1096 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1097 | { |
| 1098 | struct nfs4_call_sync_data *data = calldata; |
| 1099 | nfs4_sequence_done(task, data->seq_res); |
| 1100 | } |
| 1101 | |
| 1102 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1103 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1104 | .rpc_call_done = nfs40_call_sync_done, |
| 1105 | }; |
| 1106 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1107 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1108 | { |
| 1109 | int ret; |
| 1110 | struct rpc_task *task; |
| 1111 | |
| 1112 | task = rpc_run_task(task_setup); |
| 1113 | if (IS_ERR(task)) |
| 1114 | return PTR_ERR(task); |
| 1115 | |
| 1116 | ret = task->tk_status; |
| 1117 | rpc_put_task(task); |
| 1118 | return ret; |
| 1119 | } |
| 1120 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1121 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1122 | struct nfs_server *server, |
| 1123 | struct rpc_message *msg, |
| 1124 | struct nfs4_sequence_args *args, |
| 1125 | struct nfs4_sequence_res *res, |
| 1126 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1127 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1128 | struct nfs_client *clp = server->nfs_client; |
| 1129 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1130 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1131 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1132 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1133 | }; |
| 1134 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1135 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1136 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1137 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1138 | .callback_data = &data, |
| 1139 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1140 | }; |
| 1141 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1142 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1145 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1146 | struct nfs_server *server, |
| 1147 | struct rpc_message *msg, |
| 1148 | struct nfs4_sequence_args *args, |
| 1149 | struct nfs4_sequence_res *res) |
| 1150 | { |
| 1151 | return nfs4_do_call_sync(clnt, server, msg, args, res, 0); |
| 1152 | } |
| 1153 | |
| 1154 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1155 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1156 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1157 | struct rpc_message *msg, |
| 1158 | struct nfs4_sequence_args *args, |
| 1159 | struct nfs4_sequence_res *res, |
| 1160 | int cache_reply) |
| 1161 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1162 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1163 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1166 | static void |
| 1167 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1168 | { |
| 1169 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1170 | inc_nlink(inode); |
| 1171 | } |
| 1172 | |
| 1173 | static void |
| 1174 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1175 | { |
| 1176 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1177 | drop_nlink(inode); |
| 1178 | } |
| 1179 | |
| 1180 | static void |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1181 | nfs4_update_changeattr_locked(struct inode *inode, |
| 1182 | struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1183 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1185 | struct nfs_inode *nfsi = NFS_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1187 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1188 | | NFS_INO_INVALID_MTIME |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1189 | | cache_validity; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1190 | |
| 1191 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(inode)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1192 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1193 | nfsi->attrtimeo_timestamp = jiffies; |
| 1194 | } else { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1195 | if (S_ISDIR(inode->i_mode)) { |
| 1196 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; |
| 1197 | nfs_force_lookup_revalidate(inode); |
| 1198 | } else { |
| 1199 | if (!NFS_PROTO(inode)->have_delegation(inode, |
| 1200 | FMODE_READ)) |
| 1201 | nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE; |
| 1202 | } |
| 1203 | |
| 1204 | if (cinfo->before != inode_peek_iversion_raw(inode)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1205 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
Frank van der Linden | 0f44da5 | 2020-06-23 22:39:00 +0000 | [diff] [blame] | 1206 | NFS_INO_INVALID_ACL | |
| 1207 | NFS_INO_INVALID_XATTR; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1208 | } |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1209 | inode_set_iversion_raw(inode, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1210 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1211 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1212 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1213 | |
| 1214 | if (nfsi->cache_validity & NFS_INO_INVALID_DATA) |
| 1215 | nfs_fscache_invalidate(inode); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1218 | void |
| 1219 | nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1220 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1221 | { |
| 1222 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1223 | nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | spin_unlock(&dir->i_lock); |
| 1225 | } |
| 1226 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1227 | struct nfs4_open_createattrs { |
| 1228 | struct nfs4_label *label; |
| 1229 | struct iattr *sattr; |
| 1230 | const __u32 verf[2]; |
| 1231 | }; |
| 1232 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1233 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1234 | int err, struct nfs4_exception *exception) |
| 1235 | { |
| 1236 | if (err != -EINVAL) |
| 1237 | return false; |
| 1238 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1239 | return false; |
| 1240 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1241 | exception->retry = 1; |
| 1242 | return true; |
| 1243 | } |
| 1244 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1245 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1246 | { |
| 1247 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1248 | } |
| 1249 | |
| 1250 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1251 | { |
| 1252 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1253 | |
| 1254 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1255 | } |
| 1256 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1257 | static u32 |
| 1258 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1259 | fmode_t fmode, int openflags) |
| 1260 | { |
| 1261 | u32 res = 0; |
| 1262 | |
| 1263 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1264 | case FMODE_READ: |
| 1265 | res = NFS4_SHARE_ACCESS_READ; |
| 1266 | break; |
| 1267 | case FMODE_WRITE: |
| 1268 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1269 | break; |
| 1270 | case FMODE_READ|FMODE_WRITE: |
| 1271 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1272 | } |
| 1273 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1274 | goto out; |
| 1275 | /* Want no delegation if we're using O_DIRECT */ |
| 1276 | if (openflags & O_DIRECT) |
| 1277 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1278 | out: |
| 1279 | return res; |
| 1280 | } |
| 1281 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1282 | static enum open_claim_type4 |
| 1283 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1284 | enum open_claim_type4 claim) |
| 1285 | { |
| 1286 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1287 | return claim; |
| 1288 | switch (claim) { |
| 1289 | default: |
| 1290 | return claim; |
| 1291 | case NFS4_OPEN_CLAIM_FH: |
| 1292 | return NFS4_OPEN_CLAIM_NULL; |
| 1293 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1294 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1295 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1296 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1297 | } |
| 1298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
| 1300 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1301 | { |
| 1302 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1303 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1304 | p->o_res.seqid = p->o_arg.seqid; |
| 1305 | p->c_res.seqid = p->c_arg.seqid; |
| 1306 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1307 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1308 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1309 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1312 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1313 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1314 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1315 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1316 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1317 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1318 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1319 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1320 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1321 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1322 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1323 | struct nfs4_opendata *p; |
| 1324 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1325 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1326 | if (p == NULL) |
| 1327 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1328 | |
| 1329 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1330 | if (IS_ERR(p->f_label)) |
| 1331 | goto err_free_p; |
| 1332 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1333 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1334 | if (IS_ERR(p->a_label)) |
| 1335 | goto err_free_f; |
| 1336 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1337 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1338 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1339 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1340 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1341 | nfs_sb_active(dentry->d_sb); |
| 1342 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1343 | p->dir = parent; |
| 1344 | p->owner = sp; |
| 1345 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | p->o_arg.open_flags = flags; |
| 1347 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1348 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1349 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1350 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1351 | if (flags & O_CREAT) { |
| 1352 | p->o_arg.umask = current_umask(); |
| 1353 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1354 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1355 | p->o_arg.u.attrs = &p->attrs; |
| 1356 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1357 | |
| 1358 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1359 | sizeof(p->o_arg.u.verifier.data)); |
| 1360 | } |
| 1361 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1362 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1363 | * will return permission denied for all bits until close */ |
| 1364 | if (!(flags & O_EXCL)) { |
| 1365 | /* ask server to check for all possible rights as results |
| 1366 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1367 | switch (p->o_arg.claim) { |
| 1368 | default: |
| 1369 | break; |
| 1370 | case NFS4_OPEN_CLAIM_NULL: |
| 1371 | case NFS4_OPEN_CLAIM_FH: |
| 1372 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1373 | NFS4_ACCESS_MODIFY | |
| 1374 | NFS4_ACCESS_EXTEND | |
| 1375 | NFS4_ACCESS_EXECUTE; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1376 | #ifdef CONFIG_NFS_V4_2 |
| 1377 | if (server->caps & NFS_CAP_XATTR) |
| 1378 | p->o_arg.access |= NFS4_ACCESS_XAREAD | |
| 1379 | NFS4_ACCESS_XAWRITE | |
| 1380 | NFS4_ACCESS_XALIST; |
| 1381 | #endif |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1382 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1383 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1384 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1385 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1386 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1387 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1388 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1389 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1390 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1391 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1392 | case NFS4_OPEN_CLAIM_NULL: |
| 1393 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1394 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1395 | p->o_arg.fh = NFS_FH(dir); |
| 1396 | break; |
| 1397 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1398 | case NFS4_OPEN_CLAIM_FH: |
| 1399 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1400 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1401 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1402 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1403 | p->c_arg.fh = &p->o_res.fh; |
| 1404 | p->c_arg.stateid = &p->o_res.stateid; |
| 1405 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1406 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1407 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1408 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1409 | |
| 1410 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1411 | nfs4_label_free(p->a_label); |
| 1412 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1413 | nfs4_label_free(p->f_label); |
| 1414 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1415 | kfree(p); |
| 1416 | err: |
| 1417 | dput(parent); |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1421 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1422 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1423 | struct nfs4_opendata *p = container_of(kref, |
| 1424 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1425 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1426 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1427 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1428 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1429 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1430 | if (p->state != NULL) |
| 1431 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1432 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1433 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1434 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1435 | nfs4_label_free(p->f_label); |
| 1436 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1437 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1438 | dput(p->dentry); |
| 1439 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1440 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1441 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1442 | kfree(p); |
| 1443 | } |
| 1444 | |
| 1445 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1446 | { |
| 1447 | if (p != NULL) |
| 1448 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1449 | } |
| 1450 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1451 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1452 | fmode_t fmode) |
| 1453 | { |
| 1454 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1455 | case FMODE_READ|FMODE_WRITE: |
| 1456 | return state->n_rdwr != 0; |
| 1457 | case FMODE_WRITE: |
| 1458 | return state->n_wronly != 0; |
| 1459 | case FMODE_READ: |
| 1460 | return state->n_rdonly != 0; |
| 1461 | } |
| 1462 | WARN_ON_ONCE(1); |
| 1463 | return false; |
| 1464 | } |
| 1465 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1466 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1467 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1468 | { |
| 1469 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1470 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1471 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1472 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1473 | switch (claim) { |
| 1474 | case NFS4_OPEN_CLAIM_NULL: |
| 1475 | case NFS4_OPEN_CLAIM_FH: |
| 1476 | goto out; |
| 1477 | default: |
| 1478 | break; |
| 1479 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1480 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1481 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1482 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1483 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1484 | break; |
| 1485 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1486 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1487 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1488 | break; |
| 1489 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1490 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1491 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1492 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1493 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1494 | return ret; |
| 1495 | } |
| 1496 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1497 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1498 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1499 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1500 | if (delegation == NULL) |
| 1501 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1502 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1503 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1504 | switch (claim) { |
| 1505 | case NFS4_OPEN_CLAIM_NULL: |
| 1506 | case NFS4_OPEN_CLAIM_FH: |
| 1507 | break; |
| 1508 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1509 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1510 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1511 | fallthrough; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1512 | default: |
| 1513 | return 0; |
| 1514 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1515 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1516 | return 1; |
| 1517 | } |
| 1518 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1519 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1520 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1521 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1522 | case FMODE_WRITE: |
| 1523 | state->n_wronly++; |
| 1524 | break; |
| 1525 | case FMODE_READ: |
| 1526 | state->n_rdonly++; |
| 1527 | break; |
| 1528 | case FMODE_READ|FMODE_WRITE: |
| 1529 | state->n_rdwr++; |
| 1530 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1531 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1532 | } |
| 1533 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1534 | #ifdef CONFIG_NFS_V4_1 |
| 1535 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1536 | { |
| 1537 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1538 | return true; |
| 1539 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1540 | return true; |
| 1541 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1542 | return true; |
| 1543 | return false; |
| 1544 | } |
| 1545 | #endif /* CONFIG_NFS_V4_1 */ |
| 1546 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1547 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1548 | { |
| 1549 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1550 | wake_up_all(&state->waitq); |
| 1551 | } |
| 1552 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1553 | static void nfs_test_and_clear_all_open_stateid(struct nfs4_state *state) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1554 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1555 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1556 | bool need_recover = false; |
| 1557 | |
| 1558 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1559 | need_recover = true; |
| 1560 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1561 | need_recover = true; |
| 1562 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1563 | need_recover = true; |
| 1564 | if (need_recover) |
| 1565 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1566 | } |
| 1567 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1568 | /* |
| 1569 | * Check for whether or not the caller may update the open stateid |
| 1570 | * to the value passed in by stateid. |
| 1571 | * |
| 1572 | * Note: This function relies heavily on the server implementing |
| 1573 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1574 | * correctly. |
| 1575 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1576 | * are then incremented on every state transition. |
| 1577 | */ |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 1578 | static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1579 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1580 | { |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 1581 | if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
| 1582 | /* The common case - we're updating to a new sequence number */ |
| 1583 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1584 | nfs4_stateid_is_next(&state->open_stateid, stateid)) { |
| 1585 | return true; |
| 1586 | } |
| 1587 | } else { |
| 1588 | /* This is the first OPEN in this generation */ |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1589 | if (stateid->seqid == cpu_to_be32(1)) |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 1590 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1591 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1592 | return false; |
| 1593 | } |
| 1594 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1595 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1596 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1597 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1598 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1599 | if (state->n_wronly) |
| 1600 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1601 | if (state->n_rdonly) |
| 1602 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1603 | if (state->n_rdwr) |
| 1604 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1605 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1606 | } |
| 1607 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1608 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1609 | nfs4_stateid *stateid, fmode_t fmode) |
| 1610 | { |
| 1611 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1612 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1613 | case FMODE_WRITE: |
| 1614 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1615 | break; |
| 1616 | case FMODE_READ: |
| 1617 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1618 | break; |
| 1619 | case 0: |
| 1620 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1621 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1622 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1623 | } |
| 1624 | if (stateid == NULL) |
| 1625 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1626 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1627 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1628 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1629 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1630 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1631 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1632 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1633 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1634 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1635 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1636 | out: |
| 1637 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1638 | } |
| 1639 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1640 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1641 | nfs4_stateid *arg_stateid, |
| 1642 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1643 | { |
| 1644 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1645 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1646 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1647 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1648 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1649 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1650 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1651 | } |
| 1652 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1653 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1654 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1655 | __must_hold(&state->owner->so_lock) |
| 1656 | __must_hold(&state->seqlock) |
| 1657 | __must_hold(RCU) |
| 1658 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1659 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1660 | DEFINE_WAIT(wait); |
| 1661 | int status = 0; |
| 1662 | for (;;) { |
| 1663 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 1664 | if (nfs_stateid_is_sequential(state, stateid)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1665 | break; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 1666 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1667 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1668 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1669 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1670 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1671 | break; |
| 1672 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 1673 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1674 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1675 | /* |
| 1676 | * Ensure we process the state changes in the same order |
| 1677 | * in which the server processed them by delaying the |
| 1678 | * update of the stateid until we are in sequence. |
| 1679 | */ |
| 1680 | write_sequnlock(&state->seqlock); |
| 1681 | spin_unlock(&state->owner->so_lock); |
| 1682 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1683 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 1684 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1685 | if (!signal_pending(current)) { |
| 1686 | if (schedule_timeout(5*HZ) == 0) |
| 1687 | status = -EAGAIN; |
| 1688 | else |
| 1689 | status = 0; |
| 1690 | } else |
| 1691 | status = -EINTR; |
| 1692 | finish_wait(&state->waitq, &wait); |
| 1693 | rcu_read_lock(); |
| 1694 | spin_lock(&state->owner->so_lock); |
| 1695 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1696 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1697 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1698 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1699 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1700 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1701 | nfs_test_and_clear_all_open_stateid(state); |
| 1702 | } |
| 1703 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1704 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1705 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1706 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1707 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1708 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1709 | } |
| 1710 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1711 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1712 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1713 | fmode_t fmode, |
| 1714 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1716 | /* |
| 1717 | * Protect the call to nfs4_state_set_mode_locked and |
| 1718 | * serialise the stateid update |
| 1719 | */ |
| 1720 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1721 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1722 | switch (fmode) { |
| 1723 | case FMODE_READ: |
| 1724 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1725 | break; |
| 1726 | case FMODE_WRITE: |
| 1727 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1728 | break; |
| 1729 | case FMODE_READ|FMODE_WRITE: |
| 1730 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1731 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1732 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1733 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1734 | } |
| 1735 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1736 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1737 | { |
| 1738 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1739 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1740 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1741 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1742 | } |
| 1743 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1744 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1745 | const nfs4_stateid *deleg_stateid, |
| 1746 | fmode_t fmode) |
| 1747 | { |
| 1748 | /* |
| 1749 | * Protect the call to nfs4_state_set_mode_locked and |
| 1750 | * serialise the stateid update |
| 1751 | */ |
| 1752 | write_seqlock(&state->seqlock); |
| 1753 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1754 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1755 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1758 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1759 | { |
| 1760 | write_seqlock(&state->seqlock); |
| 1761 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1762 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1763 | write_sequnlock(&state->seqlock); |
| 1764 | } |
| 1765 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1766 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1767 | const nfs4_stateid *open_stateid, |
| 1768 | const nfs4_stateid *delegation, |
| 1769 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1770 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1771 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1772 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1773 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1774 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1775 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1776 | int ret = 0; |
| 1777 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1778 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1779 | |
| 1780 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1781 | spin_lock(&state->owner->so_lock); |
| 1782 | if (open_stateid != NULL) { |
| 1783 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1784 | ret = 1; |
| 1785 | } |
| 1786 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1787 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1788 | if (deleg_cur == NULL) |
| 1789 | goto no_delegation; |
| 1790 | |
| 1791 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1792 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1793 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1794 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1795 | goto no_delegation_unlock; |
| 1796 | |
| 1797 | if (delegation == NULL) |
| 1798 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1799 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1800 | goto no_delegation_unlock; |
| 1801 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1802 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1803 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1804 | ret = 1; |
| 1805 | no_delegation_unlock: |
| 1806 | spin_unlock(&deleg_cur->lock); |
| 1807 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1808 | if (ret) |
| 1809 | update_open_stateflags(state, fmode); |
| 1810 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1811 | rcu_read_unlock(); |
| 1812 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1813 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1814 | nfs4_schedule_state_manager(clp); |
| 1815 | if (freeme.type != 0) |
| 1816 | nfs4_test_and_free_stateid(server, &freeme, |
| 1817 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1818 | |
| 1819 | return ret; |
| 1820 | } |
| 1821 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1822 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1823 | const nfs4_stateid *stateid) |
| 1824 | { |
| 1825 | struct nfs4_state *state = lsp->ls_state; |
| 1826 | bool ret = false; |
| 1827 | |
| 1828 | spin_lock(&state->state_lock); |
| 1829 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1830 | goto out_noupdate; |
| 1831 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1832 | goto out_noupdate; |
| 1833 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1834 | ret = true; |
| 1835 | out_noupdate: |
| 1836 | spin_unlock(&state->state_lock); |
| 1837 | return ret; |
| 1838 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1839 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1840 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1841 | { |
| 1842 | struct nfs_delegation *delegation; |
| 1843 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1844 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1845 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1846 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1847 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1848 | rcu_read_unlock(); |
| 1849 | return; |
| 1850 | } |
| 1851 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1852 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1853 | } |
| 1854 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1855 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1856 | { |
| 1857 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1858 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1859 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1860 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1861 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1862 | nfs4_stateid stateid; |
| 1863 | int ret = -EAGAIN; |
| 1864 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1865 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1866 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1867 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1868 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1869 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1870 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1871 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1872 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1873 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1874 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1875 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1876 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1877 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1878 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1879 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1880 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1881 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1882 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1883 | if (!opendata->is_recover) { |
| 1884 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1885 | if (ret != 0) |
| 1886 | goto out; |
| 1887 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1888 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1889 | |
| 1890 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1891 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1892 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1893 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1894 | out: |
| 1895 | return ERR_PTR(ret); |
| 1896 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1897 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1898 | return state; |
| 1899 | } |
| 1900 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1901 | static void |
| 1902 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1903 | { |
| 1904 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1905 | struct nfs_delegation *delegation; |
| 1906 | int delegation_flags = 0; |
| 1907 | |
| 1908 | rcu_read_lock(); |
| 1909 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1910 | if (delegation) |
| 1911 | delegation_flags = delegation->flags; |
| 1912 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1913 | switch (data->o_arg.claim) { |
| 1914 | default: |
| 1915 | break; |
| 1916 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1917 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1918 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1919 | "returning a delegation for " |
| 1920 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1921 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1922 | return; |
| 1923 | } |
| 1924 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1925 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1926 | data->owner->so_cred, |
| 1927 | data->o_res.delegation_type, |
| 1928 | &data->o_res.delegation, |
| 1929 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1930 | else |
| 1931 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1932 | data->owner->so_cred, |
| 1933 | data->o_res.delegation_type, |
| 1934 | &data->o_res.delegation, |
| 1935 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1936 | |
| 1937 | if (data->o_res.do_recall) |
| 1938 | nfs_async_inode_return_delegation(state->inode, |
| 1939 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | /* |
| 1943 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1944 | * and update the nfs4_state. |
| 1945 | */ |
| 1946 | static struct nfs4_state * |
| 1947 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1948 | { |
| 1949 | struct inode *inode = data->state->inode; |
| 1950 | struct nfs4_state *state = data->state; |
| 1951 | int ret; |
| 1952 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1953 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1954 | if (data->rpc_status) |
| 1955 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1956 | /* cached opens have already been processed */ |
| 1957 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1958 | } |
| 1959 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1960 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1961 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1962 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1963 | |
| 1964 | if (data->o_res.delegation_type != 0) |
| 1965 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1966 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1967 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1968 | NULL, data->o_arg.fmode)) |
| 1969 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1970 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1971 | |
| 1972 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1973 | } |
| 1974 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1975 | static struct inode * |
| 1976 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1977 | { |
| 1978 | struct inode *inode; |
| 1979 | |
| 1980 | switch (data->o_arg.claim) { |
| 1981 | case NFS4_OPEN_CLAIM_NULL: |
| 1982 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1983 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1984 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1985 | return ERR_PTR(-EAGAIN); |
| 1986 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1987 | &data->f_attr, data->f_label); |
| 1988 | break; |
| 1989 | default: |
| 1990 | inode = d_inode(data->dentry); |
| 1991 | ihold(inode); |
| 1992 | nfs_refresh_inode(inode, &data->f_attr); |
| 1993 | } |
| 1994 | return inode; |
| 1995 | } |
| 1996 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1997 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1998 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1999 | { |
| 2000 | struct nfs4_state *state; |
| 2001 | struct inode *inode; |
| 2002 | |
| 2003 | inode = nfs4_opendata_get_inode(data); |
| 2004 | if (IS_ERR(inode)) |
| 2005 | return ERR_CAST(inode); |
| 2006 | if (data->state != NULL && data->state->inode == inode) { |
| 2007 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2008 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2009 | } else |
| 2010 | state = nfs4_get_open_state(inode, data->owner); |
| 2011 | iput(inode); |
| 2012 | if (state == NULL) |
| 2013 | state = ERR_PTR(-ENOMEM); |
| 2014 | return state; |
| 2015 | } |
| 2016 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2017 | static struct nfs4_state * |
| 2018 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2019 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2020 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2021 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2022 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2023 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2024 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2025 | goto out; |
| 2026 | } |
| 2027 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2028 | state = nfs4_opendata_find_nfs4_state(data); |
| 2029 | if (IS_ERR(state)) |
| 2030 | goto out; |
| 2031 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2032 | if (data->o_res.delegation_type != 0) |
| 2033 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2034 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2035 | NULL, data->o_arg.fmode)) { |
| 2036 | nfs4_put_open_state(state); |
| 2037 | state = ERR_PTR(-EAGAIN); |
| 2038 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2039 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2040 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2041 | return state; |
| 2042 | } |
| 2043 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2044 | static struct nfs4_state * |
| 2045 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2046 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2047 | struct nfs4_state *ret; |
| 2048 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2049 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2050 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2051 | else |
| 2052 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2053 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2054 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2055 | } |
| 2056 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2057 | static struct nfs_open_context * |
| 2058 | nfs4_state_find_open_context_mode(struct nfs4_state *state, fmode_t mode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2059 | { |
| 2060 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2061 | struct nfs_open_context *ctx; |
| 2062 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2063 | rcu_read_lock(); |
| 2064 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2065 | if (ctx->state != state) |
| 2066 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2067 | if ((ctx->mode & mode) != mode) |
| 2068 | continue; |
| 2069 | if (!get_nfs_open_context(ctx)) |
| 2070 | continue; |
| 2071 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2072 | return ctx; |
| 2073 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2074 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2075 | return ERR_PTR(-ENOENT); |
| 2076 | } |
| 2077 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2078 | static struct nfs_open_context * |
| 2079 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2080 | { |
| 2081 | struct nfs_open_context *ctx; |
| 2082 | |
| 2083 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2084 | if (!IS_ERR(ctx)) |
| 2085 | return ctx; |
| 2086 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2087 | if (!IS_ERR(ctx)) |
| 2088 | return ctx; |
| 2089 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2090 | } |
| 2091 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2092 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2093 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2094 | { |
| 2095 | struct nfs4_opendata *opendata; |
| 2096 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2097 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2098 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2099 | if (opendata == NULL) |
| 2100 | return ERR_PTR(-ENOMEM); |
| 2101 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2102 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2103 | return opendata; |
| 2104 | } |
| 2105 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2106 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2107 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2108 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2109 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2110 | int ret; |
| 2111 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2112 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2113 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2114 | opendata->o_arg.open_flags = 0; |
| 2115 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2116 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2117 | NFS_SB(opendata->dentry->d_sb), |
| 2118 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2119 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2120 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2121 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2122 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2123 | if (ret != 0) |
| 2124 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2125 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2126 | if (IS_ERR(newstate)) |
| 2127 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2128 | if (newstate != opendata->state) |
| 2129 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2130 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2131 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2135 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2136 | int ret; |
| 2137 | |
| 2138 | /* memory barrier prior to reading state->n_* */ |
| 2139 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2140 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2141 | if (ret != 0) |
| 2142 | return ret; |
| 2143 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2144 | if (ret != 0) |
| 2145 | return ret; |
| 2146 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2147 | if (ret != 0) |
| 2148 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2149 | /* |
| 2150 | * We may have performed cached opens for all three recoveries. |
| 2151 | * Check if we need to update the current stateid. |
| 2152 | */ |
| 2153 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2154 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2155 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2156 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2157 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2158 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2159 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2160 | return 0; |
| 2161 | } |
| 2162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | /* |
| 2164 | * OPEN_RECLAIM: |
| 2165 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2167 | static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2169 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2170 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2171 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | int status; |
| 2173 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2174 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2175 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2176 | if (IS_ERR(opendata)) |
| 2177 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2178 | rcu_read_lock(); |
| 2179 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2180 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2181 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2182 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2183 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2184 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2185 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | return status; |
| 2187 | } |
| 2188 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2189 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | { |
| 2191 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2192 | struct nfs4_exception exception = { }; |
| 2193 | int err; |
| 2194 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2195 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2196 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2197 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2198 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2199 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2200 | break; |
| 2201 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | } while (exception.retry); |
| 2203 | return err; |
| 2204 | } |
| 2205 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2206 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2207 | { |
| 2208 | struct nfs_open_context *ctx; |
| 2209 | int ret; |
| 2210 | |
| 2211 | ctx = nfs4_state_find_open_context(state); |
| 2212 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2213 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2214 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2215 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2216 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2217 | put_nfs_open_context(ctx); |
| 2218 | return ret; |
| 2219 | } |
| 2220 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2221 | static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, struct file_lock *fl, int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2223 | switch (err) { |
| 2224 | default: |
| 2225 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2226 | "%d.\n", __func__, err); |
| 2227 | case 0: |
| 2228 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2229 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2230 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2231 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2232 | break; |
| 2233 | case -NFS4ERR_BADSESSION: |
| 2234 | case -NFS4ERR_BADSLOT: |
| 2235 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2236 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2237 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2238 | return -EAGAIN; |
| 2239 | case -NFS4ERR_STALE_CLIENTID: |
| 2240 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2241 | /* Don't recall a delegation if it was lost */ |
| 2242 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2243 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2244 | case -NFS4ERR_MOVED: |
| 2245 | nfs4_schedule_migration_recovery(server); |
| 2246 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2247 | case -NFS4ERR_LEASE_MOVED: |
| 2248 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2249 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2250 | case -NFS4ERR_DELEG_REVOKED: |
| 2251 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2252 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2253 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2254 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2255 | nfs_inode_find_state_and_recover(state->inode, |
| 2256 | stateid); |
| 2257 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2258 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2259 | case -NFS4ERR_DELAY: |
| 2260 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2261 | ssleep(1); |
| 2262 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2263 | case -ENOMEM: |
| 2264 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2265 | if (fl) { |
| 2266 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2267 | if (lsp) |
| 2268 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2269 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2270 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | return err; |
| 2273 | } |
| 2274 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2275 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2276 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2277 | { |
| 2278 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2279 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2280 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2281 | |
| 2282 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2283 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2284 | if (IS_ERR(opendata)) |
| 2285 | return PTR_ERR(opendata); |
| 2286 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2287 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2288 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2289 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2290 | goto out; |
| 2291 | } |
| 2292 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2293 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2294 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2295 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2296 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2297 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2298 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2299 | if (err) |
| 2300 | goto out; |
| 2301 | } |
| 2302 | nfs_state_clear_delegation(state); |
| 2303 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2304 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2305 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2306 | } |
| 2307 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2308 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2309 | { |
| 2310 | struct nfs4_opendata *data = calldata; |
| 2311 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2312 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2313 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2314 | } |
| 2315 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2316 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2317 | { |
| 2318 | struct nfs4_opendata *data = calldata; |
| 2319 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2320 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2321 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2322 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2323 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2324 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2325 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2326 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2327 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2328 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | static void nfs4_open_confirm_release(void *calldata) |
| 2332 | { |
| 2333 | struct nfs4_opendata *data = calldata; |
| 2334 | struct nfs4_state *state = NULL; |
| 2335 | |
| 2336 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2337 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2338 | goto out_free; |
| 2339 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2340 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2341 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2342 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2343 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2344 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2345 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2346 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2350 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2351 | .rpc_call_done = nfs4_open_confirm_done, |
| 2352 | .rpc_release = nfs4_open_confirm_release, |
| 2353 | }; |
| 2354 | |
| 2355 | /* |
| 2356 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2357 | */ |
| 2358 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2359 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2360 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2361 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2362 | struct rpc_message msg = { |
| 2363 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2364 | .rpc_argp = &data->c_arg, |
| 2365 | .rpc_resp = &data->c_res, |
| 2366 | .rpc_cred = data->owner->so_cred, |
| 2367 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2368 | struct rpc_task_setup task_setup_data = { |
| 2369 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2370 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2371 | .callback_ops = &nfs4_open_confirm_ops, |
| 2372 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2373 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2374 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2375 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | int status; |
| 2377 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2378 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2379 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2380 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2381 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2382 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2383 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2384 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2385 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2386 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2387 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2388 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2389 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2390 | smp_wmb(); |
| 2391 | } else |
| 2392 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2393 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | return status; |
| 2395 | } |
| 2396 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2397 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2399 | struct nfs4_opendata *data = calldata; |
| 2400 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2401 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2402 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2403 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2404 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2405 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2406 | /* |
| 2407 | * Check if we still need to send an OPEN call, or if we can use |
| 2408 | * a delegation instead. |
| 2409 | */ |
| 2410 | if (data->state != NULL) { |
| 2411 | struct nfs_delegation *delegation; |
| 2412 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2413 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2414 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2415 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2416 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2417 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2418 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2419 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2420 | rcu_read_unlock(); |
| 2421 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2422 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2423 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2424 | switch (claim) { |
| 2425 | default: |
| 2426 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2427 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2428 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2429 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2430 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2431 | fallthrough; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2432 | case NFS4_OPEN_CLAIM_FH: |
| 2433 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2434 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2435 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2436 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2437 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2438 | &data->o_res.seq_res, |
| 2439 | task) != 0) |
| 2440 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2441 | |
| 2442 | /* Set the create mode (note dependency on the session type) */ |
| 2443 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2444 | if (data->o_arg.open_flags & O_EXCL) { |
| 2445 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2446 | if (nfs4_has_persistent_session(clp)) |
| 2447 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2448 | else if (clp->cl_mvops->minor_version > 0) |
| 2449 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2450 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2451 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2452 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2453 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2454 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2455 | out_no_action: |
| 2456 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2457 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2458 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2459 | } |
| 2460 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2461 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2462 | { |
| 2463 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2465 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2466 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2467 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2468 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2469 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2470 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2471 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2472 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2473 | case S_IFREG: |
| 2474 | break; |
| 2475 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2476 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2477 | break; |
| 2478 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2479 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2480 | break; |
| 2481 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2482 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2483 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2484 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2485 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2486 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2487 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2488 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2489 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2490 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2491 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2492 | static void nfs4_open_release(void *calldata) |
| 2493 | { |
| 2494 | struct nfs4_opendata *data = calldata; |
| 2495 | struct nfs4_state *state = NULL; |
| 2496 | |
| 2497 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2498 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2499 | goto out_free; |
| 2500 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2501 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2502 | goto out_free; |
| 2503 | /* In case we need an open_confirm, no cleanup! */ |
| 2504 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2505 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2506 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2507 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2508 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2509 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2510 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2514 | .rpc_call_prepare = nfs4_open_prepare, |
| 2515 | .rpc_call_done = nfs4_open_done, |
| 2516 | .rpc_release = nfs4_open_release, |
| 2517 | }; |
| 2518 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2519 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2520 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2521 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2522 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2523 | struct nfs_server *server = NFS_SERVER(dir); |
| 2524 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2525 | struct nfs_openres *o_res = &data->o_res; |
| 2526 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2527 | struct rpc_message msg = { |
| 2528 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2529 | .rpc_argp = o_arg, |
| 2530 | .rpc_resp = o_res, |
| 2531 | .rpc_cred = data->owner->so_cred, |
| 2532 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2533 | struct rpc_task_setup task_setup_data = { |
| 2534 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2535 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2536 | .callback_ops = &nfs4_open_ops, |
| 2537 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2538 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2539 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2540 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2541 | int status; |
| 2542 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2543 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2544 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2545 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2546 | data->cancelled = false; |
| 2547 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2548 | if (!ctx) { |
| 2549 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 1); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2550 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2551 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2552 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2553 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 0); |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2554 | pnfs_lgopen_prepare(data, ctx); |
| 2555 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2556 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2557 | if (IS_ERR(task)) |
| 2558 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2559 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2560 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2561 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2562 | smp_wmb(); |
| 2563 | } else |
| 2564 | status = data->rpc_status; |
| 2565 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2566 | |
| 2567 | return status; |
| 2568 | } |
| 2569 | |
| 2570 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2571 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2572 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2573 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2574 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2575 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2576 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2577 | if (status != 0 || !data->rpc_done) |
| 2578 | return status; |
| 2579 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2580 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2581 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2582 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2583 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2584 | |
| 2585 | return status; |
| 2586 | } |
| 2587 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2588 | /* |
| 2589 | * Additional permission checks in order to distinguish between an |
| 2590 | * open for read, and an open for execute. This works around the |
| 2591 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2592 | * the same. |
| 2593 | * Note that in the non-execute case, we want to turn off permission |
| 2594 | * checking if we just created a new file (POSIX open() semantics). |
| 2595 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2596 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2597 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2598 | struct nfs4_state *state, fmode_t fmode, |
| 2599 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2600 | { |
| 2601 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2602 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2603 | |
| 2604 | /* access call failed or for some reason the server doesn't |
| 2605 | * support any access modes -- defer access call until later */ |
| 2606 | if (opendata->o_res.access_supported == 0) |
| 2607 | return 0; |
| 2608 | |
| 2609 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2610 | /* |
| 2611 | * Use openflags to check for exec, because fmode won't |
| 2612 | * always have FMODE_EXEC set when file open for exec. |
| 2613 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2614 | if (openflags & __FMODE_EXEC) { |
| 2615 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2616 | if (S_ISDIR(state->inode->i_mode)) |
| 2617 | mask = NFS4_ACCESS_LOOKUP; |
| 2618 | else |
| 2619 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2620 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2621 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2622 | |
| 2623 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2624 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2625 | nfs_access_add_cache(state->inode, &cache); |
| 2626 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2627 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2628 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2629 | return 0; |
| 2630 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2631 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2632 | } |
| 2633 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2634 | /* |
| 2635 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2636 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2637 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2638 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2639 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2640 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2641 | struct nfs_server *server = NFS_SERVER(dir); |
| 2642 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2643 | struct nfs_openres *o_res = &data->o_res; |
| 2644 | int status; |
| 2645 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2646 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2647 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2648 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2649 | if (status != 0) { |
| 2650 | if (status == -NFS4ERR_BADNAME && |
| 2651 | !(o_arg->open_flags & O_CREAT)) |
| 2652 | return -ENOENT; |
| 2653 | return status; |
| 2654 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2655 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2656 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2657 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2658 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2659 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2660 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2661 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2662 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2663 | if (data->file_created || |
| 2664 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 2665 | nfs4_update_changeattr(dir, &o_res->cinfo, |
| 2666 | o_res->f_attr->time_start, |
| 2667 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2668 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2669 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2670 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2672 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2674 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2676 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2677 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2678 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2679 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2680 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2681 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | /* |
| 2685 | * OPEN_EXPIRED: |
| 2686 | * reclaim state on the server after a network partition. |
| 2687 | * Assumes caller holds the appropriate lock |
| 2688 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2689 | static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2691 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2692 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2694 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2695 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2696 | if (IS_ERR(opendata)) |
| 2697 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2698 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2699 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2700 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2701 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2702 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2705 | static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2706 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2707 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2708 | struct nfs4_exception exception = { }; |
| 2709 | int err; |
| 2710 | |
| 2711 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2712 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2713 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2714 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2715 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2716 | switch (err) { |
| 2717 | default: |
| 2718 | goto out; |
| 2719 | case -NFS4ERR_GRACE: |
| 2720 | case -NFS4ERR_DELAY: |
| 2721 | nfs4_handle_exception(server, err, &exception); |
| 2722 | err = 0; |
| 2723 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2724 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2725 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2726 | return err; |
| 2727 | } |
| 2728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2730 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2732 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2734 | ctx = nfs4_state_find_open_context(state); |
| 2735 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2736 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2737 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2738 | put_nfs_open_context(ctx); |
| 2739 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2742 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2743 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2744 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2745 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2746 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2750 | { |
| 2751 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2752 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2756 | { |
| 2757 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2758 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2759 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2760 | return nfs4_open_expired(sp, state); |
| 2761 | } |
| 2762 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2763 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2764 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2765 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2766 | { |
| 2767 | return -NFS4ERR_BAD_STATEID; |
| 2768 | } |
| 2769 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2770 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2771 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2772 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2773 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2774 | { |
| 2775 | int status; |
| 2776 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2777 | switch (stateid->type) { |
| 2778 | default: |
| 2779 | break; |
| 2780 | case NFS4_INVALID_STATEID_TYPE: |
| 2781 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2782 | return -NFS4ERR_BAD_STATEID; |
| 2783 | case NFS4_REVOKED_STATEID_TYPE: |
| 2784 | goto out_free; |
| 2785 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2786 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2787 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2788 | switch (status) { |
| 2789 | case -NFS4ERR_EXPIRED: |
| 2790 | case -NFS4ERR_ADMIN_REVOKED: |
| 2791 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2792 | break; |
| 2793 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2794 | return status; |
| 2795 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2796 | out_free: |
| 2797 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2798 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2799 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2802 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2803 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2804 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2805 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2806 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2807 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2808 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2809 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2810 | /* Get the delegation credential for use by test/free_stateid */ |
| 2811 | rcu_read_lock(); |
| 2812 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2813 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2814 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2815 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2816 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2817 | } |
| 2818 | |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2819 | spin_lock(&delegation->lock); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2820 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2821 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2822 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2823 | &delegation->flags)) { |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2824 | spin_unlock(&delegation->lock); |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2825 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2826 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2827 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2828 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2829 | if (delegation->cred) |
| 2830 | cred = get_cred(delegation->cred); |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2831 | spin_unlock(&delegation->lock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2832 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2833 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2834 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2835 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2836 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2837 | else |
| 2838 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2839 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2840 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2841 | return ret; |
| 2842 | } |
| 2843 | |
| 2844 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2845 | { |
| 2846 | nfs4_stateid tmp; |
| 2847 | |
| 2848 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2849 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2850 | &tmp, NULL) && |
| 2851 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2852 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2853 | else |
| 2854 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2858 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2859 | * |
| 2860 | * @state: NFSv4 state for an inode |
| 2861 | * |
| 2862 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2863 | * Otherwise a negative NFS4ERR value is returned. |
| 2864 | */ |
| 2865 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2866 | { |
| 2867 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2868 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2869 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2870 | |
| 2871 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2872 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2873 | |
| 2874 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2875 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2876 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2877 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2878 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2879 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2880 | spin_unlock(&state->state_lock); |
| 2881 | |
| 2882 | nfs4_put_lock_state(prev); |
| 2883 | prev = lsp; |
| 2884 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2885 | status = nfs41_test_and_free_expired_stateid(server, |
| 2886 | &lsp->ls_stateid, |
| 2887 | cred); |
| 2888 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2889 | if (status == -NFS4ERR_EXPIRED || |
| 2890 | status == -NFS4ERR_BAD_STATEID) { |
| 2891 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2892 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2893 | if (!recover_lost_locks) |
| 2894 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2895 | } else if (status != NFS_OK) { |
| 2896 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2897 | nfs4_put_lock_state(prev); |
| 2898 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2899 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2900 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2901 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2902 | } |
| 2903 | spin_unlock(&state->state_lock); |
| 2904 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2905 | out: |
| 2906 | return ret; |
| 2907 | } |
| 2908 | |
| 2909 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2910 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2911 | * |
| 2912 | * @state: NFSv4 state for an inode |
| 2913 | * |
| 2914 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2915 | * Otherwise a negative NFS4ERR value is returned. |
| 2916 | */ |
| 2917 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2918 | { |
| 2919 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2920 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2921 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2922 | int status; |
| 2923 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2924 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2925 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2926 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2927 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2928 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2929 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2930 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2931 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2932 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2933 | if (nfs_open_stateid_recover_openmode(state)) |
| 2934 | return -NFS4ERR_OPENMODE; |
| 2935 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2939 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2940 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2941 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2942 | status = nfs41_check_delegation_stateid(state); |
| 2943 | if (status != NFS_OK) |
| 2944 | return status; |
| 2945 | nfs41_delegation_recover_stateid(state); |
| 2946 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2947 | status = nfs41_check_expired_locks(state); |
| 2948 | if (status != NFS_OK) |
| 2949 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2950 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2951 | if (status != NFS_OK) |
| 2952 | status = nfs4_open_expired(sp, state); |
| 2953 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2954 | } |
| 2955 | #endif |
| 2956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2958 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2959 | * fields corresponding to attributes that were used to store the verifier. |
| 2960 | * Make sure we clobber those fields in the later setattr call |
| 2961 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2962 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2963 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2964 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2965 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2966 | __u32 attrset[3]; |
| 2967 | unsigned ret; |
| 2968 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2969 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2970 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2971 | attrset[i] = opendata->o_res.attrset[i]; |
| 2972 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2973 | attrset[i] &= ~bitmask[i]; |
| 2974 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2975 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2976 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2977 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2978 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2979 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2980 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2981 | ret |= ATTR_ATIME_SET; |
| 2982 | else |
| 2983 | ret |= ATTR_ATIME; |
| 2984 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2985 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2986 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2987 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2988 | ret |= ATTR_MTIME_SET; |
| 2989 | else |
| 2990 | ret |= ATTR_MTIME; |
| 2991 | } |
| 2992 | |
| 2993 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2994 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2995 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2996 | } |
| 2997 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2998 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 2999 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3000 | { |
| 3001 | struct nfs4_state_owner *sp = opendata->owner; |
| 3002 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3003 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3004 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3005 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3006 | struct inode *dir = d_inode(opendata->dir); |
| 3007 | unsigned long dir_verifier; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3008 | unsigned int seq; |
| 3009 | int ret; |
| 3010 | |
| 3011 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3012 | dir_verifier = nfs_save_change_attribute(dir); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3013 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 3014 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 3015 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3016 | goto out; |
| 3017 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 3018 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3019 | ret = PTR_ERR(state); |
| 3020 | if (IS_ERR(state)) |
| 3021 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 3022 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3023 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 3024 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 3025 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 3026 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3027 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3028 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3029 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3030 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3031 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3032 | alias = d_exact_alias(dentry, state->inode); |
| 3033 | if (!alias) |
| 3034 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3035 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3036 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3037 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3038 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3039 | } |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | switch(opendata->o_arg.claim) { |
| 3043 | default: |
| 3044 | break; |
| 3045 | case NFS4_OPEN_CLAIM_NULL: |
| 3046 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 3047 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 3048 | if (!opendata->rpc_done) |
| 3049 | break; |
| 3050 | if (opendata->o_res.delegation_type != 0) |
| 3051 | dir_verifier = nfs_save_change_attribute(dir); |
| 3052 | nfs_set_verifier(dentry, dir_verifier); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3053 | } |
| 3054 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3055 | /* Parse layoutget results before we check for access */ |
| 3056 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3057 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3058 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3059 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3060 | if (ret != 0) |
| 3061 | goto out; |
| 3062 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3063 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3064 | nfs_inode_attach_open_context(ctx); |
| 3065 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3066 | nfs4_schedule_stateid_recovery(server, state); |
| 3067 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3068 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3069 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3070 | if (!opendata->cancelled) |
| 3071 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3072 | return ret; |
| 3073 | } |
| 3074 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3075 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3076 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3078 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3079 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3080 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3081 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3082 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | { |
| 3084 | struct nfs4_state_owner *sp; |
| 3085 | struct nfs4_state *state = NULL; |
| 3086 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3087 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3088 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3089 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3090 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3091 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3092 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3093 | struct iattr *sattr = c->sattr; |
| 3094 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3095 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3096 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | |
| 3098 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3100 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3101 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3103 | goto out_err; |
| 3104 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3105 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3106 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3107 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3108 | if (d_really_is_positive(dentry)) |
| 3109 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3110 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3111 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3112 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3113 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3114 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3115 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3116 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3118 | if (label) { |
| 3119 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 3120 | if (IS_ERR(olabel)) { |
| 3121 | status = PTR_ERR(olabel); |
| 3122 | goto err_opendata_put; |
| 3123 | } |
| 3124 | } |
| 3125 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3126 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3127 | if (!opendata->f_attr.mdsthreshold) { |
| 3128 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3129 | if (!opendata->f_attr.mdsthreshold) |
| 3130 | goto err_free_label; |
| 3131 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3132 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3133 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3134 | if (d_really_is_positive(dentry)) |
| 3135 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3136 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3137 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3138 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3139 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3140 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3141 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3142 | if ((opendata->o_arg.open_flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL) && |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 3143 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3144 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3145 | /* |
| 3146 | * send create attributes which was not set by open |
| 3147 | * with an extra setattr. |
| 3148 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3149 | if (attrs || label) { |
| 3150 | unsigned ia_old = sattr->ia_valid; |
| 3151 | |
| 3152 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3153 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3154 | status = nfs4_do_setattr(state->inode, cred, |
| 3155 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3156 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3157 | if (status == 0) { |
| 3158 | nfs_setattr_update_inode(state->inode, sattr, |
| 3159 | opendata->o_res.f_attr); |
| 3160 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 3161 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3162 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3163 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3164 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3165 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3166 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3167 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3168 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3169 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3170 | opendata->f_attr.mdsthreshold = NULL; |
| 3171 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3172 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3173 | nfs4_label_free(olabel); |
| 3174 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3175 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3178 | err_free_label: |
| 3179 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3180 | err_opendata_put: |
| 3181 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3182 | err_put_state_owner: |
| 3183 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | return status; |
| 3186 | } |
| 3187 | |
| 3188 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3189 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3190 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3191 | int flags, |
| 3192 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3193 | struct nfs4_label *label, |
| 3194 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3196 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3197 | struct nfs4_exception exception = { |
| 3198 | .interruptible = true, |
| 3199 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3201 | struct nfs4_open_createattrs c = { |
| 3202 | .label = label, |
| 3203 | .sattr = sattr, |
| 3204 | .verf = { |
| 3205 | [0] = (__u32)jiffies, |
| 3206 | [1] = (__u32)current->pid, |
| 3207 | }, |
| 3208 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | int status; |
| 3210 | |
| 3211 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3212 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3213 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3214 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | if (status == 0) |
| 3216 | break; |
| 3217 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3218 | * book-keeping w.r.t. state-changing operations |
| 3219 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3220 | * It is actually a sign of a bug on the client or on the server. |
| 3221 | * |
| 3222 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3223 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | * have unhashed the old state_owner for us, and that we can |
| 3225 | * therefore safely retry using a new one. We should still warn |
| 3226 | * the user though... |
| 3227 | */ |
| 3228 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3229 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3230 | " returned a bad sequence-id error!\n", |
| 3231 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | exception.retry = 1; |
| 3233 | continue; |
| 3234 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3235 | /* |
| 3236 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3237 | * state before it received the OPEN_CONFIRM. |
| 3238 | * Recover by retrying the request as per the discussion |
| 3239 | * on Page 181 of RFC3530. |
| 3240 | */ |
| 3241 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3242 | exception.retry = 1; |
| 3243 | continue; |
| 3244 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame] | 3245 | if (status == -NFS4ERR_EXPIRED) { |
| 3246 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3247 | exception.retry = 1; |
| 3248 | continue; |
| 3249 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3250 | if (status == -EAGAIN) { |
| 3251 | /* We must have found a delegation */ |
| 3252 | exception.retry = 1; |
| 3253 | continue; |
| 3254 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3255 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3256 | continue; |
| 3257 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | status, &exception)); |
| 3259 | } while (exception.retry); |
| 3260 | return res; |
| 3261 | } |
| 3262 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3263 | static int _nfs4_do_setattr(struct inode *inode, |
| 3264 | struct nfs_setattrargs *arg, |
| 3265 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3266 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3267 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3268 | { |
| 3269 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3270 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3272 | .rpc_argp = arg, |
| 3273 | .rpc_resp = res, |
| 3274 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3275 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3276 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3277 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3278 | bool truncate; |
| 3279 | int status; |
| 3280 | |
| 3281 | nfs_fattr_init(res->fattr); |
| 3282 | |
| 3283 | /* Servers should only apply open mode checks for file size changes */ |
| 3284 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3285 | if (!truncate) { |
| 3286 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3287 | goto zero_stateid; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3288 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3289 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3290 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3291 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3292 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3293 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3294 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3295 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3296 | l_ctx = nfs_get_lock_context(ctx); |
| 3297 | if (IS_ERR(l_ctx)) |
| 3298 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3299 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3300 | &arg->stateid, &delegation_cred); |
| 3301 | nfs_put_lock_context(l_ctx); |
| 3302 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3303 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3304 | else if (status == -EAGAIN) |
| 3305 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3306 | } else { |
| 3307 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3308 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3309 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3310 | if (delegation_cred) |
| 3311 | msg.rpc_cred = delegation_cred; |
| 3312 | |
| 3313 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3314 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3315 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3316 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3317 | renew_lease(server, timestamp); |
| 3318 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3319 | return status; |
| 3320 | } |
| 3321 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3322 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3323 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3324 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3325 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3327 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3328 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3329 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3330 | struct nfs_setattrargs arg = { |
| 3331 | .fh = NFS_FH(inode), |
| 3332 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3334 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3335 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3336 | }; |
| 3337 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3339 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3341 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3342 | struct nfs4_exception exception = { |
| 3343 | .state = state, |
| 3344 | .inode = inode, |
| 3345 | .stateid = &arg.stateid, |
| 3346 | }; |
| 3347 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3350 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3351 | nfs4_bitmask(server, olabel), |
| 3352 | inode); |
| 3353 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3354 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3355 | switch (err) { |
| 3356 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3357 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3358 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3359 | "applying open mode checks to " |
| 3360 | "a SETATTR that is not " |
| 3361 | "changing file size.\n", |
| 3362 | server->nfs_client->cl_hostname); |
| 3363 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3364 | if (state && !(state->state & FMODE_WRITE)) { |
| 3365 | err = -EBADF; |
| 3366 | if (sattr->ia_valid & ATTR_OPEN) |
| 3367 | err = -EACCES; |
| 3368 | goto out; |
| 3369 | } |
| 3370 | } |
| 3371 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3373 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | return err; |
| 3375 | } |
| 3376 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3377 | static bool |
| 3378 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3379 | { |
| 3380 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3381 | return false; |
| 3382 | |
| 3383 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3384 | } |
| 3385 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3386 | /* |
| 3387 | * Update the seqid of an open stateid |
| 3388 | */ |
| 3389 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3390 | struct nfs4_state *state) |
| 3391 | { |
| 3392 | __be32 seqid_open; |
| 3393 | u32 dst_seqid; |
| 3394 | int seq; |
| 3395 | |
| 3396 | for (;;) { |
| 3397 | if (!nfs4_valid_open_stateid(state)) |
| 3398 | break; |
| 3399 | seq = read_seqbegin(&state->seqlock); |
| 3400 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3401 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3402 | if (read_seqretry(&state->seqlock, seq)) |
| 3403 | continue; |
| 3404 | break; |
| 3405 | } |
| 3406 | seqid_open = state->open_stateid.seqid; |
| 3407 | if (read_seqretry(&state->seqlock, seq)) |
| 3408 | continue; |
| 3409 | |
| 3410 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3411 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3412 | dst->seqid = seqid_open; |
| 3413 | break; |
| 3414 | } |
| 3415 | } |
| 3416 | |
| 3417 | /* |
| 3418 | * Update the seqid of an open stateid after receiving |
| 3419 | * NFS4ERR_OLD_STATEID |
| 3420 | */ |
| 3421 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3422 | struct nfs4_state *state) |
| 3423 | { |
| 3424 | __be32 seqid_open; |
| 3425 | u32 dst_seqid; |
| 3426 | bool ret; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 3427 | int seq, status = -EAGAIN; |
| 3428 | DEFINE_WAIT(wait); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3429 | |
| 3430 | for (;;) { |
| 3431 | ret = false; |
| 3432 | if (!nfs4_valid_open_stateid(state)) |
| 3433 | break; |
| 3434 | seq = read_seqbegin(&state->seqlock); |
| 3435 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3436 | if (read_seqretry(&state->seqlock, seq)) |
| 3437 | continue; |
| 3438 | break; |
| 3439 | } |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 3440 | |
| 3441 | write_seqlock(&state->seqlock); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3442 | seqid_open = state->open_stateid.seqid; |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3443 | |
| 3444 | dst_seqid = be32_to_cpu(dst->seqid); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 3445 | |
| 3446 | /* Did another OPEN bump the state's seqid? try again: */ |
| 3447 | if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3448 | dst->seqid = seqid_open; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame^] | 3449 | write_sequnlock(&state->seqlock); |
| 3450 | ret = true; |
| 3451 | break; |
| 3452 | } |
| 3453 | |
| 3454 | /* server says we're behind but we haven't seen the update yet */ |
| 3455 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 3456 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 3457 | write_sequnlock(&state->seqlock); |
| 3458 | trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
| 3459 | |
| 3460 | if (signal_pending(current)) |
| 3461 | status = -EINTR; |
| 3462 | else |
| 3463 | if (schedule_timeout(5*HZ) != 0) |
| 3464 | status = 0; |
| 3465 | |
| 3466 | finish_wait(&state->waitq, &wait); |
| 3467 | |
| 3468 | if (!status) |
| 3469 | continue; |
| 3470 | if (status == -EINTR) |
| 3471 | break; |
| 3472 | |
| 3473 | /* we slept the whole 5 seconds, we must have lost a seqid */ |
| 3474 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3475 | ret = true; |
| 3476 | break; |
| 3477 | } |
| 3478 | |
| 3479 | return ret; |
| 3480 | } |
| 3481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | struct nfs4_closedata { |
| 3483 | struct inode *inode; |
| 3484 | struct nfs4_state *state; |
| 3485 | struct nfs_closeargs arg; |
| 3486 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3487 | struct { |
| 3488 | struct nfs4_layoutreturn_args arg; |
| 3489 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3490 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3491 | u32 roc_barrier; |
| 3492 | bool roc; |
| 3493 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3494 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3495 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | }; |
| 3497 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3498 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3499 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3500 | struct nfs4_closedata *calldata = data; |
| 3501 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3502 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3503 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3504 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3505 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3506 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3507 | nfs4_put_open_state(calldata->state); |
| 3508 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3509 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3510 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3511 | kfree(calldata); |
| 3512 | } |
| 3513 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3514 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3516 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3519 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3520 | struct nfs4_exception exception = { |
| 3521 | .state = state, |
| 3522 | .inode = calldata->inode, |
| 3523 | .stateid = &calldata->arg.stateid, |
| 3524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3526 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3527 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3528 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3529 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3530 | |
| 3531 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3532 | if (pnfs_roc_done(task, calldata->inode, |
| 3533 | &calldata->arg.lr_args, |
| 3534 | &calldata->res.lr_res, |
| 3535 | &calldata->res.lr_ret) == -EAGAIN) |
| 3536 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3537 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3538 | /* hmm. we are done with the inode, and in the process of freeing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | * the state_owner. we keep this around to process errors |
| 3540 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | switch (task->tk_status) { |
| 3542 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3543 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3544 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3545 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3546 | case -NFS4ERR_ACCESS: |
| 3547 | if (calldata->arg.bitmask != NULL) { |
| 3548 | calldata->arg.bitmask = NULL; |
| 3549 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3550 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3551 | |
| 3552 | } |
| 3553 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3554 | case -NFS4ERR_OLD_STATEID: |
| 3555 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3556 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3557 | state)) |
| 3558 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3559 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3560 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3562 | case -NFS4ERR_EXPIRED: |
| 3563 | nfs4_free_revoked_stateid(server, |
| 3564 | &calldata->arg.stateid, |
| 3565 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3566 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3567 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3568 | if (calldata->arg.fmode == 0) |
| 3569 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3570 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3572 | task->tk_status = nfs4_async_handle_exception(task, |
| 3573 | server, task->tk_status, &exception); |
| 3574 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3575 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3577 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3578 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3579 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3580 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3581 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3582 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3583 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3584 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3585 | out_restart: |
| 3586 | task->tk_status = 0; |
| 3587 | rpc_restart_call_prepare(task); |
| 3588 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3591 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3593 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3594 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3595 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3596 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3597 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3598 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3599 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3600 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3601 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3602 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3603 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3604 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3605 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3606 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3607 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3608 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3609 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3610 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3611 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3612 | if (state->n_rdonly == 0) |
| 3613 | call_close |= is_rdonly; |
| 3614 | else if (is_rdonly) |
| 3615 | calldata->arg.fmode |= FMODE_READ; |
| 3616 | if (state->n_wronly == 0) |
| 3617 | call_close |= is_wronly; |
| 3618 | else if (is_wronly) |
| 3619 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3620 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3621 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3622 | } else if (is_rdwr) |
| 3623 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3624 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3625 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3626 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3627 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3628 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3629 | |
| 3630 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3631 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3632 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3633 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3634 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3635 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3636 | nfs_release_seqid(calldata->arg.seqid); |
| 3637 | goto out_wait; |
| 3638 | } |
| 3639 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3640 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3641 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3642 | calldata->arg.lr_args = NULL; |
| 3643 | calldata->res.lr_res = NULL; |
| 3644 | } |
| 3645 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3646 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3647 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3648 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3649 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3650 | /* Close-to-open cache consistency revalidation */ |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3651 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3652 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3653 | nfs4_bitmask_adjust(calldata->arg.bitmask, inode, NFS_SERVER(inode), NULL); |
| 3654 | } else |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3655 | calldata->arg.bitmask = NULL; |
| 3656 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3657 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3658 | calldata->arg.share_access = |
| 3659 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3660 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3661 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3662 | if (calldata->res.fattr == NULL) |
| 3663 | calldata->arg.bitmask = NULL; |
| 3664 | else if (calldata->arg.bitmask == NULL) |
| 3665 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3666 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3667 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3668 | &calldata->arg.seq_args, |
| 3669 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3670 | task) != 0) |
| 3671 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3672 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3673 | return; |
| 3674 | out_no_action: |
| 3675 | task->tk_action = NULL; |
| 3676 | out_wait: |
| 3677 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3680 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3681 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3682 | .rpc_call_done = nfs4_close_done, |
| 3683 | .rpc_release = nfs4_free_closedata, |
| 3684 | }; |
| 3685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | /* |
| 3687 | * It is possible for data to be read/written from a mem-mapped file |
| 3688 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3689 | * This means that we can't safely call nfsv4 close on a file until |
| 3690 | * the inode is cleared. This in turn means that we are not good |
| 3691 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3692 | * share state even when we are done with one of the three share |
| 3693 | * stateid's in the inode. |
| 3694 | * |
| 3695 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3696 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3697 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3699 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3700 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3702 | struct nfs4_state_owner *sp = state->owner; |
| 3703 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3704 | struct rpc_message msg = { |
| 3705 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3706 | .rpc_cred = state->owner->so_cred, |
| 3707 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3708 | struct rpc_task_setup task_setup_data = { |
| 3709 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3710 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3711 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3712 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 3713 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3714 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3715 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3717 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3718 | &task_setup_data.rpc_client, &msg); |
| 3719 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3720 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3722 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3723 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1, 0); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3724 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3726 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3727 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3728 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3730 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3731 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3732 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3733 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3734 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3735 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3736 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3737 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3738 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3739 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3740 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3741 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3742 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3743 | if (calldata->lr.roc) { |
| 3744 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3745 | calldata->res.lr_res = &calldata->lr.res; |
| 3746 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3747 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3748 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3749 | msg.rpc_argp = &calldata->arg; |
| 3750 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3751 | task_setup_data.callback_data = calldata; |
| 3752 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3753 | if (IS_ERR(task)) |
| 3754 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3755 | status = 0; |
| 3756 | if (wait) |
| 3757 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3758 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3759 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3760 | out_free_calldata: |
| 3761 | kfree(calldata); |
| 3762 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3763 | nfs4_put_open_state(state); |
| 3764 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3765 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3768 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3769 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3770 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3773 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3774 | |
| 3775 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3777 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3778 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3779 | |
| 3780 | nfs4_label_release_security(label); |
| 3781 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3782 | if (IS_ERR(state)) |
| 3783 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3784 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3787 | static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync) |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3788 | { |
| 3789 | if (ctx->state == NULL) |
| 3790 | return; |
| 3791 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3792 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3793 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3794 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3795 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3797 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3798 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 3799 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3802 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3803 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3804 | struct nfs4_server_caps_arg args = { |
| 3805 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3806 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3807 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | struct nfs4_server_caps_res res = {}; |
| 3809 | struct rpc_message msg = { |
| 3810 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3811 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | .rpc_resp = &res, |
| 3813 | }; |
| 3814 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3815 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3817 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3818 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3819 | FATTR4_WORD0_LINK_SUPPORT | |
| 3820 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3821 | FATTR4_WORD0_ACLSUPPORT; |
| 3822 | if (minorversion) |
| 3823 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3824 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3825 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3827 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3828 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3829 | case 0: |
| 3830 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3831 | res.attr_bitmask[2] = 0; |
| 3832 | break; |
| 3833 | case 1: |
| 3834 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3835 | break; |
| 3836 | case 2: |
| 3837 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3838 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3840 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3841 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3842 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3843 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3844 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3845 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3846 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3847 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | server->caps |= NFS_CAP_ACLS; |
| 3849 | if (res.has_links != 0) |
| 3850 | server->caps |= NFS_CAP_HARDLINKS; |
| 3851 | if (res.has_symlinks != 0) |
| 3852 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3853 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3854 | server->caps |= NFS_CAP_FILEID; |
| 3855 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3856 | server->caps |= NFS_CAP_MODE; |
| 3857 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3858 | server->caps |= NFS_CAP_NLINK; |
| 3859 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3860 | server->caps |= NFS_CAP_OWNER; |
| 3861 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3862 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3863 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3864 | server->caps |= NFS_CAP_ATIME; |
| 3865 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3866 | server->caps |= NFS_CAP_CTIME; |
| 3867 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3868 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3869 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3870 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3871 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3872 | #endif |
| 3873 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3874 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3875 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3876 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3877 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3878 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3879 | server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3880 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3881 | |
| 3882 | /* Avoid a regression due to buggy server */ |
| 3883 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3884 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3885 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3886 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3889 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3892 | return status; |
| 3893 | } |
| 3894 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3895 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3897 | struct nfs4_exception exception = { |
| 3898 | .interruptible = true, |
| 3899 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | int err; |
| 3901 | do { |
| 3902 | err = nfs4_handle_exception(server, |
| 3903 | _nfs4_server_capabilities(server, fhandle), |
| 3904 | &exception); |
| 3905 | } while (exception.retry); |
| 3906 | return err; |
| 3907 | } |
| 3908 | |
| 3909 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3910 | struct nfs_fsinfo *info) |
| 3911 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3912 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3914 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | }; |
| 3916 | struct nfs4_lookup_res res = { |
| 3917 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3918 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | .fh = fhandle, |
| 3920 | }; |
| 3921 | struct rpc_message msg = { |
| 3922 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3923 | .rpc_argp = &args, |
| 3924 | .rpc_resp = &res, |
| 3925 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3926 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3927 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3928 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3929 | /* |
| 3930 | * Process the label in the upcoming getfattr |
| 3931 | */ |
| 3932 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3933 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3934 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3935 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3939 | struct nfs_fsinfo *info) |
| 3940 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3941 | struct nfs4_exception exception = { |
| 3942 | .interruptible = true, |
| 3943 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | int err; |
| 3945 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3946 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3947 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3948 | switch (err) { |
| 3949 | case 0: |
| 3950 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3951 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3952 | default: |
| 3953 | err = nfs4_handle_exception(server, err, &exception); |
| 3954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3956 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | return err; |
| 3958 | } |
| 3959 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3960 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3961 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3962 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3963 | struct rpc_auth_create_args auth_args = { |
| 3964 | .pseudoflavor = flavor, |
| 3965 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3966 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3967 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3968 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3969 | if (IS_ERR(auth)) |
| 3970 | return -EACCES; |
| 3971 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3972 | } |
| 3973 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3974 | /* |
| 3975 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3976 | * |
| 3977 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3978 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3979 | * |
| 3980 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3981 | * negative errno value. |
| 3982 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3983 | static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3984 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3986 | /* Per 3530bis 15.33.5 */ |
| 3987 | static const rpc_authflavor_t flav_array[] = { |
| 3988 | RPC_AUTH_GSS_KRB5P, |
| 3989 | RPC_AUTH_GSS_KRB5I, |
| 3990 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3991 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3992 | RPC_AUTH_NULL, |
| 3993 | }; |
| 3994 | int status = -EPERM; |
| 3995 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3997 | if (server->auth_info.flavor_len > 0) { |
| 3998 | /* try each flavor specified by user */ |
| 3999 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 4000 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4001 | server->auth_info.flavors[i]); |
| 4002 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4003 | continue; |
| 4004 | break; |
| 4005 | } |
| 4006 | } else { |
| 4007 | /* no flavors specified by user, try default list */ |
| 4008 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 4009 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4010 | flav_array[i]); |
| 4011 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4012 | continue; |
| 4013 | break; |
| 4014 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4015 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4016 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4017 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 4018 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4019 | * to access the mount. It could also mean that we tried to mount |
| 4020 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 4021 | * existing mount programs don't handle -EACCES very well so it should |
| 4022 | * be mapped to -EPERM instead. |
| 4023 | */ |
| 4024 | if (status == -EACCES) |
| 4025 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4026 | return status; |
| 4027 | } |
| 4028 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4029 | /** |
| 4030 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 4031 | * @server: initialized nfs_server handle |
| 4032 | * @fhandle: we fill in the pseudo-fs root file handle |
| 4033 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4034 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4035 | * |
| 4036 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4037 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 4038 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4039 | struct nfs_fsinfo *info, |
| 4040 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4041 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4042 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4043 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4044 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4045 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4046 | |
| 4047 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 4048 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 4049 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | if (status == 0) |
| 4052 | status = nfs4_server_capabilities(server, fhandle); |
| 4053 | if (status == 0) |
| 4054 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4055 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 4056 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4059 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 4060 | struct nfs_fsinfo *info) |
| 4061 | { |
| 4062 | int error; |
| 4063 | struct nfs_fattr *fattr = info->fattr; |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4064 | struct nfs4_label *label = fattr->label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4065 | |
| 4066 | error = nfs4_server_capabilities(server, mntfh); |
| 4067 | if (error < 0) { |
| 4068 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 4069 | return error; |
| 4070 | } |
| 4071 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4072 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4073 | if (error < 0) { |
| 4074 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4075 | goto out; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4079 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4080 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4081 | |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4082 | out: |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4083 | return error; |
| 4084 | } |
| 4085 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4086 | /* |
| 4087 | * Get locations and (maybe) other attributes of a referral. |
| 4088 | * Note that we'll actually follow the referral later when |
| 4089 | * we detect fsid mismatch in inode revalidation |
| 4090 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4091 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4092 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4093 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4094 | { |
| 4095 | int status = -ENOMEM; |
| 4096 | struct page *page = NULL; |
| 4097 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4098 | |
| 4099 | page = alloc_page(GFP_KERNEL); |
| 4100 | if (page == NULL) |
| 4101 | goto out; |
| 4102 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4103 | if (locations == NULL) |
| 4104 | goto out; |
| 4105 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4106 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4107 | if (status != 0) |
| 4108 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4109 | |
| 4110 | /* |
| 4111 | * If the fsid didn't change, this is a migration event, not a |
| 4112 | * referral. Cause us to drop into the exception handler, which |
| 4113 | * will kick off migration recovery. |
| 4114 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4115 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4116 | dprintk("%s: server did not return a different fsid for" |
| 4117 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4118 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4119 | goto out; |
| 4120 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4121 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4122 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4123 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4124 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4125 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4126 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4127 | out: |
| 4128 | if (page) |
| 4129 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4130 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4131 | return status; |
| 4132 | } |
| 4133 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4134 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4135 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4136 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4138 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | struct nfs4_getattr_arg args = { |
| 4140 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4141 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | }; |
| 4143 | struct nfs4_getattr_res res = { |
| 4144 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4145 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | .server = server, |
| 4147 | }; |
| 4148 | struct rpc_message msg = { |
| 4149 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4150 | .rpc_argp = &args, |
| 4151 | .rpc_resp = &res, |
| 4152 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4153 | unsigned short task_flags = 0; |
| 4154 | |
| 4155 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4156 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4157 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4158 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4159 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4160 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4161 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4162 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4163 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4164 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | } |
| 4166 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4167 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4168 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4169 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4171 | struct nfs4_exception exception = { |
| 4172 | .interruptible = true, |
| 4173 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | int err; |
| 4175 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4176 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4177 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4178 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | &exception); |
| 4180 | } while (exception.retry); |
| 4181 | return err; |
| 4182 | } |
| 4183 | |
| 4184 | /* |
| 4185 | * The file is not closed if it is opened due to the a request to change |
| 4186 | * the size of the file. The open call will not be needed once the |
| 4187 | * VFS layer lookup-intents are implemented. |
| 4188 | * |
| 4189 | * Close is called when the inode is destroyed. |
| 4190 | * If we haven't opened the file for O_WRONLY, we |
| 4191 | * need to in the size_change case to obtain a stateid. |
| 4192 | * |
| 4193 | * Got race? |
| 4194 | * Because OPEN is always done by name in nfsv4, it is |
| 4195 | * possible that we opened a different file by the same |
| 4196 | * name. We can recognize this race condition, but we |
| 4197 | * can't do anything about it besides returning an error. |
| 4198 | * |
| 4199 | * This will be fixed with VFS changes (lookup-intent). |
| 4200 | */ |
| 4201 | static int |
| 4202 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4203 | struct iattr *sattr) |
| 4204 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4205 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4206 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4207 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4208 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | int status; |
| 4210 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4211 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4212 | sattr->ia_valid & ATTR_SIZE && |
| 4213 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4214 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4215 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4216 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4218 | /* Deal with open(O_TRUNC) */ |
| 4219 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4220 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4221 | |
| 4222 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4223 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4224 | return 0; |
| 4225 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4226 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4227 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4228 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4229 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4230 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4231 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4232 | } |
| 4233 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4234 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4235 | if (IS_ERR(label)) |
| 4236 | return PTR_ERR(label); |
| 4237 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4238 | /* Return any delegations if we're going to change ACLs */ |
| 4239 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4240 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4241 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4242 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4243 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4244 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4245 | nfs_setsecurity(inode, fattr, label); |
| 4246 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4247 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | return status; |
| 4249 | } |
| 4250 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4251 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4252 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4253 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4254 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4255 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4256 | int status; |
| 4257 | struct nfs4_lookup_arg args = { |
| 4258 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4259 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4260 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4261 | }; |
| 4262 | struct nfs4_lookup_res res = { |
| 4263 | .server = server, |
| 4264 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4265 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4266 | .fh = fhandle, |
| 4267 | }; |
| 4268 | struct rpc_message msg = { |
| 4269 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4270 | .rpc_argp = &args, |
| 4271 | .rpc_resp = &res, |
| 4272 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4273 | unsigned short task_flags = 0; |
| 4274 | |
| 4275 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4276 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4277 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4278 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4279 | args.bitmask = nfs4_bitmask(server, label); |
| 4280 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4281 | nfs_fattr_init(fattr); |
| 4282 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4283 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4284 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4285 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4286 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | dprintk("NFS reply lookup: %d\n", status); |
| 4288 | return status; |
| 4289 | } |
| 4290 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4291 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4292 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4293 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4294 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4295 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4296 | fattr->nlink = 2; |
| 4297 | } |
| 4298 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4299 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4300 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4301 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4302 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4303 | struct nfs4_exception exception = { |
| 4304 | .interruptible = true, |
| 4305 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4306 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4307 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4308 | int err; |
| 4309 | do { |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4310 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4311 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4312 | switch (err) { |
| 4313 | case -NFS4ERR_BADNAME: |
| 4314 | err = -ENOENT; |
| 4315 | goto out; |
| 4316 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4317 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4318 | if (err == -NFS4ERR_MOVED) |
| 4319 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4320 | goto out; |
| 4321 | case -NFS4ERR_WRONGSEC: |
| 4322 | err = -EPERM; |
| 4323 | if (client != *clnt) |
| 4324 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4325 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4326 | if (IS_ERR(client)) |
| 4327 | return PTR_ERR(client); |
| 4328 | |
| 4329 | exception.retry = 1; |
| 4330 | break; |
| 4331 | default: |
| 4332 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4333 | } |
| 4334 | } while (exception.retry); |
| 4335 | |
| 4336 | out: |
| 4337 | if (err == 0) |
| 4338 | *clnt = client; |
| 4339 | else if (client != *clnt) |
| 4340 | rpc_shutdown_client(client); |
| 4341 | |
| 4342 | return err; |
| 4343 | } |
| 4344 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4345 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4346 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4347 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4349 | int status; |
| 4350 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4351 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4352 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4353 | if (client != NFS_CLIENT(dir)) { |
| 4354 | rpc_shutdown_client(client); |
| 4355 | nfs_fixup_secinfo_attributes(fattr); |
| 4356 | } |
| 4357 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4360 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4361 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4362 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4363 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4364 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4365 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4366 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4367 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4368 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4369 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4370 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4371 | } |
| 4372 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4373 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4374 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4375 | struct nfs4_label *label) |
| 4376 | { |
| 4377 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4378 | struct nfs_server *server = NFS_SERVER(inode); |
| 4379 | int status; |
| 4380 | struct nfs4_lookupp_arg args = { |
| 4381 | .bitmask = server->attr_bitmask, |
| 4382 | .fh = NFS_FH(inode), |
| 4383 | }; |
| 4384 | struct nfs4_lookupp_res res = { |
| 4385 | .server = server, |
| 4386 | .fattr = fattr, |
| 4387 | .label = label, |
| 4388 | .fh = fhandle, |
| 4389 | }; |
| 4390 | struct rpc_message msg = { |
| 4391 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4392 | .rpc_argp = &args, |
| 4393 | .rpc_resp = &res, |
| 4394 | }; |
| 4395 | |
| 4396 | args.bitmask = nfs4_bitmask(server, label); |
| 4397 | |
| 4398 | nfs_fattr_init(fattr); |
| 4399 | |
| 4400 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4401 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4402 | &res.seq_res, 0); |
| 4403 | dprintk("NFS reply lookupp: %d\n", status); |
| 4404 | return status; |
| 4405 | } |
| 4406 | |
| 4407 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4408 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4409 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4410 | struct nfs4_exception exception = { |
| 4411 | .interruptible = true, |
| 4412 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4413 | int err; |
| 4414 | do { |
| 4415 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4416 | trace_nfs4_lookupp(inode, err); |
| 4417 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4418 | &exception); |
| 4419 | } while (exception.retry); |
| 4420 | return err; |
| 4421 | } |
| 4422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4424 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4425 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | struct nfs4_accessargs args = { |
| 4427 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4428 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4430 | struct nfs4_accessres res = { |
| 4431 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4432 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | struct rpc_message msg = { |
| 4434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4435 | .rpc_argp = &args, |
| 4436 | .rpc_resp = &res, |
| 4437 | .rpc_cred = entry->cred, |
| 4438 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4439 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4441 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4442 | res.fattr = nfs_alloc_fattr(); |
| 4443 | if (res.fattr == NULL) |
| 4444 | return -ENOMEM; |
| 4445 | args.bitmask = server->cache_consistency_bitmask; |
| 4446 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4447 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4449 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4450 | if (res.fattr) |
| 4451 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4453 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | return status; |
| 4455 | } |
| 4456 | |
| 4457 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4458 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4459 | struct nfs4_exception exception = { |
| 4460 | .interruptible = true, |
| 4461 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | int err; |
| 4463 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4464 | err = _nfs4_proc_access(inode, entry); |
| 4465 | trace_nfs4_access(inode, err); |
| 4466 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | &exception); |
| 4468 | } while (exception.retry); |
| 4469 | return err; |
| 4470 | } |
| 4471 | |
| 4472 | /* |
| 4473 | * TODO: For the time being, we don't try to get any attributes |
| 4474 | * along with any of the zero-copy operations READ, READDIR, |
| 4475 | * READLINK, WRITE. |
| 4476 | * |
| 4477 | * In the case of the first three, we want to put the GETATTR |
| 4478 | * after the read-type operation -- this is because it is hard |
| 4479 | * to predict the length of a GETATTR response in v4, and thus |
| 4480 | * align the READ data correctly. This means that the GETATTR |
| 4481 | * may end up partially falling into the page cache, and we should |
| 4482 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4483 | * To do this efficiently, we need to know the total length |
| 4484 | * of data received, which doesn't seem to be available outside |
| 4485 | * of the RPC layer. |
| 4486 | * |
| 4487 | * In the case of WRITE, we also want to put the GETATTR after |
| 4488 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4489 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | * |
| 4491 | * Both of these changes to the XDR layer would in fact be quite |
| 4492 | * minor, but I decided to leave them for a subsequent patch. |
| 4493 | */ |
| 4494 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4495 | unsigned int pgbase, unsigned int pglen) |
| 4496 | { |
| 4497 | struct nfs4_readlink args = { |
| 4498 | .fh = NFS_FH(inode), |
| 4499 | .pgbase = pgbase, |
| 4500 | .pglen = pglen, |
| 4501 | .pages = &page, |
| 4502 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4503 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | struct rpc_message msg = { |
| 4505 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4506 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4507 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | }; |
| 4509 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4510 | return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4514 | unsigned int pgbase, unsigned int pglen) |
| 4515 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4516 | struct nfs4_exception exception = { |
| 4517 | .interruptible = true, |
| 4518 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | int err; |
| 4520 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4521 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4522 | trace_nfs4_readlink(inode, err); |
| 4523 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | &exception); |
| 4525 | } while (exception.retry); |
| 4526 | return err; |
| 4527 | } |
| 4528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4530 | * This is just for mknod. open(O_CREAT) will always do ->open_context(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | static int |
| 4533 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4534 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4536 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4537 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4538 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | int status = 0; |
| 4541 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4542 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4543 | if (IS_ERR(ctx)) |
| 4544 | return PTR_ERR(ctx); |
| 4545 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4546 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4547 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4548 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4549 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4550 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | if (IS_ERR(state)) { |
| 4552 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4553 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4556 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4557 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | return status; |
| 4559 | } |
| 4560 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4561 | static int |
| 4562 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4564 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4565 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4567 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4569 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4570 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4571 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4573 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4574 | .rpc_argp = &args, |
| 4575 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4577 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4578 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4579 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4580 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4581 | if (status == 0) { |
| 4582 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4583 | nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
| 4584 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4585 | /* Removing a directory decrements nlink in the parent */ |
| 4586 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4587 | nfs4_dec_nlink_locked(dir); |
| 4588 | spin_unlock(&dir->i_lock); |
| 4589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | return status; |
| 4591 | } |
| 4592 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4593 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4594 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4595 | struct nfs4_exception exception = { |
| 4596 | .interruptible = true, |
| 4597 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4598 | struct inode *inode = d_inode(dentry); |
| 4599 | int err; |
| 4600 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4601 | if (inode) { |
| 4602 | if (inode->i_nlink == 1) |
| 4603 | nfs4_inode_return_delegation(inode); |
| 4604 | else |
| 4605 | nfs4_inode_make_writeable(inode); |
| 4606 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4607 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4608 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4609 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4610 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4611 | &exception); |
| 4612 | } while (exception.retry); |
| 4613 | return err; |
| 4614 | } |
| 4615 | |
| 4616 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4618 | struct nfs4_exception exception = { |
| 4619 | .interruptible = true, |
| 4620 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4624 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4625 | trace_nfs4_remove(dir, name, err); |
| 4626 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | &exception); |
| 4628 | } while (exception.retry); |
| 4629 | return err; |
| 4630 | } |
| 4631 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4632 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4633 | struct dentry *dentry, |
| 4634 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4636 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4637 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4639 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4641 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4642 | |
| 4643 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4644 | |
| 4645 | if (inode) |
| 4646 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | } |
| 4648 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4649 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4650 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4651 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4652 | &data->args.seq_args, |
| 4653 | &data->res.seq_res, |
| 4654 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4657 | static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4659 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4660 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4661 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4662 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4663 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4664 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4665 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4666 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4667 | if (task->tk_status == 0) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4668 | nfs4_update_changeattr(dir, &res->cinfo, |
| 4669 | res->dir_attr->time_start, |
| 4670 | NFS_INO_INVALID_DATA); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4671 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4674 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4675 | struct dentry *old_dentry, |
| 4676 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4677 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4678 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4679 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4680 | struct inode *old_inode = d_inode(old_dentry); |
| 4681 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4682 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4683 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4684 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4685 | if (new_inode) |
| 4686 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4687 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4688 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4689 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4690 | } |
| 4691 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4692 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4693 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4694 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4695 | &data->args.seq_args, |
| 4696 | &data->res.seq_res, |
| 4697 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4701 | struct inode *new_dir) |
| 4702 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4703 | struct nfs_renamedata *data = task->tk_calldata; |
| 4704 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4705 | |
| 4706 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4707 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4708 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4709 | return 0; |
| 4710 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4711 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4712 | if (new_dir != old_dir) { |
| 4713 | /* Note: If we moved a directory, nlink will change */ |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4714 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4715 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4716 | NFS_INO_INVALID_OTHER | |
| 4717 | NFS_INO_INVALID_DATA); |
| 4718 | nfs4_update_changeattr(new_dir, &res->new_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4719 | res->new_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4720 | NFS_INO_INVALID_OTHER | |
| 4721 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4722 | } else |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4723 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4724 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4725 | NFS_INO_INVALID_DATA); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4726 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4727 | return 1; |
| 4728 | } |
| 4729 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4730 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4732 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4733 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | struct nfs4_link_arg arg = { |
| 4735 | .fh = NFS_FH(inode), |
| 4736 | .dir_fh = NFS_FH(dir), |
| 4737 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4738 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4740 | struct nfs4_link_res res = { |
| 4741 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4742 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4743 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | struct rpc_message msg = { |
| 4745 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4746 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4747 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4749 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4751 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4752 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4753 | goto out; |
| 4754 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4755 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4756 | if (IS_ERR(res.label)) { |
| 4757 | status = PTR_ERR(res.label); |
| 4758 | goto out; |
| 4759 | } |
| 4760 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4761 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4762 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4763 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4764 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4765 | if (!status) { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4766 | nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
| 4767 | NFS_INO_INVALID_DATA); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4768 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4769 | if (!status) |
| 4770 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4771 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4772 | |
| 4773 | |
| 4774 | nfs4_label_free(res.label); |
| 4775 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4776 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4777 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | return status; |
| 4779 | } |
| 4780 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4781 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4783 | struct nfs4_exception exception = { |
| 4784 | .interruptible = true, |
| 4785 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | int err; |
| 4787 | do { |
| 4788 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4789 | _nfs4_proc_link(inode, dir, name), |
| 4790 | &exception); |
| 4791 | } while (exception.retry); |
| 4792 | return err; |
| 4793 | } |
| 4794 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4795 | struct nfs4_createdata { |
| 4796 | struct rpc_message msg; |
| 4797 | struct nfs4_create_arg arg; |
| 4798 | struct nfs4_create_res res; |
| 4799 | struct nfs_fh fh; |
| 4800 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4801 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4802 | }; |
| 4803 | |
| 4804 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4805 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4806 | { |
| 4807 | struct nfs4_createdata *data; |
| 4808 | |
| 4809 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4810 | if (data != NULL) { |
| 4811 | struct nfs_server *server = NFS_SERVER(dir); |
| 4812 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4813 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4814 | if (IS_ERR(data->label)) |
| 4815 | goto out_free; |
| 4816 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4817 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4818 | data->msg.rpc_argp = &data->arg; |
| 4819 | data->msg.rpc_resp = &data->res; |
| 4820 | data->arg.dir_fh = NFS_FH(dir); |
| 4821 | data->arg.server = server; |
| 4822 | data->arg.name = name; |
| 4823 | data->arg.attrs = sattr; |
| 4824 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4825 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4826 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4827 | data->res.server = server; |
| 4828 | data->res.fh = &data->fh; |
| 4829 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4830 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4831 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4832 | } |
| 4833 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4834 | out_free: |
| 4835 | kfree(data); |
| 4836 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4840 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4841 | int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 4842 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4843 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4844 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4845 | nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
| 4846 | data->res.fattr->time_start, |
| 4847 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4848 | /* Creating a directory bumps nlink in the parent */ |
| 4849 | if (data->arg.ftype == NF4DIR) |
| 4850 | nfs4_inc_nlink_locked(dir); |
| 4851 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4852 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4853 | } |
| 4854 | return status; |
| 4855 | } |
| 4856 | |
| 4857 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4858 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4859 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4860 | kfree(data); |
| 4861 | } |
| 4862 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4863 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4864 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4865 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4867 | struct nfs4_createdata *data; |
| 4868 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4870 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4871 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4872 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4873 | status = -ENOMEM; |
| 4874 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4875 | if (data == NULL) |
| 4876 | goto out; |
| 4877 | |
| 4878 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4879 | data->arg.u.symlink.pages = &page; |
| 4880 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4881 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4883 | status = nfs4_do_create(dir, dentry, data); |
| 4884 | |
| 4885 | nfs4_free_createdata(data); |
| 4886 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | return status; |
| 4888 | } |
| 4889 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4890 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4891 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4893 | struct nfs4_exception exception = { |
| 4894 | .interruptible = true, |
| 4895 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4896 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4898 | |
| 4899 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4902 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4903 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4904 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | &exception); |
| 4906 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4907 | |
| 4908 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | return err; |
| 4910 | } |
| 4911 | |
| 4912 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4913 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4915 | struct nfs4_createdata *data; |
| 4916 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4918 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4919 | if (data == NULL) |
| 4920 | goto out; |
| 4921 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4922 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4923 | status = nfs4_do_create(dir, dentry, data); |
| 4924 | |
| 4925 | nfs4_free_createdata(data); |
| 4926 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | return status; |
| 4928 | } |
| 4929 | |
| 4930 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4931 | struct iattr *sattr) |
| 4932 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4933 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4934 | struct nfs4_exception exception = { |
| 4935 | .interruptible = true, |
| 4936 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4937 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4939 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4940 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4941 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4942 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4943 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4945 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4946 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4947 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | &exception); |
| 4949 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4950 | nfs4_label_release_security(label); |
| 4951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | return err; |
| 4953 | } |
| 4954 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4955 | static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4956 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4958 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | struct nfs4_readdir_arg args = { |
| 4960 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4961 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | .pgbase = 0, |
| 4963 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4964 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4965 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4966 | }; |
| 4967 | struct nfs4_readdir_res res; |
| 4968 | struct rpc_message msg = { |
| 4969 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4970 | .rpc_argp = &args, |
| 4971 | .rpc_resp = &res, |
| 4972 | .rpc_cred = cred, |
| 4973 | }; |
| 4974 | int status; |
| 4975 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4976 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4977 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4978 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4979 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4981 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4982 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4983 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4984 | status += args.pgbase; |
| 4985 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4986 | |
| 4987 | nfs_invalidate_atime(dir); |
| 4988 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4989 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | return status; |
| 4991 | } |
| 4992 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4993 | static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4994 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4996 | struct nfs4_exception exception = { |
| 4997 | .interruptible = true, |
| 4998 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | int err; |
| 5000 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5001 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 5002 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5003 | trace_nfs4_readdir(d_inode(dentry), err); |
| 5004 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | &exception); |
| 5006 | } while (exception.retry); |
| 5007 | return err; |
| 5008 | } |
| 5009 | |
| 5010 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5011 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5013 | struct nfs4_createdata *data; |
| 5014 | int mode = sattr->ia_mode; |
| 5015 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5017 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 5018 | if (data == NULL) |
| 5019 | goto out; |
| 5020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5022 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5024 | data->arg.ftype = NF4BLK; |
| 5025 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5026 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | } |
| 5028 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5029 | data->arg.ftype = NF4CHR; |
| 5030 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5031 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5032 | } else if (!S_ISSOCK(mode)) { |
| 5033 | status = -EINVAL; |
| 5034 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5036 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5037 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5038 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5039 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5040 | nfs4_free_createdata(data); |
| 5041 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | return status; |
| 5043 | } |
| 5044 | |
| 5045 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 5046 | struct iattr *sattr, dev_t rdev) |
| 5047 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5048 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5049 | struct nfs4_exception exception = { |
| 5050 | .interruptible = true, |
| 5051 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5052 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5054 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5055 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5056 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5057 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5058 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5060 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 5061 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 5062 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5063 | &exception); |
| 5064 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5065 | |
| 5066 | nfs4_label_release_security(label); |
| 5067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | return err; |
| 5069 | } |
| 5070 | |
| 5071 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5072 | struct nfs_fsstat *fsstat) |
| 5073 | { |
| 5074 | struct nfs4_statfs_arg args = { |
| 5075 | .fh = fhandle, |
| 5076 | .bitmask = server->attr_bitmask, |
| 5077 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5078 | struct nfs4_statfs_res res = { |
| 5079 | .fsstat = fsstat, |
| 5080 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | struct rpc_message msg = { |
| 5082 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5083 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5084 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | }; |
| 5086 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5087 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5088 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5092 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5093 | struct nfs4_exception exception = { |
| 5094 | .interruptible = true, |
| 5095 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | int err; |
| 5097 | do { |
| 5098 | err = nfs4_handle_exception(server, |
| 5099 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5100 | &exception); |
| 5101 | } while (exception.retry); |
| 5102 | return err; |
| 5103 | } |
| 5104 | |
| 5105 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5106 | struct nfs_fsinfo *fsinfo) |
| 5107 | { |
| 5108 | struct nfs4_fsinfo_arg args = { |
| 5109 | .fh = fhandle, |
| 5110 | .bitmask = server->attr_bitmask, |
| 5111 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5112 | struct nfs4_fsinfo_res res = { |
| 5113 | .fsinfo = fsinfo, |
| 5114 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | struct rpc_message msg = { |
| 5116 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5117 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5118 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | }; |
| 5120 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5121 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5125 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5126 | struct nfs4_exception exception = { |
| 5127 | .interruptible = true, |
| 5128 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | int err; |
| 5130 | |
| 5131 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5132 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5133 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5134 | if (err == 0) { |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 5135 | nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5136 | break; |
| 5137 | } |
| 5138 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | } while (exception.retry); |
| 5140 | return err; |
| 5141 | } |
| 5142 | |
| 5143 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5144 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5145 | int error; |
| 5146 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5147 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5148 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5149 | if (error == 0) { |
| 5150 | /* block layout checks this! */ |
| 5151 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5152 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5153 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5154 | |
| 5155 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5159 | struct nfs_pathconf *pathconf) |
| 5160 | { |
| 5161 | struct nfs4_pathconf_arg args = { |
| 5162 | .fh = fhandle, |
| 5163 | .bitmask = server->attr_bitmask, |
| 5164 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5165 | struct nfs4_pathconf_res res = { |
| 5166 | .pathconf = pathconf, |
| 5167 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5168 | struct rpc_message msg = { |
| 5169 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5170 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5171 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | }; |
| 5173 | |
| 5174 | /* None of the pathconf attributes are mandatory to implement */ |
| 5175 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5176 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5177 | return 0; |
| 5178 | } |
| 5179 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5180 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5181 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5185 | struct nfs_pathconf *pathconf) |
| 5186 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5187 | struct nfs4_exception exception = { |
| 5188 | .interruptible = true, |
| 5189 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | int err; |
| 5191 | |
| 5192 | do { |
| 5193 | err = nfs4_handle_exception(server, |
| 5194 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5195 | &exception); |
| 5196 | } while (exception.retry); |
| 5197 | return err; |
| 5198 | } |
| 5199 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5200 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5201 | const struct nfs_open_context *ctx, |
| 5202 | const struct nfs_lock_context *l_ctx, |
| 5203 | fmode_t fmode) |
| 5204 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5205 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5206 | } |
| 5207 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5208 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5209 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5210 | const struct nfs_open_context *ctx, |
| 5211 | const struct nfs_lock_context *l_ctx, |
| 5212 | fmode_t fmode) |
| 5213 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5214 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5215 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5216 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5217 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5218 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5219 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | static bool nfs4_error_stateid_expired(int err) |
| 5223 | { |
| 5224 | switch (err) { |
| 5225 | case -NFS4ERR_DELEG_REVOKED: |
| 5226 | case -NFS4ERR_ADMIN_REVOKED: |
| 5227 | case -NFS4ERR_BAD_STATEID: |
| 5228 | case -NFS4ERR_STALE_STATEID: |
| 5229 | case -NFS4ERR_OLD_STATEID: |
| 5230 | case -NFS4ERR_OPENMODE: |
| 5231 | case -NFS4ERR_EXPIRED: |
| 5232 | return true; |
| 5233 | } |
| 5234 | return false; |
| 5235 | } |
| 5236 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5237 | static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5239 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5241 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5242 | if (task->tk_status < 0) { |
| 5243 | struct nfs4_exception exception = { |
| 5244 | .inode = hdr->inode, |
| 5245 | .state = hdr->args.context->state, |
| 5246 | .stateid = &hdr->args.stateid, |
| 5247 | }; |
| 5248 | task->tk_status = nfs4_async_handle_exception(task, |
| 5249 | server, task->tk_status, &exception); |
| 5250 | if (exception.retry) { |
| 5251 | rpc_restart_call_prepare(task); |
| 5252 | return -EAGAIN; |
| 5253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5256 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5257 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5258 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5261 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5262 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5263 | { |
| 5264 | |
| 5265 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5266 | nfs4_stateid_is_current(&args->stateid, |
| 5267 | args->context, |
| 5268 | args->lock_context, |
| 5269 | FMODE_READ)) |
| 5270 | return false; |
| 5271 | rpc_restart_call_prepare(task); |
| 5272 | return true; |
| 5273 | } |
| 5274 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5275 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5276 | { |
| 5277 | |
| 5278 | dprintk("--> %s\n", __func__); |
| 5279 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5280 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5281 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5282 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5283 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5284 | if (task->tk_status > 0) |
| 5285 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5286 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5287 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5288 | } |
| 5289 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5290 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5291 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5293 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5294 | if (!hdr->pgio_done_cb) |
| 5295 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5296 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5297 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5300 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5301 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5302 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5303 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5304 | &hdr->args.seq_args, |
| 5305 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5306 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5307 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5308 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5309 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5310 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5311 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5312 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5313 | return -EIO; |
| 5314 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5317 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5318 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5320 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5321 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5322 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5323 | if (task->tk_status < 0) { |
| 5324 | struct nfs4_exception exception = { |
| 5325 | .inode = hdr->inode, |
| 5326 | .state = hdr->args.context->state, |
| 5327 | .stateid = &hdr->args.stateid, |
| 5328 | }; |
| 5329 | task->tk_status = nfs4_async_handle_exception(task, |
| 5330 | NFS_SERVER(inode), task->tk_status, |
| 5331 | &exception); |
| 5332 | if (exception.retry) { |
| 5333 | rpc_restart_call_prepare(task); |
| 5334 | return -EAGAIN; |
| 5335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5337 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5338 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5339 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5340 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5341 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | } |
| 5343 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5344 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5345 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5346 | { |
| 5347 | |
| 5348 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5349 | nfs4_stateid_is_current(&args->stateid, |
| 5350 | args->context, |
| 5351 | args->lock_context, |
| 5352 | FMODE_WRITE)) |
| 5353 | return false; |
| 5354 | rpc_restart_call_prepare(task); |
| 5355 | return true; |
| 5356 | } |
| 5357 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5358 | static int nfs4_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5359 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5360 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5361 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5362 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5363 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5364 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5365 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5366 | } |
| 5367 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5368 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5369 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5370 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5371 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5372 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5373 | return false; |
| 5374 | /* Otherwise, request attributes if and only if we don't hold |
| 5375 | * a delegation |
| 5376 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5377 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5378 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5379 | |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5380 | static void nfs4_bitmask_adjust(__u32 *bitmask, struct inode *inode, |
| 5381 | struct nfs_server *server, |
| 5382 | struct nfs4_label *label) |
| 5383 | { |
| 5384 | |
| 5385 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 5386 | |
| 5387 | if ((cache_validity & NFS_INO_INVALID_DATA) || |
| 5388 | (cache_validity & NFS_INO_REVAL_PAGECACHE) || |
| 5389 | (cache_validity & NFS_INO_REVAL_FORCED) || |
| 5390 | (cache_validity & NFS_INO_INVALID_OTHER)) |
| 5391 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
| 5392 | |
| 5393 | if (cache_validity & NFS_INO_INVALID_ATIME) |
| 5394 | bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
| 5395 | if (cache_validity & NFS_INO_INVALID_ACCESS) |
| 5396 | bitmask[0] |= FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | |
| 5397 | FATTR4_WORD1_OWNER_GROUP; |
| 5398 | if (cache_validity & NFS_INO_INVALID_ACL) |
| 5399 | bitmask[0] |= FATTR4_WORD0_ACL; |
| 5400 | if (cache_validity & NFS_INO_INVALID_LABEL) |
| 5401 | bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; |
| 5402 | if (cache_validity & NFS_INO_INVALID_CTIME) |
| 5403 | bitmask[0] |= FATTR4_WORD0_CHANGE; |
| 5404 | if (cache_validity & NFS_INO_INVALID_MTIME) |
| 5405 | bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
| 5406 | if (cache_validity & NFS_INO_INVALID_SIZE) |
| 5407 | bitmask[0] |= FATTR4_WORD0_SIZE; |
| 5408 | if (cache_validity & NFS_INO_INVALID_BLOCKS) |
| 5409 | bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
| 5410 | } |
| 5411 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5412 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5413 | struct rpc_message *msg, |
| 5414 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5416 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5417 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5418 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5419 | hdr->args.bitmask = NULL; |
| 5420 | hdr->res.fattr = NULL; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5421 | } else { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5422 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5423 | nfs4_bitmask_adjust(hdr->args.bitmask, hdr->inode, server, NULL); |
| 5424 | } |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5425 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5426 | if (!hdr->pgio_done_cb) |
| 5427 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5428 | hdr->res.server = server; |
| 5429 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5431 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Olga Kornievskaia | cd1b659 | 2020-02-12 17:32:12 -0500 | [diff] [blame] | 5432 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5433 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | } |
| 5435 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5436 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5437 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5438 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5439 | &data->args.seq_args, |
| 5440 | &data->res.seq_res, |
| 5441 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5442 | } |
| 5443 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5444 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5446 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5447 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5448 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5449 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5450 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5451 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5452 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5453 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5454 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | } |
| 5456 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5457 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data) |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5458 | { |
| 5459 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5460 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5461 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5462 | } |
| 5463 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5464 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5465 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5467 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5468 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5469 | if (data->commit_done_cb == NULL) |
| 5470 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5471 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5472 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5473 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5474 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_COMMIT, clnt, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5477 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5478 | struct nfs_commitres *res) |
| 5479 | { |
| 5480 | struct inode *dst_inode = file_inode(dst); |
| 5481 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5482 | struct rpc_message msg = { |
| 5483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5484 | .rpc_argp = args, |
| 5485 | .rpc_resp = res, |
| 5486 | }; |
| 5487 | |
| 5488 | args->fh = NFS_FH(dst_inode); |
| 5489 | return nfs4_call_sync(server->client, server, &msg, |
| 5490 | &args->seq_args, &res->seq_res, 1); |
| 5491 | } |
| 5492 | |
| 5493 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5494 | { |
| 5495 | struct nfs_commitargs args = { |
| 5496 | .offset = offset, |
| 5497 | .count = count, |
| 5498 | }; |
| 5499 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5500 | struct nfs4_exception exception = { }; |
| 5501 | int status; |
| 5502 | |
| 5503 | do { |
| 5504 | status = _nfs4_proc_commit(dst, &args, res); |
| 5505 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5506 | } while (exception.retry); |
| 5507 | |
| 5508 | return status; |
| 5509 | } |
| 5510 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5511 | struct nfs4_renewdata { |
| 5512 | struct nfs_client *client; |
| 5513 | unsigned long timestamp; |
| 5514 | }; |
| 5515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | /* |
| 5517 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5518 | * standalone procedure for queueing an asynchronous RENEW. |
| 5519 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5520 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5521 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5522 | struct nfs4_renewdata *data = calldata; |
| 5523 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5524 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5525 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5526 | nfs4_schedule_state_renewal(clp); |
| 5527 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5528 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5529 | } |
| 5530 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5531 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5533 | struct nfs4_renewdata *data = calldata; |
| 5534 | struct nfs_client *clp = data->client; |
| 5535 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5537 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5538 | switch (task->tk_status) { |
| 5539 | case 0: |
| 5540 | break; |
| 5541 | case -NFS4ERR_LEASE_MOVED: |
| 5542 | nfs4_schedule_lease_moved_recovery(clp); |
| 5543 | break; |
| 5544 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5545 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5546 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5547 | return; |
| 5548 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5549 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5550 | return; |
| 5551 | } |
| 5552 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5554 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5557 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5558 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5559 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5560 | }; |
| 5561 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5562 | static int nfs4_proc_async_renew(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | { |
| 5564 | struct rpc_message msg = { |
| 5565 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5566 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5567 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5568 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5569 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5571 | if (renew_flags == 0) |
| 5572 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5573 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5574 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5575 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5576 | if (data == NULL) { |
| 5577 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5578 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5579 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5580 | data->client = clp; |
| 5581 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5582 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5583 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | } |
| 5585 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5586 | static int nfs4_proc_renew(struct nfs_client *clp, const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | { |
| 5588 | struct rpc_message msg = { |
| 5589 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5590 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5591 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | }; |
| 5593 | unsigned long now = jiffies; |
| 5594 | int status; |
| 5595 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5596 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | if (status < 0) |
| 5598 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5599 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5600 | return 0; |
| 5601 | } |
| 5602 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5603 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5604 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5605 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5608 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5609 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5610 | * the stack. |
| 5611 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5612 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5613 | |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5614 | int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5615 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5616 | { |
| 5617 | struct page *newpage, **spages; |
| 5618 | int rc = 0; |
| 5619 | size_t len; |
| 5620 | spages = pages; |
| 5621 | |
| 5622 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5623 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5624 | newpage = alloc_page(GFP_KERNEL); |
| 5625 | |
| 5626 | if (newpage == NULL) |
| 5627 | goto unwind; |
| 5628 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5629 | buf += len; |
| 5630 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5631 | *pages++ = newpage; |
| 5632 | rc++; |
| 5633 | } while (buflen != 0); |
| 5634 | |
| 5635 | return rc; |
| 5636 | |
| 5637 | unwind: |
| 5638 | for(; rc > 0; rc--) |
| 5639 | __free_page(spages[rc-1]); |
| 5640 | return -ENOMEM; |
| 5641 | } |
| 5642 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5643 | struct nfs4_cached_acl { |
| 5644 | int cached; |
| 5645 | size_t len; |
Gustavo A. R. Silva | 5601cda | 2020-03-09 13:24:42 -0500 | [diff] [blame] | 5646 | char data[]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5647 | }; |
| 5648 | |
| 5649 | static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5650 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5651 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5652 | |
| 5653 | spin_lock(&inode->i_lock); |
| 5654 | kfree(nfsi->nfs4_acl); |
| 5655 | nfsi->nfs4_acl = acl; |
| 5656 | spin_unlock(&inode->i_lock); |
| 5657 | } |
| 5658 | |
| 5659 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5660 | { |
| 5661 | nfs4_set_cached_acl(inode, NULL); |
| 5662 | } |
| 5663 | |
| 5664 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5665 | { |
| 5666 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5667 | struct nfs4_cached_acl *acl; |
| 5668 | int ret = -ENOENT; |
| 5669 | |
| 5670 | spin_lock(&inode->i_lock); |
| 5671 | acl = nfsi->nfs4_acl; |
| 5672 | if (acl == NULL) |
| 5673 | goto out; |
| 5674 | if (buf == NULL) /* user is just asking for length */ |
| 5675 | goto out_len; |
| 5676 | if (acl->cached == 0) |
| 5677 | goto out; |
| 5678 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5679 | if (acl->len > buflen) |
| 5680 | goto out; |
| 5681 | memcpy(buf, acl->data, acl->len); |
| 5682 | out_len: |
| 5683 | ret = acl->len; |
| 5684 | out: |
| 5685 | spin_unlock(&inode->i_lock); |
| 5686 | return ret; |
| 5687 | } |
| 5688 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5689 | static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5690 | { |
| 5691 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5692 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5693 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5694 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5695 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5696 | if (acl == NULL) |
| 5697 | goto out; |
| 5698 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5699 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5700 | } else { |
| 5701 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5702 | if (acl == NULL) |
| 5703 | goto out; |
| 5704 | acl->cached = 0; |
| 5705 | } |
| 5706 | acl->len = acl_len; |
| 5707 | out: |
| 5708 | nfs4_set_cached_acl(inode, acl); |
| 5709 | } |
| 5710 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5711 | /* |
| 5712 | * The getxattr API returns the required buffer length when called with a |
| 5713 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5714 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5715 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5716 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5717 | * the cache. If not so, we throw away the page, and cache the required |
| 5718 | * length. The next getxattr call will then produce another round trip to |
| 5719 | * the server, this time with the input buf of the required size. |
| 5720 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5721 | static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5722 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5723 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5724 | struct nfs_getaclargs args = { |
| 5725 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5726 | .acl_len = buflen, |
| 5727 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5728 | struct nfs_getaclres res = { |
| 5729 | .acl_len = buflen, |
| 5730 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5731 | struct rpc_message msg = { |
| 5732 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5733 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5734 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5735 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5736 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5737 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5738 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5739 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5740 | if (buflen == 0) |
| 5741 | buflen = server->rsize; |
| 5742 | |
| 5743 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5744 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5745 | if (!pages) |
| 5746 | return -ENOMEM; |
| 5747 | |
| 5748 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5749 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5750 | for (i = 0; i < npages; i++) { |
| 5751 | pages[i] = alloc_page(GFP_KERNEL); |
| 5752 | if (!pages[i]) |
| 5753 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5754 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5755 | |
| 5756 | /* for decoding across pages */ |
| 5757 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5758 | if (!res.acl_scratch) |
| 5759 | goto out_free; |
| 5760 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5761 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5762 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5763 | dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n", |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5764 | __func__, buf, buflen, npages, args.acl_len); |
| 5765 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5766 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5767 | if (ret) |
| 5768 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5769 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5770 | /* Handle the case where the passed-in buffer is too short */ |
| 5771 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5772 | /* Did the user only issue a request for the acl length? */ |
| 5773 | if (buf == NULL) |
| 5774 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5775 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5776 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5777 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5778 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5779 | if (buf) { |
| 5780 | if (res.acl_len > buflen) { |
| 5781 | ret = -ERANGE; |
| 5782 | goto out_free; |
| 5783 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5784 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5785 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5786 | out_ok: |
| 5787 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5788 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5789 | for (i = 0; i < npages; i++) |
| 5790 | if (pages[i]) |
| 5791 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5792 | if (res.acl_scratch) |
| 5793 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5794 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5795 | return ret; |
| 5796 | } |
| 5797 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5798 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5799 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5800 | struct nfs4_exception exception = { |
| 5801 | .interruptible = true, |
| 5802 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5803 | ssize_t ret; |
| 5804 | do { |
| 5805 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5806 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5807 | if (ret >= 0) |
| 5808 | break; |
| 5809 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5810 | } while (exception.retry); |
| 5811 | return ret; |
| 5812 | } |
| 5813 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5814 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5815 | { |
| 5816 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5817 | int ret; |
| 5818 | |
| 5819 | if (!nfs4_server_supports_acls(server)) |
| 5820 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5821 | ret = nfs_revalidate_inode(server, inode); |
| 5822 | if (ret < 0) |
| 5823 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5824 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5825 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5826 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5827 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5828 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5829 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5830 | return ret; |
| 5831 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5834 | static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5835 | { |
| 5836 | struct nfs_server *server = NFS_SERVER(inode); |
| 5837 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5838 | struct nfs_setaclargs arg = { |
| 5839 | .fh = NFS_FH(inode), |
| 5840 | .acl_pages = pages, |
| 5841 | .acl_len = buflen, |
| 5842 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5843 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5844 | struct rpc_message msg = { |
| 5845 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5846 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5847 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5848 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5849 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5850 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5851 | |
| 5852 | if (!nfs4_server_supports_acls(server)) |
| 5853 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5854 | if (npages > ARRAY_SIZE(pages)) |
| 5855 | return -ERANGE; |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5856 | i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5857 | if (i < 0) |
| 5858 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5859 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5860 | ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5861 | |
| 5862 | /* |
| 5863 | * Free each page after tx, so the only ref left is |
| 5864 | * held by the network stack |
| 5865 | */ |
| 5866 | for (; i > 0; i--) |
| 5867 | put_page(pages[i-1]); |
| 5868 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5869 | /* |
| 5870 | * Acl update can result in inode attribute update. |
| 5871 | * so mark the attribute cache invalid. |
| 5872 | */ |
| 5873 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5874 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5875 | | NFS_INO_INVALID_CTIME |
| 5876 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5877 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5878 | nfs_access_zap_cache(inode); |
| 5879 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5880 | return ret; |
| 5881 | } |
| 5882 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5883 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5884 | { |
| 5885 | struct nfs4_exception exception = { }; |
| 5886 | int err; |
| 5887 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5888 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5889 | trace_nfs4_set_acl(inode, err); |
| 5890 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5891 | &exception); |
| 5892 | } while (exception.retry); |
| 5893 | return err; |
| 5894 | } |
| 5895 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5896 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5897 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5898 | size_t buflen) |
| 5899 | { |
| 5900 | struct nfs_server *server = NFS_SERVER(inode); |
| 5901 | struct nfs_fattr fattr; |
| 5902 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5903 | |
| 5904 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5905 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5906 | .fh = NFS_FH(inode), |
| 5907 | .bitmask = bitmask, |
| 5908 | }; |
| 5909 | struct nfs4_getattr_res res = { |
| 5910 | .fattr = &fattr, |
| 5911 | .label = &label, |
| 5912 | .server = server, |
| 5913 | }; |
| 5914 | struct rpc_message msg = { |
| 5915 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5916 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5917 | .rpc_resp = &res, |
| 5918 | }; |
| 5919 | int ret; |
| 5920 | |
| 5921 | nfs_fattr_init(&fattr); |
| 5922 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5923 | ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5924 | if (ret) |
| 5925 | return ret; |
| 5926 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5927 | return -ENOENT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5928 | return 0; |
| 5929 | } |
| 5930 | |
| 5931 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5932 | size_t buflen) |
| 5933 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5934 | struct nfs4_exception exception = { |
| 5935 | .interruptible = true, |
| 5936 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5937 | int err; |
| 5938 | |
| 5939 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5940 | return -EOPNOTSUPP; |
| 5941 | |
| 5942 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5943 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5944 | trace_nfs4_get_security_label(inode, err); |
| 5945 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5946 | &exception); |
| 5947 | } while (exception.retry); |
| 5948 | return err; |
| 5949 | } |
| 5950 | |
| 5951 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5952 | struct nfs4_label *ilabel, |
| 5953 | struct nfs_fattr *fattr, |
| 5954 | struct nfs4_label *olabel) |
| 5955 | { |
| 5956 | |
| 5957 | struct iattr sattr = {0}; |
| 5958 | struct nfs_server *server = NFS_SERVER(inode); |
| 5959 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5960 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5961 | .fh = NFS_FH(inode), |
| 5962 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5963 | .server = server, |
| 5964 | .bitmask = bitmask, |
| 5965 | .label = ilabel, |
| 5966 | }; |
| 5967 | struct nfs_setattrres res = { |
| 5968 | .fattr = fattr, |
| 5969 | .label = olabel, |
| 5970 | .server = server, |
| 5971 | }; |
| 5972 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5974 | .rpc_argp = &arg, |
| 5975 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5976 | }; |
| 5977 | int status; |
| 5978 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5979 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5980 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5981 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5982 | if (status) |
| 5983 | dprintk("%s failed: %d\n", __func__, status); |
| 5984 | |
| 5985 | return status; |
| 5986 | } |
| 5987 | |
| 5988 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5989 | struct nfs4_label *ilabel, |
| 5990 | struct nfs_fattr *fattr, |
| 5991 | struct nfs4_label *olabel) |
| 5992 | { |
| 5993 | struct nfs4_exception exception = { }; |
| 5994 | int err; |
| 5995 | |
| 5996 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5997 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5998 | fattr, olabel); |
| 5999 | trace_nfs4_set_security_label(inode, err); |
| 6000 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6001 | &exception); |
| 6002 | } while (exception.retry); |
| 6003 | return err; |
| 6004 | } |
| 6005 | |
| 6006 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6007 | nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen) |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6008 | { |
| 6009 | struct nfs4_label ilabel, *olabel = NULL; |
| 6010 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6011 | int status; |
| 6012 | |
| 6013 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6014 | return -EOPNOTSUPP; |
| 6015 | |
| 6016 | nfs_fattr_init(&fattr); |
| 6017 | |
| 6018 | ilabel.pi = 0; |
| 6019 | ilabel.lfs = 0; |
| 6020 | ilabel.label = (char *)buf; |
| 6021 | ilabel.len = buflen; |
| 6022 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6023 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 6024 | if (IS_ERR(olabel)) { |
| 6025 | status = -PTR_ERR(olabel); |
| 6026 | goto out; |
| 6027 | } |
| 6028 | |
| 6029 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 6030 | if (status == 0) |
| 6031 | nfs_setsecurity(inode, &fattr, olabel); |
| 6032 | |
| 6033 | nfs4_label_free(olabel); |
| 6034 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6035 | return status; |
| 6036 | } |
| 6037 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 6038 | |
| 6039 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6040 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 6041 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6042 | { |
| 6043 | __be32 verf[2]; |
| 6044 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6045 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 6046 | /* An impossible timestamp guarantees this value |
| 6047 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6048 | verf[0] = cpu_to_be32(U32_MAX); |
| 6049 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6050 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6051 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6052 | u64 ns = ktime_to_ns(nn->boot_time); |
| 6053 | |
| 6054 | verf[0] = cpu_to_be32(ns >> 32); |
| 6055 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6056 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6057 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 6058 | } |
| 6059 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6060 | static int |
| 6061 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6062 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6063 | size_t len; |
| 6064 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6065 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6066 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6067 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 6068 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6069 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6070 | len = 14 + |
| 6071 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 6072 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6073 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6074 | 1; |
| 6075 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6076 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 6077 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6078 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6079 | return -EINVAL; |
| 6080 | |
| 6081 | /* |
| 6082 | * Since this string is allocated at mount time, and held until the |
| 6083 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6084 | * about a memory-reclaim deadlock. |
| 6085 | */ |
| 6086 | str = kmalloc(len, GFP_KERNEL); |
| 6087 | if (!str) |
| 6088 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6089 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6090 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6091 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6092 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6093 | clp->cl_rpcclient->cl_nodename, |
| 6094 | nfs4_client_id_uniquifier, |
| 6095 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6096 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6097 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6098 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6099 | clp->cl_rpcclient->cl_nodename, |
| 6100 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6101 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6102 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6103 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6104 | clp->cl_owner_id = str; |
| 6105 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6106 | } |
| 6107 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6108 | static int |
| 6109 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6110 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6111 | size_t len; |
| 6112 | char *str; |
| 6113 | |
| 6114 | len = 10 + 10 + 1 + 10 + 1 + |
| 6115 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 6116 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6117 | |
| 6118 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6119 | return -EINVAL; |
| 6120 | |
| 6121 | /* |
| 6122 | * Since this string is allocated at mount time, and held until the |
| 6123 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6124 | * about a memory-reclaim deadlock. |
| 6125 | */ |
| 6126 | str = kmalloc(len, GFP_KERNEL); |
| 6127 | if (!str) |
| 6128 | return -ENOMEM; |
| 6129 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 6130 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6131 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6132 | nfs4_client_id_uniquifier, |
| 6133 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6134 | clp->cl_owner_id = str; |
| 6135 | return 0; |
| 6136 | } |
| 6137 | |
| 6138 | static int |
| 6139 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6140 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6141 | size_t len; |
| 6142 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6143 | |
| 6144 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6145 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6146 | |
| 6147 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6148 | return nfs4_init_uniquifier_client_string(clp); |
| 6149 | |
| 6150 | len = 10 + 10 + 1 + 10 + 1 + |
| 6151 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6152 | |
| 6153 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6154 | return -EINVAL; |
| 6155 | |
| 6156 | /* |
| 6157 | * Since this string is allocated at mount time, and held until the |
| 6158 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6159 | * about a memory-reclaim deadlock. |
| 6160 | */ |
| 6161 | str = kmalloc(len, GFP_KERNEL); |
| 6162 | if (!str) |
| 6163 | return -ENOMEM; |
| 6164 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 6165 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6166 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6167 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6168 | clp->cl_owner_id = str; |
| 6169 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6170 | } |
| 6171 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6172 | /* |
| 6173 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6174 | * services. Advertise one based on the address family of the |
| 6175 | * clientaddr. |
| 6176 | */ |
| 6177 | static unsigned int |
| 6178 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6179 | { |
| 6180 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6181 | return scnprintf(buf, len, "tcp6"); |
| 6182 | else |
| 6183 | return scnprintf(buf, len, "tcp"); |
| 6184 | } |
| 6185 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6186 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6187 | { |
| 6188 | struct nfs4_setclientid *sc = calldata; |
| 6189 | |
| 6190 | if (task->tk_status == 0) |
| 6191 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6192 | } |
| 6193 | |
| 6194 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6195 | .rpc_call_done = nfs4_setclientid_done, |
| 6196 | }; |
| 6197 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6198 | /** |
| 6199 | * nfs4_proc_setclientid - Negotiate client ID |
| 6200 | * @clp: state data structure |
| 6201 | * @program: RPC program for NFSv4 callback service |
| 6202 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6203 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6204 | * @res: where to place the result |
| 6205 | * |
| 6206 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6207 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6208 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6209 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6210 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6211 | { |
| 6212 | nfs4_verifier sc_verifier; |
| 6213 | struct nfs4_setclientid setclientid = { |
| 6214 | .sc_verifier = &sc_verifier, |
| 6215 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6216 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | }; |
| 6218 | struct rpc_message msg = { |
| 6219 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6220 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6221 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6222 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6224 | struct rpc_task_setup task_setup_data = { |
| 6225 | .rpc_client = clp->cl_rpcclient, |
| 6226 | .rpc_message = &msg, |
| 6227 | .callback_ops = &nfs4_setclientid_ops, |
| 6228 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6229 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6230 | }; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6231 | unsigned long now = jiffies; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6232 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6233 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6234 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6235 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6236 | |
| 6237 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6238 | status = nfs4_init_uniform_client_string(clp); |
| 6239 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6240 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6241 | |
| 6242 | if (status) |
| 6243 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6244 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6245 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6246 | setclientid.sc_netid_len = |
| 6247 | nfs4_init_callback_netid(clp, |
| 6248 | setclientid.sc_netid, |
| 6249 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6250 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6251 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6252 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6253 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6254 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6255 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6256 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6257 | |
| 6258 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6259 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6260 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6261 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6262 | put_rpccred(setclientid.sc_cred); |
| 6263 | } |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6264 | |
| 6265 | if (status == 0) |
| 6266 | do_renew_lease(clp, now); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6267 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6268 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6269 | dprintk("NFS reply setclientid: %d\n", status); |
| 6270 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6271 | } |
| 6272 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6273 | /** |
| 6274 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6275 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6276 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6277 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6278 | * |
| 6279 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6280 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6281 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6282 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6283 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6285 | struct rpc_message msg = { |
| 6286 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6287 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6288 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | int status; |
| 6291 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6292 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6293 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6294 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6295 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6296 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6297 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6298 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6299 | return status; |
| 6300 | } |
| 6301 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6302 | struct nfs4_delegreturndata { |
| 6303 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6304 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6305 | struct nfs_fh fh; |
| 6306 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6307 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6308 | struct { |
| 6309 | struct nfs4_layoutreturn_args arg; |
| 6310 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6311 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6312 | u32 roc_barrier; |
| 6313 | bool roc; |
| 6314 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6315 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6316 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6317 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6318 | }; |
| 6319 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6320 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6321 | { |
| 6322 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6323 | struct nfs4_exception exception = { |
| 6324 | .inode = data->inode, |
| 6325 | .stateid = &data->stateid, |
| 6326 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6327 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6328 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6329 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6330 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6331 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6332 | |
| 6333 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6334 | if (pnfs_roc_done(task, data->inode, |
| 6335 | &data->args.lr_args, |
| 6336 | &data->res.lr_res, |
| 6337 | &data->res.lr_ret) == -EAGAIN) |
| 6338 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6339 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6340 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6341 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6342 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6343 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6344 | case -NFS4ERR_ADMIN_REVOKED: |
| 6345 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6346 | case -NFS4ERR_EXPIRED: |
| 6347 | nfs4_free_revoked_stateid(data->res.server, |
| 6348 | data->args.stateid, |
| 6349 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6350 | fallthrough; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6351 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6352 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 244fcd2 | 2019-12-20 10:43:37 -0500 | [diff] [blame] | 6353 | case -ETIMEDOUT: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6354 | task->tk_status = 0; |
| 6355 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6356 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6357 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6358 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6359 | if (data->args.bitmask) { |
| 6360 | data->args.bitmask = NULL; |
| 6361 | data->res.fattr = NULL; |
| 6362 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6363 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6364 | case -NFS4ERR_ACCESS: |
| 6365 | if (data->args.bitmask) { |
| 6366 | data->args.bitmask = NULL; |
| 6367 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6368 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6369 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6370 | fallthrough; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6371 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6372 | task->tk_status = nfs4_async_handle_exception(task, |
| 6373 | data->res.server, task->tk_status, |
| 6374 | &exception); |
| 6375 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6376 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6377 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6378 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6379 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6380 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6381 | out_restart: |
| 6382 | task->tk_status = 0; |
| 6383 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | static void nfs4_delegreturn_release(void *calldata) |
| 6387 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6388 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6389 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6390 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6391 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6392 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6393 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6394 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6395 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6396 | nfs_iput_and_deactive(inode); |
| 6397 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6398 | kfree(calldata); |
| 6399 | } |
| 6400 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6401 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6402 | { |
| 6403 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6404 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6405 | |
| 6406 | d_data = (struct nfs4_delegreturndata *)data; |
| 6407 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6408 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6409 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6410 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6411 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6412 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6413 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6414 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6415 | d_data->args.lr_args = NULL; |
| 6416 | d_data->res.lr_res = NULL; |
| 6417 | } |
| 6418 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6419 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6420 | &d_data->args.seq_args, |
| 6421 | &d_data->res.seq_res, |
| 6422 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6423 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6424 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6425 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6426 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6427 | .rpc_call_done = nfs4_delegreturn_done, |
| 6428 | .rpc_release = nfs4_delegreturn_release, |
| 6429 | }; |
| 6430 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6431 | static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6432 | { |
| 6433 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6434 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6435 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6436 | struct rpc_message msg = { |
| 6437 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6438 | .rpc_cred = cred, |
| 6439 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6440 | struct rpc_task_setup task_setup_data = { |
| 6441 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6442 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6443 | .callback_ops = &nfs4_delegreturn_ops, |
Trond Myklebust | f304a80 | 2020-05-11 10:42:04 -0400 | [diff] [blame] | 6444 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6445 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6446 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6447 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6448 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6449 | if (data == NULL) |
| 6450 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6451 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6452 | |
| 6453 | nfs4_state_protect(server->nfs_client, |
| 6454 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6455 | &task_setup_data.rpc_client, &msg); |
| 6456 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6457 | data->args.fhandle = &data->fh; |
| 6458 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6459 | data->args.bitmask = server->cache_consistency_bitmask; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 6460 | nfs4_bitmask_adjust(data->args.bitmask, inode, server, NULL); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6461 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6462 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6463 | data->res.fattr = &data->fattr; |
| 6464 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6465 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6466 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6467 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6468 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6469 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6470 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, cred); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6471 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6472 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6473 | if (data->lr.roc) { |
| 6474 | data->args.lr_args = &data->lr.arg; |
| 6475 | data->res.lr_res = &data->lr.res; |
| 6476 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6477 | } else if (data->lr.roc) { |
| 6478 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6479 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6480 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6481 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6482 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6483 | msg.rpc_argp = &data->args; |
| 6484 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6485 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6486 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6487 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6488 | if (!issync) |
| 6489 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6490 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6491 | if (status != 0) |
| 6492 | goto out; |
| 6493 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6494 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6495 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6496 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6497 | } |
| 6498 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6499 | int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6500 | { |
| 6501 | struct nfs_server *server = NFS_SERVER(inode); |
| 6502 | struct nfs4_exception exception = { }; |
| 6503 | int err; |
| 6504 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6505 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6506 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6507 | switch (err) { |
| 6508 | case -NFS4ERR_STALE_STATEID: |
| 6509 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6510 | case 0: |
| 6511 | return 0; |
| 6512 | } |
| 6513 | err = nfs4_handle_exception(server, err, &exception); |
| 6514 | } while (exception.retry); |
| 6515 | return err; |
| 6516 | } |
| 6517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6518 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6519 | { |
| 6520 | struct inode *inode = state->inode; |
| 6521 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6522 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6523 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6524 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6525 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6526 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6527 | struct nfs_lockt_res res = { |
| 6528 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6529 | }; |
| 6530 | struct rpc_message msg = { |
| 6531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6532 | .rpc_argp = &arg, |
| 6533 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6534 | .rpc_cred = state->owner->so_cred, |
| 6535 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 | struct nfs4_lock_state *lsp; |
| 6537 | int status; |
| 6538 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6539 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6540 | status = nfs4_set_lock_state(state, request); |
| 6541 | if (status != 0) |
| 6542 | goto out; |
| 6543 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6544 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6545 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6546 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6547 | switch (status) { |
| 6548 | case 0: |
| 6549 | request->fl_type = F_UNLCK; |
| 6550 | break; |
| 6551 | case -NFS4ERR_DENIED: |
| 6552 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6553 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6554 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6555 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6556 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6557 | return status; |
| 6558 | } |
| 6559 | |
| 6560 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6561 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6562 | struct nfs4_exception exception = { |
| 6563 | .interruptible = true, |
| 6564 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6565 | int err; |
| 6566 | |
| 6567 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6568 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6569 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6570 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6571 | &exception); |
| 6572 | } while (exception.retry); |
| 6573 | return err; |
| 6574 | } |
| 6575 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6576 | /* |
| 6577 | * Update the seqid of a lock stateid after receiving |
| 6578 | * NFS4ERR_OLD_STATEID |
| 6579 | */ |
| 6580 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6581 | struct nfs4_lock_state *lsp) |
| 6582 | { |
| 6583 | struct nfs4_state *state = lsp->ls_state; |
| 6584 | bool ret = false; |
| 6585 | |
| 6586 | spin_lock(&state->state_lock); |
| 6587 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6588 | goto out; |
| 6589 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6590 | nfs4_stateid_seqid_inc(dst); |
| 6591 | else |
| 6592 | dst->seqid = lsp->ls_stateid.seqid; |
| 6593 | ret = true; |
| 6594 | out: |
| 6595 | spin_unlock(&state->state_lock); |
| 6596 | return ret; |
| 6597 | } |
| 6598 | |
| 6599 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6600 | struct nfs4_lock_state *lsp) |
| 6601 | { |
| 6602 | struct nfs4_state *state = lsp->ls_state; |
| 6603 | bool ret; |
| 6604 | |
| 6605 | spin_lock(&state->state_lock); |
| 6606 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6607 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6608 | spin_unlock(&state->state_lock); |
| 6609 | return ret; |
| 6610 | } |
| 6611 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6612 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6613 | struct nfs_locku_args arg; |
| 6614 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6615 | struct nfs4_lock_state *lsp; |
| 6616 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6617 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6618 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6619 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6620 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6621 | }; |
| 6622 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6623 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6624 | struct nfs_open_context *ctx, |
| 6625 | struct nfs4_lock_state *lsp, |
| 6626 | struct nfs_seqid *seqid) |
| 6627 | { |
| 6628 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6629 | struct nfs4_state *state = lsp->ls_state; |
| 6630 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6631 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6632 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6633 | if (p == NULL) |
| 6634 | return NULL; |
| 6635 | p->arg.fh = NFS_FH(inode); |
| 6636 | p->arg.fl = &p->fl; |
| 6637 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6638 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6639 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6640 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6641 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6642 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6643 | locks_init_lock(&p->fl); |
| 6644 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6645 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6646 | spin_lock(&state->state_lock); |
| 6647 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6648 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6649 | return p; |
| 6650 | } |
| 6651 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6652 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6653 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6654 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6655 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6656 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6657 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6658 | put_nfs_open_context(calldata->ctx); |
| 6659 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6660 | } |
| 6661 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6662 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6663 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6664 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6665 | struct nfs4_exception exception = { |
| 6666 | .inode = calldata->lsp->ls_state->inode, |
| 6667 | .stateid = &calldata->arg.stateid, |
| 6668 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6669 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6670 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6671 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6672 | switch (task->tk_status) { |
| 6673 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6674 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6675 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6676 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6677 | &calldata->res.stateid)) |
| 6678 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6679 | fallthrough; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6680 | case -NFS4ERR_ADMIN_REVOKED: |
| 6681 | case -NFS4ERR_EXPIRED: |
| 6682 | nfs4_free_revoked_stateid(calldata->server, |
| 6683 | &calldata->arg.stateid, |
| 6684 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6685 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6686 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6687 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6688 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6689 | calldata->lsp)) |
| 6690 | rpc_restart_call_prepare(task); |
| 6691 | break; |
| 6692 | case -NFS4ERR_OLD_STATEID: |
| 6693 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6694 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6695 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6696 | break; |
| 6697 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6698 | task->tk_status = nfs4_async_handle_exception(task, |
| 6699 | calldata->server, task->tk_status, |
| 6700 | &exception); |
| 6701 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6702 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6703 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6704 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6705 | } |
| 6706 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6707 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6708 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6709 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6710 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6711 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6712 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6713 | return; |
| 6714 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6715 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6716 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6717 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6718 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6719 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6720 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6721 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6722 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6723 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6724 | &calldata->res.seq_res, |
| 6725 | task) != 0) |
| 6726 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6727 | return; |
| 6728 | out_no_action: |
| 6729 | task->tk_action = NULL; |
| 6730 | out_wait: |
| 6731 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6732 | } |
| 6733 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6734 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6735 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6736 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6737 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6738 | }; |
| 6739 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6740 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6741 | struct nfs_open_context *ctx, |
| 6742 | struct nfs4_lock_state *lsp, |
| 6743 | struct nfs_seqid *seqid) |
| 6744 | { |
| 6745 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6746 | struct rpc_message msg = { |
| 6747 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6748 | .rpc_cred = ctx->cred, |
| 6749 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6750 | struct rpc_task_setup task_setup_data = { |
| 6751 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6752 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6753 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6754 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6755 | .flags = RPC_TASK_ASYNC, |
| 6756 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6757 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6758 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6759 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6760 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6761 | /* Ensure this is an unlock - when canceling a lock, the |
| 6762 | * canceled lock is passed in, and it won't be an unlock. |
| 6763 | */ |
| 6764 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6765 | if (fl->fl_flags & FL_CLOSE) |
| 6766 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6767 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6768 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6769 | if (data == NULL) { |
| 6770 | nfs_free_seqid(seqid); |
| 6771 | return ERR_PTR(-ENOMEM); |
| 6772 | } |
| 6773 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6774 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, 0); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6775 | msg.rpc_argp = &data->arg; |
| 6776 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6777 | task_setup_data.callback_data = data; |
| 6778 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6779 | } |
| 6780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6781 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6782 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6783 | struct inode *inode = state->inode; |
| 6784 | struct nfs4_state_owner *sp = state->owner; |
| 6785 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6786 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6787 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6788 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6789 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6790 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6791 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6792 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6793 | status = nfs4_set_lock_state(state, request); |
| 6794 | /* Unlock _before_ we do the RPC call */ |
| 6795 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6796 | /* Exclude nfs_delegation_claim_locks() */ |
| 6797 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6798 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6799 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6800 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6801 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6802 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6803 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6804 | } |
| 6805 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6806 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6807 | if (status != 0) |
| 6808 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6809 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6810 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6811 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6812 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6813 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6814 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6815 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6816 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6817 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6818 | task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6819 | status = PTR_ERR(task); |
| 6820 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6821 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6822 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6823 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6824 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6825 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6826 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6827 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6828 | } |
| 6829 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6830 | struct nfs4_lockdata { |
| 6831 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6832 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6833 | struct nfs4_lock_state *lsp; |
| 6834 | struct nfs_open_context *ctx; |
| 6835 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6836 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6837 | int rpc_status; |
| 6838 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6839 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6840 | }; |
| 6841 | |
| 6842 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6843 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6844 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6845 | { |
| 6846 | struct nfs4_lockdata *p; |
| 6847 | struct inode *inode = lsp->ls_state->inode; |
| 6848 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6849 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6850 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6851 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6852 | if (p == NULL) |
| 6853 | return NULL; |
| 6854 | |
| 6855 | p->arg.fh = NFS_FH(inode); |
| 6856 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6857 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6858 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6859 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6860 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6861 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6862 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6863 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6864 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6865 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6866 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6867 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6868 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6869 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6870 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6871 | locks_init_lock(&p->fl); |
| 6872 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6873 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6874 | out_free_seqid: |
| 6875 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6876 | out_free: |
| 6877 | kfree(p); |
| 6878 | return NULL; |
| 6879 | } |
| 6880 | |
| 6881 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6882 | { |
| 6883 | struct nfs4_lockdata *data = calldata; |
| 6884 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6885 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6886 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6887 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6888 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6889 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6890 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6891 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6892 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6893 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6894 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6895 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6896 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6897 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6898 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6899 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6900 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6901 | &data->lsp->ls_stateid); |
| 6902 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6903 | if (!nfs4_valid_open_stateid(state)) { |
| 6904 | data->rpc_status = -EBADF; |
| 6905 | task->tk_action = NULL; |
| 6906 | goto out_release_open_seqid; |
| 6907 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6908 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6909 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6910 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6911 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6912 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6913 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6914 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6915 | nfs_release_seqid(data->arg.open_seqid); |
| 6916 | out_release_lock_seqid: |
| 6917 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6918 | out_wait: |
| 6919 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6920 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6921 | } |
| 6922 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6923 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6924 | { |
| 6925 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6926 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6927 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6928 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6929 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6930 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6931 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6932 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6933 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6934 | switch (task->tk_status) { |
| 6935 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6936 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6937 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6938 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6939 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6940 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6941 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6942 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6943 | if (data->arg.new_lock_owner != 0) { |
| 6944 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6945 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6946 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6947 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6948 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6949 | break; |
| 6950 | case -NFS4ERR_BAD_STATEID: |
| 6951 | case -NFS4ERR_OLD_STATEID: |
| 6952 | case -NFS4ERR_STALE_STATEID: |
| 6953 | case -NFS4ERR_EXPIRED: |
| 6954 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6955 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6956 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6957 | goto out_restart; |
| 6958 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6959 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6960 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6961 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6962 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6963 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6964 | return; |
| 6965 | out_restart: |
| 6966 | if (!data->cancelled) |
| 6967 | rpc_restart_call_prepare(task); |
| 6968 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6969 | } |
| 6970 | |
| 6971 | static void nfs4_lock_release(void *calldata) |
| 6972 | { |
| 6973 | struct nfs4_lockdata *data = calldata; |
| 6974 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6975 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6976 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6977 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6978 | struct rpc_task *task; |
| 6979 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6980 | data->arg.lock_seqid); |
| 6981 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6982 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6983 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6984 | } else |
| 6985 | nfs_free_seqid(data->arg.lock_seqid); |
| 6986 | nfs4_put_lock_state(data->lsp); |
| 6987 | put_nfs_open_context(data->ctx); |
| 6988 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6989 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6993 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6994 | .rpc_call_done = nfs4_lock_done, |
| 6995 | .rpc_release = nfs4_lock_release, |
| 6996 | }; |
| 6997 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6998 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6999 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7000 | switch (error) { |
| 7001 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 7002 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7003 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7004 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7005 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 7006 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7007 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7008 | break; |
| 7009 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7010 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7011 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 7012 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7013 | } |
| 7014 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7015 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7016 | { |
| 7017 | struct nfs4_lockdata *data; |
| 7018 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7019 | struct rpc_message msg = { |
| 7020 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 7021 | .rpc_cred = state->owner->so_cred, |
| 7022 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7023 | struct rpc_task_setup task_setup_data = { |
| 7024 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7025 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7026 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 7027 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 7028 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7029 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7030 | int ret; |
| 7031 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7032 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7033 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7034 | fl->fl_u.nfs4_fl.owner, |
| 7035 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7036 | if (data == NULL) |
| 7037 | return -ENOMEM; |
| 7038 | if (IS_SETLKW(cmd)) |
| 7039 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7040 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 7041 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 7042 | msg.rpc_argp = &data->arg; |
| 7043 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7044 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7045 | if (recovery_type > NFS_LOCK_NEW) { |
| 7046 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 7047 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7048 | } else |
| 7049 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7050 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 7051 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7052 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 7053 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7054 | if (ret == 0) { |
| 7055 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7056 | if (ret) |
| 7057 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 7058 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7059 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 7060 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 7061 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7062 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 7063 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7064 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7065 | } |
| 7066 | |
| 7067 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 7068 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7069 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7070 | struct nfs4_exception exception = { |
| 7071 | .inode = state->inode, |
| 7072 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7073 | int err; |
| 7074 | |
| 7075 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7076 | /* Cache the lock if possible... */ |
| 7077 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7078 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7079 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 7080 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7081 | break; |
| 7082 | nfs4_handle_exception(server, err, &exception); |
| 7083 | } while (exception.retry); |
| 7084 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7088 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7089 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7090 | struct nfs4_exception exception = { |
| 7091 | .inode = state->inode, |
| 7092 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7093 | int err; |
| 7094 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 7095 | err = nfs4_set_lock_state(state, request); |
| 7096 | if (err != 0) |
| 7097 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 7098 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 7099 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 7100 | return 0; |
| 7101 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7102 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7103 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7104 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7105 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7106 | switch (err) { |
| 7107 | default: |
| 7108 | goto out; |
| 7109 | case -NFS4ERR_GRACE: |
| 7110 | case -NFS4ERR_DELAY: |
| 7111 | nfs4_handle_exception(server, err, &exception); |
| 7112 | err = 0; |
| 7113 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7114 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7115 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7116 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7117 | } |
| 7118 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7119 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7120 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7121 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7122 | struct nfs4_lock_state *lsp; |
| 7123 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7124 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7125 | status = nfs4_set_lock_state(state, request); |
| 7126 | if (status != 0) |
| 7127 | return status; |
| 7128 | lsp = request->fl_u.nfs4_fl.owner; |
| 7129 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7130 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7131 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7132 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7133 | } |
| 7134 | #endif |
| 7135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7136 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7137 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7138 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7139 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7140 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7141 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7142 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7143 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7144 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7145 | if (status < 0) |
| 7146 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7147 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7148 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7149 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7150 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7151 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7152 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7153 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7154 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7155 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7156 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7157 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7158 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7159 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7160 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7161 | out: |
| 7162 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7163 | return status; |
| 7164 | } |
| 7165 | |
| 7166 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7167 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7168 | struct nfs4_exception exception = { |
| 7169 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7170 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7171 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7172 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7173 | int err; |
| 7174 | |
| 7175 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7176 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7177 | if (err == -NFS4ERR_DENIED) |
| 7178 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7179 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7180 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7181 | } while (exception.retry); |
| 7182 | return err; |
| 7183 | } |
| 7184 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7185 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7186 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7187 | |
| 7188 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7189 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7190 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7191 | { |
| 7192 | int status = -ERESTARTSYS; |
| 7193 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7194 | |
| 7195 | while(!signalled()) { |
| 7196 | status = nfs4_proc_setlk(state, cmd, request); |
| 7197 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7198 | break; |
| 7199 | freezable_schedule_timeout_interruptible(timeout); |
| 7200 | timeout *= 2; |
| 7201 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7202 | status = -ERESTARTSYS; |
| 7203 | } |
| 7204 | return status; |
| 7205 | } |
| 7206 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7207 | #ifdef CONFIG_NFS_V4_1 |
| 7208 | struct nfs4_lock_waiter { |
| 7209 | struct task_struct *task; |
| 7210 | struct inode *inode; |
| 7211 | struct nfs_lowner *owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7212 | }; |
| 7213 | |
| 7214 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7215 | nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, void *key) |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7216 | { |
| 7217 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7218 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7219 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7220 | /* NULL key means to wake up everyone */ |
| 7221 | if (key) { |
| 7222 | struct cb_notify_lock_args *cbnl = key; |
| 7223 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 7224 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7225 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7226 | /* Only wake if the callback was for the same owner. */ |
| 7227 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7228 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7229 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7230 | /* Make sure it's for the right inode */ |
| 7231 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7232 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7233 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7234 | |
| 7235 | /* override "private" so we can use default_wake_function */ |
| 7236 | wait->private = waiter->task; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7237 | ret = woken_wake_function(wait, mode, flags, key); |
| 7238 | if (ret) |
| 7239 | list_del_init(&wait->entry); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7240 | wait->private = waiter; |
| 7241 | return ret; |
| 7242 | } |
| 7243 | |
| 7244 | static int |
| 7245 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7246 | { |
| 7247 | int status = -ERESTARTSYS; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7248 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7249 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7250 | struct nfs_client *clp = server->nfs_client; |
| 7251 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 7252 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 7253 | .id = lsp->ls_seqid.owner_id, |
| 7254 | .s_dev = server->s_dev }; |
| 7255 | struct nfs4_lock_waiter waiter = { .task = current, |
| 7256 | .inode = state->inode, |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7257 | .owner = &owner}; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7258 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7259 | |
| 7260 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7261 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7262 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7263 | |
| 7264 | init_wait(&wait); |
| 7265 | wait.private = &waiter; |
| 7266 | wait.func = nfs4_wake_lock_waiter; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7267 | |
| 7268 | while(!signalled()) { |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7269 | add_wait_queue(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7270 | status = nfs4_proc_setlk(state, cmd, request); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7271 | if ((status != -EAGAIN) || IS_SETLK(cmd)) { |
| 7272 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7273 | break; |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7274 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7275 | |
| 7276 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7277 | freezer_do_not_count(); |
| 7278 | wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); |
| 7279 | freezer_count(); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7280 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7281 | } |
| 7282 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7283 | return status; |
| 7284 | } |
| 7285 | #else /* !CONFIG_NFS_V4_1 */ |
| 7286 | static inline int |
| 7287 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7288 | { |
| 7289 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7290 | } |
| 7291 | #endif |
| 7292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7293 | static int |
| 7294 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7295 | { |
| 7296 | struct nfs_open_context *ctx; |
| 7297 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7298 | int status; |
| 7299 | |
| 7300 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7301 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7302 | state = ctx->state; |
| 7303 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7304 | if (IS_GETLK(cmd)) { |
| 7305 | if (state != NULL) |
| 7306 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7307 | return 0; |
| 7308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7309 | |
| 7310 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7311 | return -EINVAL; |
| 7312 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7313 | if (request->fl_type == F_UNLCK) { |
| 7314 | if (state != NULL) |
| 7315 | return nfs4_proc_unlck(state, cmd, request); |
| 7316 | return 0; |
| 7317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7318 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7319 | if (state == NULL) |
| 7320 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7321 | |
| 7322 | if ((request->fl_flags & FL_POSIX) && |
| 7323 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7324 | return -ENOLCK; |
| 7325 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7326 | /* |
| 7327 | * Don't rely on the VFS having checked the file open mode, |
| 7328 | * since it won't do this for flock() locks. |
| 7329 | */ |
| 7330 | switch (request->fl_type) { |
| 7331 | case F_RDLCK: |
| 7332 | if (!(filp->f_mode & FMODE_READ)) |
| 7333 | return -EBADF; |
| 7334 | break; |
| 7335 | case F_WRLCK: |
| 7336 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7337 | return -EBADF; |
| 7338 | } |
| 7339 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7340 | status = nfs4_set_lock_state(state, request); |
| 7341 | if (status != 0) |
| 7342 | return status; |
| 7343 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7344 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7345 | } |
| 7346 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7347 | int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7348 | { |
| 7349 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7350 | int err; |
| 7351 | |
| 7352 | err = nfs4_set_lock_state(state, fl); |
| 7353 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7354 | return err; |
Olga Kornievskaia | 3d7a952 | 2020-08-20 18:52:43 -0400 | [diff] [blame] | 7355 | do { |
| 7356 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
| 7357 | if (err != -NFS4ERR_DELAY) |
| 7358 | break; |
| 7359 | ssleep(1); |
| 7360 | } while (err == -NFS4ERR_DELAY); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7361 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7362 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7363 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7364 | struct nfs_release_lockowner_data { |
| 7365 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7366 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7367 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7368 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7369 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7370 | }; |
| 7371 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7372 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7373 | { |
| 7374 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7375 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7376 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7377 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7378 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7379 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7383 | { |
| 7384 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7385 | struct nfs_server *server = data->server; |
| 7386 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7387 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7388 | |
| 7389 | switch (task->tk_status) { |
| 7390 | case 0: |
| 7391 | renew_lease(server, data->timestamp); |
| 7392 | break; |
| 7393 | case -NFS4ERR_STALE_CLIENTID: |
| 7394 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7395 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7396 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7397 | case -NFS4ERR_LEASE_MOVED: |
| 7398 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7399 | if (nfs4_async_handle_error(task, server, |
| 7400 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7401 | rpc_restart_call_prepare(task); |
| 7402 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7403 | } |
| 7404 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7405 | static void nfs4_release_lockowner_release(void *calldata) |
| 7406 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7407 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7408 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7409 | kfree(calldata); |
| 7410 | } |
| 7411 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7412 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7413 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7414 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7415 | .rpc_release = nfs4_release_lockowner_release, |
| 7416 | }; |
| 7417 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7418 | static void |
| 7419 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7420 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7421 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7422 | struct rpc_message msg = { |
| 7423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7424 | }; |
| 7425 | |
| 7426 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7427 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7428 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7429 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7430 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7431 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7432 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7433 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7434 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7435 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7436 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7437 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7438 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7439 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7440 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7441 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7442 | } |
| 7443 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7444 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7445 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7446 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7447 | struct dentry *unused, struct inode *inode, |
| 7448 | const char *key, const void *buf, |
| 7449 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7450 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7451 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7452 | } |
| 7453 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7454 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7455 | struct dentry *unused, struct inode *inode, |
| 7456 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7457 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7458 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7459 | } |
| 7460 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7461 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7462 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7463 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7464 | } |
| 7465 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7466 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7467 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7468 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7469 | struct dentry *unused, struct inode *inode, |
| 7470 | const char *key, const void *buf, |
| 7471 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7472 | { |
| 7473 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7474 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7475 | |
| 7476 | return -EOPNOTSUPP; |
| 7477 | } |
| 7478 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7479 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7480 | struct dentry *unused, struct inode *inode, |
| 7481 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7482 | { |
| 7483 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7484 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7485 | return -EOPNOTSUPP; |
| 7486 | } |
| 7487 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7488 | static ssize_t |
| 7489 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7490 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7491 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7492 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7493 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7494 | len = security_inode_listsecurity(inode, list, list_len); |
Chengguang Xu | 82c596e | 2020-06-17 09:09:39 +0800 | [diff] [blame] | 7495 | if (len >= 0 && list_len && len > list_len) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7496 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7497 | } |
| 7498 | return len; |
| 7499 | } |
| 7500 | |
| 7501 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7502 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7503 | .get = nfs4_xattr_get_nfs4_label, |
| 7504 | .set = nfs4_xattr_set_nfs4_label, |
| 7505 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7506 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7507 | #else |
| 7508 | |
| 7509 | static ssize_t |
| 7510 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7511 | { |
| 7512 | return 0; |
| 7513 | } |
| 7514 | |
| 7515 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7516 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7517 | #ifdef CONFIG_NFS_V4_2 |
| 7518 | static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
| 7519 | struct dentry *unused, struct inode *inode, |
| 7520 | const char *key, const void *buf, |
| 7521 | size_t buflen, int flags) |
| 7522 | { |
| 7523 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7524 | int ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7525 | |
| 7526 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7527 | return -EOPNOTSUPP; |
| 7528 | |
| 7529 | /* |
| 7530 | * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
| 7531 | * flags right now. Handling of xattr operations use the normal |
| 7532 | * file read/write permissions. |
| 7533 | * |
| 7534 | * Just in case the server has other ideas (which RFC 8276 allows), |
| 7535 | * do a cached access check for the XA* flags to possibly avoid |
| 7536 | * doing an RPC and getting EACCES back. |
| 7537 | */ |
| 7538 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7539 | if (!(cache.mask & NFS_ACCESS_XAWRITE)) |
| 7540 | return -EACCES; |
| 7541 | } |
| 7542 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7543 | if (buf == NULL) { |
| 7544 | ret = nfs42_proc_removexattr(inode, key); |
| 7545 | if (!ret) |
| 7546 | nfs4_xattr_cache_remove(inode, key); |
| 7547 | } else { |
| 7548 | ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
| 7549 | if (!ret) |
| 7550 | nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
| 7551 | } |
| 7552 | |
| 7553 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7554 | } |
| 7555 | |
| 7556 | static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
| 7557 | struct dentry *unused, struct inode *inode, |
| 7558 | const char *key, void *buf, size_t buflen) |
| 7559 | { |
| 7560 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7561 | ssize_t ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7562 | |
| 7563 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7564 | return -EOPNOTSUPP; |
| 7565 | |
| 7566 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7567 | if (!(cache.mask & NFS_ACCESS_XAREAD)) |
| 7568 | return -EACCES; |
| 7569 | } |
| 7570 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7571 | ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
| 7572 | if (ret) |
| 7573 | return ret; |
| 7574 | |
| 7575 | ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
| 7576 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7577 | return ret; |
| 7578 | |
| 7579 | ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
| 7580 | |
| 7581 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7582 | } |
| 7583 | |
| 7584 | static ssize_t |
| 7585 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7586 | { |
| 7587 | u64 cookie; |
| 7588 | bool eof; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7589 | ssize_t ret, size; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7590 | char *buf; |
| 7591 | size_t buflen; |
| 7592 | struct nfs_access_entry cache; |
| 7593 | |
| 7594 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7595 | return 0; |
| 7596 | |
| 7597 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7598 | if (!(cache.mask & NFS_ACCESS_XALIST)) |
| 7599 | return 0; |
| 7600 | } |
| 7601 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7602 | ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
| 7603 | if (ret) |
| 7604 | return ret; |
| 7605 | |
| 7606 | ret = nfs4_xattr_cache_list(inode, list, list_len); |
| 7607 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7608 | return ret; |
| 7609 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7610 | cookie = 0; |
| 7611 | eof = false; |
| 7612 | buflen = list_len ? list_len : XATTR_LIST_MAX; |
| 7613 | buf = list_len ? list : NULL; |
| 7614 | size = 0; |
| 7615 | |
| 7616 | while (!eof) { |
| 7617 | ret = nfs42_proc_listxattrs(inode, buf, buflen, |
| 7618 | &cookie, &eof); |
| 7619 | if (ret < 0) |
| 7620 | return ret; |
| 7621 | |
| 7622 | if (list_len) { |
| 7623 | buf += ret; |
| 7624 | buflen -= ret; |
| 7625 | } |
| 7626 | size += ret; |
| 7627 | } |
| 7628 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7629 | if (list_len) |
| 7630 | nfs4_xattr_cache_set_list(inode, list, size); |
| 7631 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7632 | return size; |
| 7633 | } |
| 7634 | |
| 7635 | #else |
| 7636 | |
| 7637 | static ssize_t |
| 7638 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7639 | { |
| 7640 | return 0; |
| 7641 | } |
| 7642 | #endif /* CONFIG_NFS_V4_2 */ |
| 7643 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7644 | /* |
| 7645 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7646 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7647 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7648 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7649 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7650 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7651 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7652 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7653 | return; |
| 7654 | |
| 7655 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7656 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7657 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7658 | fattr->nlink = 2; |
| 7659 | } |
| 7660 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7661 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7662 | const struct qstr *name, |
| 7663 | struct nfs4_fs_locations *fs_locations, |
| 7664 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7665 | { |
| 7666 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7667 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7668 | struct nfs4_fs_locations_arg args = { |
| 7669 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7670 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7671 | .page = page, |
| 7672 | .bitmask = bitmask, |
| 7673 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7674 | struct nfs4_fs_locations_res res = { |
| 7675 | .fs_locations = fs_locations, |
| 7676 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7677 | struct rpc_message msg = { |
| 7678 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7679 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7680 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7681 | }; |
| 7682 | int status; |
| 7683 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7684 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7685 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7686 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7687 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7688 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7689 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7690 | * is not supported */ |
| 7691 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7692 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7693 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7694 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7695 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7696 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7697 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7698 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7699 | status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7700 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7701 | return status; |
| 7702 | } |
| 7703 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7704 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7705 | const struct qstr *name, |
| 7706 | struct nfs4_fs_locations *fs_locations, |
| 7707 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7708 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7709 | struct nfs4_exception exception = { |
| 7710 | .interruptible = true, |
| 7711 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7712 | int err; |
| 7713 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7714 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7715 | fs_locations, page); |
| 7716 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7717 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7718 | &exception); |
| 7719 | } while (exception.retry); |
| 7720 | return err; |
| 7721 | } |
| 7722 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7723 | /* |
| 7724 | * This operation also signals the server that this client is |
| 7725 | * performing migration recovery. The server can stop returning |
| 7726 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7727 | * appended to this compound to identify the client ID which is |
| 7728 | * performing recovery. |
| 7729 | */ |
| 7730 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7731 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7732 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7733 | { |
| 7734 | struct nfs_server *server = NFS_SERVER(inode); |
| 7735 | struct rpc_clnt *clnt = server->client; |
| 7736 | u32 bitmask[2] = { |
| 7737 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7738 | }; |
| 7739 | struct nfs4_fs_locations_arg args = { |
| 7740 | .clientid = server->nfs_client->cl_clientid, |
| 7741 | .fh = NFS_FH(inode), |
| 7742 | .page = page, |
| 7743 | .bitmask = bitmask, |
| 7744 | .migration = 1, /* skip LOOKUP */ |
| 7745 | .renew = 1, /* append RENEW */ |
| 7746 | }; |
| 7747 | struct nfs4_fs_locations_res res = { |
| 7748 | .fs_locations = locations, |
| 7749 | .migration = 1, |
| 7750 | .renew = 1, |
| 7751 | }; |
| 7752 | struct rpc_message msg = { |
| 7753 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7754 | .rpc_argp = &args, |
| 7755 | .rpc_resp = &res, |
| 7756 | .rpc_cred = cred, |
| 7757 | }; |
| 7758 | unsigned long now = jiffies; |
| 7759 | int status; |
| 7760 | |
| 7761 | nfs_fattr_init(&locations->fattr); |
| 7762 | locations->server = server; |
| 7763 | locations->nlocations = 0; |
| 7764 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7765 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7766 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7767 | &args.seq_args, &res.seq_res); |
| 7768 | if (status) |
| 7769 | return status; |
| 7770 | |
| 7771 | renew_lease(server, now); |
| 7772 | return 0; |
| 7773 | } |
| 7774 | |
| 7775 | #ifdef CONFIG_NFS_V4_1 |
| 7776 | |
| 7777 | /* |
| 7778 | * This operation also signals the server that this client is |
| 7779 | * performing migration recovery. The server can stop asserting |
| 7780 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7781 | * performing this operation is identified in the SEQUENCE |
| 7782 | * operation in this compound. |
| 7783 | * |
| 7784 | * When the client supports GETATTR(fs_locations_info), it can |
| 7785 | * be plumbed in here. |
| 7786 | */ |
| 7787 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7788 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7789 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7790 | { |
| 7791 | struct nfs_server *server = NFS_SERVER(inode); |
| 7792 | struct rpc_clnt *clnt = server->client; |
| 7793 | u32 bitmask[2] = { |
| 7794 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7795 | }; |
| 7796 | struct nfs4_fs_locations_arg args = { |
| 7797 | .fh = NFS_FH(inode), |
| 7798 | .page = page, |
| 7799 | .bitmask = bitmask, |
| 7800 | .migration = 1, /* skip LOOKUP */ |
| 7801 | }; |
| 7802 | struct nfs4_fs_locations_res res = { |
| 7803 | .fs_locations = locations, |
| 7804 | .migration = 1, |
| 7805 | }; |
| 7806 | struct rpc_message msg = { |
| 7807 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7808 | .rpc_argp = &args, |
| 7809 | .rpc_resp = &res, |
| 7810 | .rpc_cred = cred, |
| 7811 | }; |
| 7812 | int status; |
| 7813 | |
| 7814 | nfs_fattr_init(&locations->fattr); |
| 7815 | locations->server = server; |
| 7816 | locations->nlocations = 0; |
| 7817 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7818 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7819 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7820 | &args.seq_args, &res.seq_res); |
| 7821 | if (status == NFS4_OK && |
| 7822 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7823 | status = -NFS4ERR_LEASE_MOVED; |
| 7824 | return status; |
| 7825 | } |
| 7826 | |
| 7827 | #endif /* CONFIG_NFS_V4_1 */ |
| 7828 | |
| 7829 | /** |
| 7830 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7831 | * @inode: inode on FSID that is migrating |
| 7832 | * @locations: result of query |
| 7833 | * @page: buffer |
| 7834 | * @cred: credential to use for this operation |
| 7835 | * |
| 7836 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7837 | * operation failed, or a negative errno if a local error occurred. |
| 7838 | * |
| 7839 | * On success, "locations" is filled in, but if the server has |
| 7840 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7841 | * asserted. |
| 7842 | * |
| 7843 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7844 | * from this client that require migration recovery. |
| 7845 | */ |
| 7846 | int nfs4_proc_get_locations(struct inode *inode, |
| 7847 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7848 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7849 | { |
| 7850 | struct nfs_server *server = NFS_SERVER(inode); |
| 7851 | struct nfs_client *clp = server->nfs_client; |
| 7852 | const struct nfs4_mig_recovery_ops *ops = |
| 7853 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7854 | struct nfs4_exception exception = { |
| 7855 | .interruptible = true, |
| 7856 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7857 | int status; |
| 7858 | |
| 7859 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7860 | (unsigned long long)server->fsid.major, |
| 7861 | (unsigned long long)server->fsid.minor, |
| 7862 | clp->cl_hostname); |
| 7863 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7864 | |
| 7865 | do { |
| 7866 | status = ops->get_locations(inode, locations, page, cred); |
| 7867 | if (status != -NFS4ERR_DELAY) |
| 7868 | break; |
| 7869 | nfs4_handle_exception(server, status, &exception); |
| 7870 | } while (exception.retry); |
| 7871 | return status; |
| 7872 | } |
| 7873 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7874 | /* |
| 7875 | * This operation also signals the server that this client is |
| 7876 | * performing "lease moved" recovery. The server can stop |
| 7877 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7878 | * is appended to this compound to identify the client ID which is |
| 7879 | * performing recovery. |
| 7880 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7881 | static int _nfs40_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7882 | { |
| 7883 | struct nfs_server *server = NFS_SERVER(inode); |
| 7884 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7885 | struct rpc_clnt *clnt = server->client; |
| 7886 | struct nfs4_fsid_present_arg args = { |
| 7887 | .fh = NFS_FH(inode), |
| 7888 | .clientid = clp->cl_clientid, |
| 7889 | .renew = 1, /* append RENEW */ |
| 7890 | }; |
| 7891 | struct nfs4_fsid_present_res res = { |
| 7892 | .renew = 1, |
| 7893 | }; |
| 7894 | struct rpc_message msg = { |
| 7895 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7896 | .rpc_argp = &args, |
| 7897 | .rpc_resp = &res, |
| 7898 | .rpc_cred = cred, |
| 7899 | }; |
| 7900 | unsigned long now = jiffies; |
| 7901 | int status; |
| 7902 | |
| 7903 | res.fh = nfs_alloc_fhandle(); |
| 7904 | if (res.fh == NULL) |
| 7905 | return -ENOMEM; |
| 7906 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7907 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7908 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7909 | &args.seq_args, &res.seq_res); |
| 7910 | nfs_free_fhandle(res.fh); |
| 7911 | if (status) |
| 7912 | return status; |
| 7913 | |
| 7914 | do_renew_lease(clp, now); |
| 7915 | return 0; |
| 7916 | } |
| 7917 | |
| 7918 | #ifdef CONFIG_NFS_V4_1 |
| 7919 | |
| 7920 | /* |
| 7921 | * This operation also signals the server that this client is |
| 7922 | * performing "lease moved" recovery. The server can stop asserting |
| 7923 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7924 | * this operation is identified in the SEQUENCE operation in this |
| 7925 | * compound. |
| 7926 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7927 | static int _nfs41_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7928 | { |
| 7929 | struct nfs_server *server = NFS_SERVER(inode); |
| 7930 | struct rpc_clnt *clnt = server->client; |
| 7931 | struct nfs4_fsid_present_arg args = { |
| 7932 | .fh = NFS_FH(inode), |
| 7933 | }; |
| 7934 | struct nfs4_fsid_present_res res = { |
| 7935 | }; |
| 7936 | struct rpc_message msg = { |
| 7937 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7938 | .rpc_argp = &args, |
| 7939 | .rpc_resp = &res, |
| 7940 | .rpc_cred = cred, |
| 7941 | }; |
| 7942 | int status; |
| 7943 | |
| 7944 | res.fh = nfs_alloc_fhandle(); |
| 7945 | if (res.fh == NULL) |
| 7946 | return -ENOMEM; |
| 7947 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7948 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7949 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7950 | &args.seq_args, &res.seq_res); |
| 7951 | nfs_free_fhandle(res.fh); |
| 7952 | if (status == NFS4_OK && |
| 7953 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7954 | status = -NFS4ERR_LEASE_MOVED; |
| 7955 | return status; |
| 7956 | } |
| 7957 | |
| 7958 | #endif /* CONFIG_NFS_V4_1 */ |
| 7959 | |
| 7960 | /** |
| 7961 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7962 | * @inode: inode on FSID to check |
| 7963 | * @cred: credential to use for this operation |
| 7964 | * |
| 7965 | * Server indicates whether the FSID is present, moved, or not |
| 7966 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7967 | * condition for this client ID. |
| 7968 | * |
| 7969 | * Returns NFS4_OK if the FSID is present on this server, |
| 7970 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7971 | * NFS4ERR code if some error occurred on the server, or a |
| 7972 | * negative errno if a local failure occurred. |
| 7973 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7974 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7975 | { |
| 7976 | struct nfs_server *server = NFS_SERVER(inode); |
| 7977 | struct nfs_client *clp = server->nfs_client; |
| 7978 | const struct nfs4_mig_recovery_ops *ops = |
| 7979 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7980 | struct nfs4_exception exception = { |
| 7981 | .interruptible = true, |
| 7982 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7983 | int status; |
| 7984 | |
| 7985 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7986 | (unsigned long long)server->fsid.major, |
| 7987 | (unsigned long long)server->fsid.minor, |
| 7988 | clp->cl_hostname); |
| 7989 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7990 | |
| 7991 | do { |
| 7992 | status = ops->fsid_present(inode, cred); |
| 7993 | if (status != -NFS4ERR_DELAY) |
| 7994 | break; |
| 7995 | nfs4_handle_exception(server, status, &exception); |
| 7996 | } while (exception.retry); |
| 7997 | return status; |
| 7998 | } |
| 7999 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 8000 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8001 | * If 'use_integrity' is true and the state managment nfs_client |
| 8002 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 8003 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 8004 | * Considerations sections. Otherwise, just use the user cred with the |
| 8005 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 8006 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8007 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8008 | { |
| 8009 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8010 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 8011 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8012 | struct nfs4_secinfo_arg args = { |
| 8013 | .dir_fh = NFS_FH(dir), |
| 8014 | .name = name, |
| 8015 | }; |
| 8016 | struct nfs4_secinfo_res res = { |
| 8017 | .flavors = flavors, |
| 8018 | }; |
| 8019 | struct rpc_message msg = { |
| 8020 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 8021 | .rpc_argp = &args, |
| 8022 | .rpc_resp = &res, |
| 8023 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8024 | struct nfs4_call_sync_data data = { |
| 8025 | .seq_server = NFS_SERVER(dir), |
| 8026 | .seq_args = &args.seq_args, |
| 8027 | .seq_res = &res.seq_res, |
| 8028 | }; |
| 8029 | struct rpc_task_setup task_setup = { |
| 8030 | .rpc_client = clnt, |
| 8031 | .rpc_message = &msg, |
| 8032 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 8033 | .callback_data = &data, |
| 8034 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 8035 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8036 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8037 | |
| 8038 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8039 | clnt = clp->cl_rpcclient; |
| 8040 | task_setup.rpc_client = clnt; |
| 8041 | |
| 8042 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8043 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8044 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8045 | |
| 8046 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8047 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8048 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 8049 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 8050 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8051 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8052 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8053 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8054 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8055 | return status; |
| 8056 | } |
| 8057 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 8058 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 8059 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8060 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8061 | struct nfs4_exception exception = { |
| 8062 | .interruptible = true, |
| 8063 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8064 | int err; |
| 8065 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8066 | err = -NFS4ERR_WRONGSEC; |
| 8067 | |
| 8068 | /* try to use integrity protection with machine cred */ |
| 8069 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 8070 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 8071 | |
| 8072 | /* |
| 8073 | * if unable to use integrity protection, or SECINFO with |
| 8074 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8075 | * disallowed by spec, but exists in deployed servers) use |
| 8076 | * the current filesystem's rpc_client and the user cred. |
| 8077 | */ |
| 8078 | if (err == -NFS4ERR_WRONGSEC) |
| 8079 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 8080 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 8081 | trace_nfs4_secinfo(dir, name, err); |
| 8082 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8083 | &exception); |
| 8084 | } while (exception.retry); |
| 8085 | return err; |
| 8086 | } |
| 8087 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8088 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8089 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8090 | * Check the exchange flags returned by the server for invalid flags, having |
| 8091 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 8092 | * DS flags set. |
| 8093 | */ |
| 8094 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 8095 | { |
| 8096 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 8097 | goto out_inval; |
| 8098 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 8099 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 8100 | goto out_inval; |
| 8101 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 8102 | goto out_inval; |
| 8103 | return NFS_OK; |
| 8104 | out_inval: |
| 8105 | return -NFS4ERR_INVAL; |
| 8106 | } |
| 8107 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8108 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 8109 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 8110 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8111 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 8112 | if (a->server_scope_sz != b->server_scope_sz) |
| 8113 | return false; |
| 8114 | return memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8115 | } |
| 8116 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8117 | static void |
| 8118 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 8119 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8120 | struct nfs41_bind_conn_to_session_args *args = task->tk_msg.rpc_argp; |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8121 | struct nfs41_bind_conn_to_session_res *res = task->tk_msg.rpc_resp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8122 | struct nfs_client *clp = args->client; |
| 8123 | |
| 8124 | switch (task->tk_status) { |
| 8125 | case -NFS4ERR_BADSESSION: |
| 8126 | case -NFS4ERR_DEADSESSION: |
| 8127 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8128 | task->tk_status); |
| 8129 | } |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8130 | if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
| 8131 | res->dir != NFS4_CDFS4_BOTH) { |
| 8132 | rpc_task_close_connection(task); |
| 8133 | if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
| 8134 | rpc_restart_call(task); |
| 8135 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8136 | } |
| 8137 | |
| 8138 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
Olga Kornievskaia | 1c709b7 | 2020-04-26 11:30:00 -0400 | [diff] [blame] | 8139 | .rpc_call_done = nfs4_bind_one_conn_to_session_done, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8140 | }; |
| 8141 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8142 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8143 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8144 | * |
| 8145 | * The 4.1 client currently uses the same TCP connection for the |
| 8146 | * fore and backchannel. |
| 8147 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8148 | static |
| 8149 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 8150 | struct rpc_xprt *xprt, |
| 8151 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8152 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8153 | { |
| 8154 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8155 | struct nfs41_bind_conn_to_session_args args = { |
| 8156 | .client = clp, |
| 8157 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8158 | .retries = 0, |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8159 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8160 | struct nfs41_bind_conn_to_session_res res; |
| 8161 | struct rpc_message msg = { |
| 8162 | .rpc_proc = |
| 8163 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8164 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8165 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 8166 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8167 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8168 | struct rpc_task_setup task_setup_data = { |
| 8169 | .rpc_client = clnt, |
| 8170 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8171 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8172 | .rpc_message = &msg, |
| 8173 | .flags = RPC_TASK_TIMEOUT, |
| 8174 | }; |
| 8175 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8176 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8177 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 8178 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 8179 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8180 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8181 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 8182 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 8183 | args.dir = NFS4_CDFC4_FORE; |
| 8184 | |
| 8185 | task = rpc_run_task(&task_setup_data); |
| 8186 | if (!IS_ERR(task)) { |
| 8187 | status = task->tk_status; |
| 8188 | rpc_put_task(task); |
| 8189 | } else |
| 8190 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8191 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8192 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8193 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8194 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 8195 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8196 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8197 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8198 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8199 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 8200 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8201 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8202 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8203 | if (res.use_conn_in_rdma_mode != args.use_conn_in_rdma_mode) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8204 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 8205 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8206 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8207 | } |
| 8208 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8209 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8210 | return status; |
| 8211 | } |
| 8212 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8213 | struct rpc_bind_conn_calldata { |
| 8214 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8215 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8216 | }; |
| 8217 | |
| 8218 | static int |
| 8219 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 8220 | struct rpc_xprt *xprt, |
| 8221 | void *calldata) |
| 8222 | { |
| 8223 | struct rpc_bind_conn_calldata *p = calldata; |
| 8224 | |
| 8225 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 8226 | } |
| 8227 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8228 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, const struct cred *cred) |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8229 | { |
| 8230 | struct rpc_bind_conn_calldata data = { |
| 8231 | .clp = clp, |
| 8232 | .cred = cred, |
| 8233 | }; |
| 8234 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 8235 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 8236 | } |
| 8237 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8238 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8239 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 8240 | * and operations we'd like to see to enable certain features in the allow map |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8241 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8242 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 8243 | .how = SP4_MACH_CRED, |
| 8244 | .enforce.u.words = { |
| 8245 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8246 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8247 | 1 << (OP_CREATE_SESSION - 32) | |
| 8248 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8249 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8250 | }, |
| 8251 | .allow.u.words = { |
| 8252 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8253 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8254 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8255 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8256 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8257 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8258 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8259 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8260 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8261 | 1 << (OP_FREE_STATEID - 32) | |
| 8262 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8263 | } |
| 8264 | }; |
| 8265 | |
| 8266 | /* |
| 8267 | * Select the state protection mode for client `clp' given the server results |
| 8268 | * from exchange_id in `sp'. |
| 8269 | * |
| 8270 | * Returns 0 on success, negative errno otherwise. |
| 8271 | */ |
| 8272 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8273 | struct nfs41_state_protection *sp) |
| 8274 | { |
| 8275 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8276 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8277 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8278 | 1 << (OP_CREATE_SESSION - 32) | |
| 8279 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8280 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8281 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8282 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8283 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8284 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8285 | |
| 8286 | if (sp->how == SP4_MACH_CRED) { |
| 8287 | /* Print state protect result */ |
| 8288 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8289 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8290 | if (test_bit(i, sp->enforce.u.longs)) |
| 8291 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8292 | if (test_bit(i, sp->allow.u.longs)) |
| 8293 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8294 | } |
| 8295 | |
| 8296 | /* make sure nothing is on enforce list that isn't supported */ |
| 8297 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8298 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8299 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8300 | ret = -EINVAL; |
| 8301 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8302 | } |
| 8303 | } |
| 8304 | |
| 8305 | /* |
| 8306 | * Minimal mode - state operations are allowed to use machine |
| 8307 | * credential. Note this already happens by default, so the |
| 8308 | * client doesn't have to do anything more than the negotiation. |
| 8309 | * |
| 8310 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8311 | * we're already using the machine cred for exchange_id |
| 8312 | * and will never use a different cred. |
| 8313 | */ |
| 8314 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8315 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8316 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8317 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8318 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8319 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8320 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8321 | } else { |
| 8322 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8323 | ret = -EINVAL; |
| 8324 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8325 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8326 | |
| 8327 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8328 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8329 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8330 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8331 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8332 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8333 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8334 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8335 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8336 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8337 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8338 | } |
| 8339 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8340 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8341 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8342 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8343 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8344 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8345 | |
| 8346 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8347 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8348 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8349 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8350 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8351 | |
| 8352 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8353 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8354 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8355 | } |
| 8356 | |
| 8357 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8358 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8359 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8360 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8361 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8362 | out: |
| 8363 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8364 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8365 | } |
| 8366 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8367 | struct nfs41_exchange_id_data { |
| 8368 | struct nfs41_exchange_id_res res; |
| 8369 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8370 | }; |
| 8371 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8372 | static void nfs4_exchange_id_release(void *data) |
| 8373 | { |
| 8374 | struct nfs41_exchange_id_data *cdata = |
| 8375 | (struct nfs41_exchange_id_data *)data; |
| 8376 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8377 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8378 | kfree(cdata->res.impl_id); |
| 8379 | kfree(cdata->res.server_scope); |
| 8380 | kfree(cdata->res.server_owner); |
| 8381 | kfree(cdata); |
| 8382 | } |
| 8383 | |
| 8384 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8385 | .rpc_release = nfs4_exchange_id_release, |
| 8386 | }; |
| 8387 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8388 | /* |
| 8389 | * _nfs4_proc_exchange_id() |
| 8390 | * |
| 8391 | * Wrapper for EXCHANGE_ID operation. |
| 8392 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8393 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8394 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8395 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8396 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8397 | struct rpc_message msg = { |
| 8398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8399 | .rpc_cred = cred, |
| 8400 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8401 | struct rpc_task_setup task_setup_data = { |
| 8402 | .rpc_client = clp->cl_rpcclient, |
| 8403 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8404 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8405 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8406 | }; |
| 8407 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8408 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8409 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8410 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8411 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8412 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8413 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8414 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8415 | if (!calldata) |
| 8416 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8417 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8418 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8419 | |
| 8420 | status = nfs4_init_uniform_client_string(clp); |
| 8421 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8422 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8423 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8424 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8425 | GFP_NOFS); |
| 8426 | status = -ENOMEM; |
| 8427 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8428 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8429 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8430 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8431 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8432 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8433 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8434 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8435 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8436 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8437 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8438 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8439 | switch (sp4_how) { |
| 8440 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8441 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8442 | break; |
| 8443 | |
| 8444 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8445 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8446 | break; |
| 8447 | |
| 8448 | default: |
| 8449 | /* unsupported! */ |
| 8450 | WARN_ON_ONCE(1); |
| 8451 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8452 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8453 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8454 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8455 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8456 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8457 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8458 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8459 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8460 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8461 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8462 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8463 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8464 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8465 | #endif |
| 8466 | msg.rpc_argp = &calldata->args; |
| 8467 | msg.rpc_resp = &calldata->res; |
| 8468 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8469 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8470 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8471 | |
| 8472 | out_impl_id: |
| 8473 | kfree(calldata->res.impl_id); |
| 8474 | out_server_scope: |
| 8475 | kfree(calldata->res.server_scope); |
| 8476 | out_server_owner: |
| 8477 | kfree(calldata->res.server_owner); |
| 8478 | out_calldata: |
| 8479 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8480 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8481 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8482 | return ERR_PTR(status); |
| 8483 | } |
| 8484 | |
| 8485 | /* |
| 8486 | * _nfs4_proc_exchange_id() |
| 8487 | * |
| 8488 | * Wrapper for EXCHANGE_ID operation. |
| 8489 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8490 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8491 | u32 sp4_how) |
| 8492 | { |
| 8493 | struct rpc_task *task; |
| 8494 | struct nfs41_exchange_id_args *argp; |
| 8495 | struct nfs41_exchange_id_res *resp; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8496 | unsigned long now = jiffies; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8497 | int status; |
| 8498 | |
| 8499 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8500 | if (IS_ERR(task)) |
| 8501 | return PTR_ERR(task); |
| 8502 | |
| 8503 | argp = task->tk_msg.rpc_argp; |
| 8504 | resp = task->tk_msg.rpc_resp; |
| 8505 | status = task->tk_status; |
| 8506 | if (status != 0) |
| 8507 | goto out; |
| 8508 | |
| 8509 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 8510 | if (status != 0) |
| 8511 | goto out; |
| 8512 | |
| 8513 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8514 | if (status != 0) |
| 8515 | goto out; |
| 8516 | |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8517 | do_renew_lease(clp, now); |
| 8518 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8519 | clp->cl_clientid = resp->clientid; |
| 8520 | clp->cl_exchange_flags = resp->flags; |
| 8521 | clp->cl_seqid = resp->seqid; |
| 8522 | /* Client ID is not confirmed */ |
| 8523 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8524 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8525 | &clp->cl_session->session_state); |
| 8526 | |
| 8527 | if (clp->cl_serverscope != NULL && |
| 8528 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8529 | resp->server_scope)) { |
| 8530 | dprintk("%s: server_scope mismatch detected\n", |
| 8531 | __func__); |
| 8532 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8533 | } |
| 8534 | |
| 8535 | swap(clp->cl_serverowner, resp->server_owner); |
| 8536 | swap(clp->cl_serverscope, resp->server_scope); |
| 8537 | swap(clp->cl_implid, resp->impl_id); |
| 8538 | |
| 8539 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8540 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8541 | sizeof(clp->cl_confirm.data)); |
| 8542 | out: |
| 8543 | trace_nfs4_exchange_id(clp, status); |
| 8544 | rpc_put_task(task); |
| 8545 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8546 | } |
| 8547 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8548 | /* |
| 8549 | * nfs4_proc_exchange_id() |
| 8550 | * |
| 8551 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8552 | * |
| 8553 | * Since the clientid has expired, all compounds using sessions |
| 8554 | * associated with the stale clientid will be returning |
| 8555 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8556 | * be in some phase of session reset. |
| 8557 | * |
| 8558 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8559 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8560 | int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8561 | { |
| 8562 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8563 | int status; |
| 8564 | |
| 8565 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8566 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8567 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8568 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8569 | if (!status) |
| 8570 | return 0; |
| 8571 | } |
| 8572 | |
| 8573 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8574 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8575 | } |
| 8576 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8577 | /** |
| 8578 | * nfs4_test_session_trunk |
| 8579 | * |
| 8580 | * This is an add_xprt_test() test function called from |
| 8581 | * rpc_clnt_setup_test_and_add_xprt. |
| 8582 | * |
| 8583 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8584 | * and is dereferrenced in nfs4_exchange_id_release |
| 8585 | * |
| 8586 | * Upon success, add the new transport to the rpc_clnt |
| 8587 | * |
| 8588 | * @clnt: struct rpc_clnt to get new transport |
| 8589 | * @xprt: the rpc_xprt to test |
| 8590 | * @data: call data for _nfs4_proc_exchange_id. |
| 8591 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8592 | void nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8593 | void *data) |
| 8594 | { |
| 8595 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8596 | struct rpc_task *task; |
| 8597 | int status; |
| 8598 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8599 | u32 sp4_how; |
| 8600 | |
| 8601 | dprintk("--> %s try %s\n", __func__, |
| 8602 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8603 | |
| 8604 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8605 | |
| 8606 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8607 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8608 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8609 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8610 | |
| 8611 | status = task->tk_status; |
| 8612 | if (status == 0) |
| 8613 | status = nfs4_detect_session_trunking(adata->clp, |
| 8614 | task->tk_msg.rpc_resp, xprt); |
| 8615 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8616 | if (status == 0) |
| 8617 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8618 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8619 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8620 | } |
| 8621 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8622 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8623 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8624 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8625 | { |
| 8626 | struct rpc_message msg = { |
| 8627 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8628 | .rpc_argp = clp, |
| 8629 | .rpc_cred = cred, |
| 8630 | }; |
| 8631 | int status; |
| 8632 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8633 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8634 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8635 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8636 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8637 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8638 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8639 | return status; |
| 8640 | } |
| 8641 | |
| 8642 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8643 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8644 | { |
| 8645 | unsigned int loop; |
| 8646 | int ret; |
| 8647 | |
| 8648 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8649 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8650 | switch (ret) { |
| 8651 | case -NFS4ERR_DELAY: |
| 8652 | case -NFS4ERR_CLIENTID_BUSY: |
| 8653 | ssleep(1); |
| 8654 | break; |
| 8655 | default: |
| 8656 | return ret; |
| 8657 | } |
| 8658 | } |
| 8659 | return 0; |
| 8660 | } |
| 8661 | |
| 8662 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8663 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8664 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8665 | int ret = 0; |
| 8666 | |
| 8667 | if (clp->cl_mvops->minor_version < 1) |
| 8668 | goto out; |
| 8669 | if (clp->cl_exchange_flags == 0) |
| 8670 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8671 | if (clp->cl_preserve_clid) |
| 8672 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8673 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8674 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8675 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8676 | switch (ret) { |
| 8677 | case 0: |
| 8678 | case -NFS4ERR_STALE_CLIENTID: |
| 8679 | clp->cl_exchange_flags = 0; |
| 8680 | } |
| 8681 | out: |
| 8682 | return ret; |
| 8683 | } |
| 8684 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8685 | #endif /* CONFIG_NFS_V4_1 */ |
| 8686 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8687 | struct nfs4_get_lease_time_data { |
| 8688 | struct nfs4_get_lease_time_args *args; |
| 8689 | struct nfs4_get_lease_time_res *res; |
| 8690 | struct nfs_client *clp; |
| 8691 | }; |
| 8692 | |
| 8693 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8694 | void *calldata) |
| 8695 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8696 | struct nfs4_get_lease_time_data *data = |
| 8697 | (struct nfs4_get_lease_time_data *)calldata; |
| 8698 | |
| 8699 | dprintk("--> %s\n", __func__); |
| 8700 | /* just setup sequence, do not trigger session recovery |
| 8701 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8702 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8703 | &data->args->la_seq_args, |
| 8704 | &data->res->lr_seq_res, |
| 8705 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8706 | dprintk("<-- %s\n", __func__); |
| 8707 | } |
| 8708 | |
| 8709 | /* |
| 8710 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8711 | * from sequence operation or clientid errors. |
| 8712 | */ |
| 8713 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8714 | { |
| 8715 | struct nfs4_get_lease_time_data *data = |
| 8716 | (struct nfs4_get_lease_time_data *)calldata; |
| 8717 | |
| 8718 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8719 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8720 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8721 | switch (task->tk_status) { |
| 8722 | case -NFS4ERR_DELAY: |
| 8723 | case -NFS4ERR_GRACE: |
| 8724 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8725 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8726 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 8727 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8728 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8729 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8730 | return; |
| 8731 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8732 | dprintk("<-- %s\n", __func__); |
| 8733 | } |
| 8734 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8735 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8736 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8737 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8738 | }; |
| 8739 | |
| 8740 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8741 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8742 | struct nfs4_get_lease_time_args args; |
| 8743 | struct nfs4_get_lease_time_res res = { |
| 8744 | .lr_fsinfo = fsinfo, |
| 8745 | }; |
| 8746 | struct nfs4_get_lease_time_data data = { |
| 8747 | .args = &args, |
| 8748 | .res = &res, |
| 8749 | .clp = clp, |
| 8750 | }; |
| 8751 | struct rpc_message msg = { |
| 8752 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8753 | .rpc_argp = &args, |
| 8754 | .rpc_resp = &res, |
| 8755 | }; |
| 8756 | struct rpc_task_setup task_setup = { |
| 8757 | .rpc_client = clp->cl_rpcclient, |
| 8758 | .rpc_message = &msg, |
| 8759 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8760 | .callback_data = &data, |
| 8761 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8762 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8763 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8764 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); |
Anna Schumaker | f836b27 | 2019-08-19 10:18:28 -0400 | [diff] [blame] | 8765 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8766 | } |
| 8767 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8768 | #ifdef CONFIG_NFS_V4_1 |
| 8769 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8770 | /* |
| 8771 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8772 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8773 | * use them. |
| 8774 | * |
| 8775 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8776 | * always set csa_cachethis to FALSE because the current implementation |
| 8777 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8778 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8779 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8780 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8781 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8782 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8783 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8784 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8785 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8786 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8787 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8788 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8789 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8790 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8791 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8792 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8793 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8794 | |
| 8795 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8796 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8797 | __func__, |
| 8798 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8799 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8800 | |
| 8801 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8802 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8803 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8804 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8805 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8806 | args->bc_attrs.max_reqs = max_t(unsigned short, max_session_cb_slots, 1); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8807 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8808 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8809 | |
| 8810 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8811 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8812 | __func__, |
| 8813 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8814 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8815 | args->bc_attrs.max_reqs); |
| 8816 | } |
| 8817 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8818 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8819 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8820 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8821 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8822 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8823 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8824 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8825 | return -EINVAL; |
| 8826 | /* |
| 8827 | * Our requested max_ops is the minimum we need; we're not |
| 8828 | * prepared to break up compounds into smaller pieces than that. |
| 8829 | * So, no point even trying to continue if the server won't |
| 8830 | * cooperate: |
| 8831 | */ |
| 8832 | if (rcvd->max_ops < sent->max_ops) |
| 8833 | return -EINVAL; |
| 8834 | if (rcvd->max_reqs == 0) |
| 8835 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8836 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8837 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8838 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8839 | } |
| 8840 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8841 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8842 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8843 | { |
| 8844 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8845 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8846 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8847 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8848 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8849 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8850 | return -EINVAL; |
| 8851 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8852 | return -EINVAL; |
| 8853 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8854 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8855 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8856 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8857 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8858 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8859 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8860 | return 0; |
| 8861 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8862 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8863 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8864 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8865 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8866 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8867 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8868 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8869 | if (ret) |
| 8870 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8871 | return nfs4_verify_back_channel_attrs(args, res); |
| 8872 | } |
| 8873 | |
| 8874 | static void nfs4_update_session(struct nfs4_session *session, |
| 8875 | struct nfs41_create_session_res *res) |
| 8876 | { |
| 8877 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8878 | /* Mark client id and session as being confirmed */ |
| 8879 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8880 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8881 | session->flags = res->flags; |
| 8882 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8883 | if (res->flags & SESSION4_BACK_CHAN) |
| 8884 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8885 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8886 | } |
| 8887 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8888 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8889 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8890 | { |
| 8891 | struct nfs4_session *session = clp->cl_session; |
| 8892 | struct nfs41_create_session_args args = { |
| 8893 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8894 | .clientid = clp->cl_clientid, |
| 8895 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8896 | .cb_program = NFS4_CALLBACK, |
| 8897 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8898 | struct nfs41_create_session_res res; |
| 8899 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8900 | struct rpc_message msg = { |
| 8901 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8902 | .rpc_argp = &args, |
| 8903 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8904 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8905 | }; |
| 8906 | int status; |
| 8907 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8908 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8909 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8910 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8911 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8912 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8913 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8914 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8915 | switch (status) { |
| 8916 | case -NFS4ERR_STALE_CLIENTID: |
| 8917 | case -NFS4ERR_DELAY: |
| 8918 | case -ETIMEDOUT: |
| 8919 | case -EACCES: |
| 8920 | case -EAGAIN: |
| 8921 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 8922 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8923 | |
| 8924 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8925 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8926 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8927 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8928 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8929 | if (status) |
| 8930 | goto out; |
| 8931 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8932 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8933 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8934 | return status; |
| 8935 | } |
| 8936 | |
| 8937 | /* |
| 8938 | * Issues a CREATE_SESSION operation to the server. |
| 8939 | * It is the responsibility of the caller to verify the session is |
| 8940 | * expired before calling this routine. |
| 8941 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8942 | int nfs4_proc_create_session(struct nfs_client *clp, const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8943 | { |
| 8944 | int status; |
| 8945 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8946 | struct nfs4_session *session = clp->cl_session; |
| 8947 | |
| 8948 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8949 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8950 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8951 | if (status) |
| 8952 | goto out; |
| 8953 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8954 | /* Init or reset the session slot tables */ |
| 8955 | status = nfs4_setup_session_slot_tables(session); |
| 8956 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8957 | if (status) |
| 8958 | goto out; |
| 8959 | |
| 8960 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8961 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8962 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8963 | out: |
| 8964 | dprintk("<-- %s\n", __func__); |
| 8965 | return status; |
| 8966 | } |
| 8967 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8968 | /* |
| 8969 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8970 | * The caller must serialize access to this routine. |
| 8971 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8972 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8973 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8974 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8975 | struct rpc_message msg = { |
| 8976 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8977 | .rpc_argp = session, |
| 8978 | .rpc_cred = cred, |
| 8979 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8980 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8981 | |
| 8982 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8983 | |
| 8984 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8985 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8986 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8987 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8988 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8989 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8990 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8991 | |
| 8992 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8993 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8994 | "Session has been destroyed regardless...\n", status); |
| 8995 | |
| 8996 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8997 | return status; |
| 8998 | } |
| 8999 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 9000 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9001 | * Renew the cl_session lease. |
| 9002 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9003 | struct nfs4_sequence_data { |
| 9004 | struct nfs_client *clp; |
| 9005 | struct nfs4_sequence_args args; |
| 9006 | struct nfs4_sequence_res res; |
| 9007 | }; |
| 9008 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9009 | static void nfs41_sequence_release(void *data) |
| 9010 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9011 | struct nfs4_sequence_data *calldata = data; |
| 9012 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9013 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9014 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9015 | nfs4_schedule_state_renewal(clp); |
| 9016 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9017 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9018 | } |
| 9019 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9020 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9021 | { |
| 9022 | switch(task->tk_status) { |
| 9023 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9024 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 9025 | return -EAGAIN; |
| 9026 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9027 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9028 | } |
| 9029 | return 0; |
| 9030 | } |
| 9031 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9032 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9033 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9034 | struct nfs4_sequence_data *calldata = data; |
| 9035 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9036 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9037 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 9038 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9039 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9040 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9041 | if (task->tk_status < 0) { |
| 9042 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9043 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9044 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9045 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9046 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 9047 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9048 | return; |
| 9049 | } |
| 9050 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9051 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9052 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9053 | dprintk("<-- %s\n", __func__); |
| 9054 | } |
| 9055 | |
| 9056 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 9057 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9058 | struct nfs4_sequence_data *calldata = data; |
| 9059 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9060 | struct nfs4_sequence_args *args; |
| 9061 | struct nfs4_sequence_res *res; |
| 9062 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9063 | args = task->tk_msg.rpc_argp; |
| 9064 | res = task->tk_msg.rpc_resp; |
| 9065 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9066 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9067 | } |
| 9068 | |
| 9069 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 9070 | .rpc_call_done = nfs41_sequence_call_done, |
| 9071 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9072 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9073 | }; |
| 9074 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9075 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9076 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9077 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9078 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9079 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9080 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9081 | struct rpc_message msg = { |
| 9082 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 9083 | .rpc_cred = cred, |
| 9084 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9085 | struct rpc_task_setup task_setup_data = { |
| 9086 | .rpc_client = clp->cl_rpcclient, |
| 9087 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9088 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 9089 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9090 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9091 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9092 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9093 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9094 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9095 | goto out_err; |
| 9096 | |
| 9097 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 9098 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9099 | if (calldata == NULL) |
| 9100 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9101 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9102 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9103 | msg.rpc_argp = &calldata->args; |
| 9104 | msg.rpc_resp = &calldata->res; |
| 9105 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9106 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9107 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9108 | ret = rpc_run_task(&task_setup_data); |
| 9109 | if (IS_ERR(ret)) |
| 9110 | goto out_err; |
| 9111 | return ret; |
| 9112 | out_put_clp: |
| 9113 | nfs_put_client(clp); |
| 9114 | out_err: |
| 9115 | nfs41_release_slot(slot); |
| 9116 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9117 | } |
| 9118 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9119 | static int nfs41_proc_async_sequence(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9120 | { |
| 9121 | struct rpc_task *task; |
| 9122 | int ret = 0; |
| 9123 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 9124 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 9125 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9126 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9127 | if (IS_ERR(task)) |
| 9128 | ret = PTR_ERR(task); |
| 9129 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 9130 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9131 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9132 | return ret; |
| 9133 | } |
| 9134 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9135 | static int nfs4_proc_sequence(struct nfs_client *clp, const struct cred *cred) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9136 | { |
| 9137 | struct rpc_task *task; |
| 9138 | int ret; |
| 9139 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9140 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9141 | if (IS_ERR(task)) { |
| 9142 | ret = PTR_ERR(task); |
| 9143 | goto out; |
| 9144 | } |
| 9145 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 9146 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9147 | ret = task->tk_status; |
| 9148 | rpc_put_task(task); |
| 9149 | out: |
| 9150 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9151 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9152 | } |
| 9153 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9154 | struct nfs4_reclaim_complete_data { |
| 9155 | struct nfs_client *clp; |
| 9156 | struct nfs41_reclaim_complete_args arg; |
| 9157 | struct nfs41_reclaim_complete_res res; |
| 9158 | }; |
| 9159 | |
| 9160 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 9161 | { |
| 9162 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9163 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9164 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9165 | &calldata->arg.seq_args, |
| 9166 | &calldata->res.seq_res, |
| 9167 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9168 | } |
| 9169 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9170 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9171 | { |
| 9172 | switch(task->tk_status) { |
| 9173 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 9174 | wake_up_all(&clp->cl_lock_waitq); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9175 | fallthrough; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9176 | case -NFS4ERR_COMPLETE_ALREADY: |
| 9177 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 9178 | break; |
| 9179 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9180 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9181 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 9182 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9183 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9184 | case -NFS4ERR_BADSESSION: |
| 9185 | case -NFS4ERR_DEADSESSION: |
| 9186 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9187 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9188 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9189 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9190 | } |
| 9191 | return 0; |
| 9192 | } |
| 9193 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9194 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 9195 | { |
| 9196 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9197 | struct nfs_client *clp = calldata->clp; |
| 9198 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 9199 | |
| 9200 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9201 | if (!nfs41_sequence_done(task, res)) |
| 9202 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9203 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9204 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9205 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 9206 | rpc_restart_call_prepare(task); |
| 9207 | return; |
| 9208 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9209 | dprintk("<-- %s\n", __func__); |
| 9210 | } |
| 9211 | |
| 9212 | static void nfs4_free_reclaim_complete_data(void *data) |
| 9213 | { |
| 9214 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9215 | |
| 9216 | kfree(calldata); |
| 9217 | } |
| 9218 | |
| 9219 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 9220 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 9221 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 9222 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 9223 | }; |
| 9224 | |
| 9225 | /* |
| 9226 | * Issue a global reclaim complete. |
| 9227 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9228 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9229 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9230 | { |
| 9231 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9232 | struct rpc_message msg = { |
| 9233 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9234 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9235 | }; |
| 9236 | struct rpc_task_setup task_setup_data = { |
| 9237 | .rpc_client = clp->cl_rpcclient, |
| 9238 | .rpc_message = &msg, |
| 9239 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9240 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9241 | }; |
| 9242 | int status = -ENOMEM; |
| 9243 | |
| 9244 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 9245 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9246 | if (calldata == NULL) |
| 9247 | goto out; |
| 9248 | calldata->clp = clp; |
| 9249 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9250 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9251 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0, 1); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9252 | msg.rpc_argp = &calldata->arg; |
| 9253 | msg.rpc_resp = &calldata->res; |
| 9254 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9255 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9256 | out: |
| 9257 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9258 | return status; |
| 9259 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9260 | |
| 9261 | static void |
| 9262 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9263 | { |
| 9264 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9265 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9266 | |
| 9267 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9268 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9269 | &lgp->res.seq_res, task); |
| 9270 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9271 | } |
| 9272 | |
| 9273 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9274 | { |
| 9275 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9276 | |
| 9277 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9278 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9279 | dprintk("<-- %s\n", __func__); |
| 9280 | } |
| 9281 | |
| 9282 | static int |
| 9283 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9284 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9285 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9286 | struct inode *inode = lgp->args.inode; |
| 9287 | struct nfs_server *server = NFS_SERVER(inode); |
| 9288 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9289 | int nfs4err = task->tk_status; |
| 9290 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9291 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9292 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9293 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9294 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9295 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9296 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9297 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9298 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9299 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9300 | |
| 9301 | /* |
| 9302 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9303 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9304 | * retry go inband. |
| 9305 | */ |
| 9306 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9307 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9308 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9309 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9310 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9311 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9312 | */ |
| 9313 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9314 | status = -EOVERFLOW; |
| 9315 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9316 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9317 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9318 | * (or clients) writing to the same RAID stripe except when |
| 9319 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9320 | * |
| 9321 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9322 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9323 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9324 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9325 | if (lgp->args.minlength == 0) { |
| 9326 | status = -EOVERFLOW; |
| 9327 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9328 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9329 | status = -EBUSY; |
| 9330 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9331 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9332 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9333 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9334 | case -NFS4ERR_DELEG_REVOKED: |
| 9335 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9336 | case -NFS4ERR_EXPIRED: |
| 9337 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9338 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9339 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9340 | lo = NFS_I(inode)->layout; |
| 9341 | /* If the open stateid was bad, then recover it. */ |
| 9342 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9343 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9344 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9345 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9346 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9347 | break; |
| 9348 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9349 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9350 | /* |
| 9351 | * Mark the bad layout state as invalid, then retry |
| 9352 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9353 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9354 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9355 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9356 | pnfs_free_lseg_list(&head); |
| 9357 | status = -EAGAIN; |
| 9358 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9359 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9360 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9361 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9362 | if (!status) { |
| 9363 | if (exception->retry) |
| 9364 | status = -EAGAIN; |
| 9365 | else |
| 9366 | status = err; |
| 9367 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9368 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9369 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9370 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9371 | } |
| 9372 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9373 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9374 | { |
| 9375 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9376 | return nfs_page_array_len(0, max_resp_sz); |
| 9377 | } |
| 9378 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9379 | static void nfs4_layoutget_release(void *calldata) |
| 9380 | { |
| 9381 | struct nfs4_layoutget *lgp = calldata; |
| 9382 | |
| 9383 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9384 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9385 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9386 | dprintk("<-- %s\n", __func__); |
| 9387 | } |
| 9388 | |
| 9389 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9390 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9391 | .rpc_call_done = nfs4_layoutget_done, |
| 9392 | .rpc_release = nfs4_layoutget_release, |
| 9393 | }; |
| 9394 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9395 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9396 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9397 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9398 | struct inode *inode = lgp->args.inode; |
| 9399 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9400 | struct rpc_task *task; |
| 9401 | struct rpc_message msg = { |
| 9402 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9403 | .rpc_argp = &lgp->args, |
| 9404 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9405 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9406 | }; |
| 9407 | struct rpc_task_setup task_setup_data = { |
| 9408 | .rpc_client = server->client, |
| 9409 | .rpc_message = &msg, |
| 9410 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9411 | .callback_data = lgp, |
Trond Myklebust | 63ec2b6 | 2020-02-07 19:40:14 -0500 | [diff] [blame] | 9412 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9413 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9414 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9415 | struct nfs4_exception exception = { |
| 9416 | .inode = inode, |
| 9417 | .timeout = *timeout, |
| 9418 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9419 | int status = 0; |
| 9420 | |
| 9421 | dprintk("--> %s\n", __func__); |
| 9422 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9423 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9424 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9425 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9426 | nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9427 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9428 | task = rpc_run_task(&task_setup_data); |
Xiyu Yang | 6e47666 | 2020-04-25 21:04:40 +0800 | [diff] [blame] | 9429 | |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9430 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9431 | if (status != 0) |
| 9432 | goto out; |
| 9433 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9434 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9435 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9436 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9437 | } else if (lgp->res.layoutp->len == 0) { |
| 9438 | status = -EAGAIN; |
| 9439 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9440 | } else |
| 9441 | lseg = pnfs_layout_process(lgp); |
| 9442 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9443 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9444 | &lgp->args.range, |
| 9445 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9446 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9447 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9448 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9449 | rpc_put_task(task); |
| 9450 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9451 | if (status) |
| 9452 | return ERR_PTR(status); |
| 9453 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9454 | } |
| 9455 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9456 | static void |
| 9457 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9458 | { |
| 9459 | struct nfs4_layoutreturn *lrp = calldata; |
| 9460 | |
| 9461 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9462 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9463 | &lrp->args.seq_args, |
| 9464 | &lrp->res.seq_res, |
| 9465 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9466 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9467 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9468 | } |
| 9469 | |
| 9470 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9471 | { |
| 9472 | struct nfs4_layoutreturn *lrp = calldata; |
| 9473 | struct nfs_server *server; |
| 9474 | |
| 9475 | dprintk("--> %s\n", __func__); |
| 9476 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9477 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9478 | return; |
| 9479 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9480 | /* |
| 9481 | * Was there an RPC level error? Assume the call succeeded, |
| 9482 | * and that we need to release the layout |
| 9483 | */ |
| 9484 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9485 | lrp->res.lrs_present = 0; |
| 9486 | return; |
| 9487 | } |
| 9488 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9489 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9490 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9491 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9492 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9493 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9494 | lrp->args.inode)) |
| 9495 | goto out_restart; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9496 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9497 | default: |
| 9498 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9499 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9500 | case 0: |
| 9501 | break; |
| 9502 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9503 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9504 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9505 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9506 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9507 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9508 | return; |
| 9509 | out_restart: |
| 9510 | task->tk_status = 0; |
| 9511 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9512 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9513 | } |
| 9514 | |
| 9515 | static void nfs4_layoutreturn_release(void *calldata) |
| 9516 | { |
| 9517 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9518 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9519 | |
| 9520 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9521 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9522 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9523 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9524 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9525 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9526 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9527 | nfs_iput_and_deactive(lrp->inode); |
Trond Myklebust | 44ea8df | 2020-04-02 15:37:02 -0400 | [diff] [blame] | 9528 | put_cred(lrp->cred); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9529 | kfree(calldata); |
| 9530 | dprintk("<-- %s\n", __func__); |
| 9531 | } |
| 9532 | |
| 9533 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9534 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9535 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9536 | .rpc_release = nfs4_layoutreturn_release, |
| 9537 | }; |
| 9538 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9539 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9540 | { |
| 9541 | struct rpc_task *task; |
| 9542 | struct rpc_message msg = { |
| 9543 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9544 | .rpc_argp = &lrp->args, |
| 9545 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9546 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9547 | }; |
| 9548 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9549 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9550 | .rpc_message = &msg, |
| 9551 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9552 | .callback_data = lrp, |
| 9553 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9554 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9555 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9556 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9557 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9558 | &task_setup_data.rpc_client, &msg); |
| 9559 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9560 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9561 | if (!sync) { |
| 9562 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9563 | if (!lrp->inode) { |
| 9564 | nfs4_layoutreturn_release(lrp); |
| 9565 | return -EAGAIN; |
| 9566 | } |
| 9567 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9568 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9569 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9570 | task = rpc_run_task(&task_setup_data); |
| 9571 | if (IS_ERR(task)) |
| 9572 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9573 | if (sync) |
| 9574 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9575 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9576 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9577 | rpc_put_task(task); |
| 9578 | return status; |
| 9579 | } |
| 9580 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9581 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9582 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9583 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9584 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9585 | { |
| 9586 | struct nfs4_getdeviceinfo_args args = { |
| 9587 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9588 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9589 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9590 | }; |
| 9591 | struct nfs4_getdeviceinfo_res res = { |
| 9592 | .pdev = pdev, |
| 9593 | }; |
| 9594 | struct rpc_message msg = { |
| 9595 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9596 | .rpc_argp = &args, |
| 9597 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9598 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9599 | }; |
| 9600 | int status; |
| 9601 | |
| 9602 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9603 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9604 | if (res.notification & ~args.notify_types) |
| 9605 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9606 | if (res.notification != args.notify_types) |
| 9607 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9608 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9609 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9610 | |
| 9611 | return status; |
| 9612 | } |
| 9613 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9614 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9615 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9616 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9617 | { |
| 9618 | struct nfs4_exception exception = { }; |
| 9619 | int err; |
| 9620 | |
| 9621 | do { |
| 9622 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9623 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9624 | &exception); |
| 9625 | } while (exception.retry); |
| 9626 | return err; |
| 9627 | } |
| 9628 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9629 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9630 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9631 | { |
| 9632 | struct nfs4_layoutcommit_data *data = calldata; |
| 9633 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9634 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9635 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9636 | &data->args.seq_args, |
| 9637 | &data->res.seq_res, |
| 9638 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9639 | } |
| 9640 | |
| 9641 | static void |
| 9642 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9643 | { |
| 9644 | struct nfs4_layoutcommit_data *data = calldata; |
| 9645 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9646 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9647 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9648 | return; |
| 9649 | |
| 9650 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9651 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9652 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9653 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9654 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9655 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9656 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9657 | break; |
| 9658 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9659 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9660 | rpc_restart_call_prepare(task); |
| 9661 | return; |
| 9662 | } |
| 9663 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9664 | } |
| 9665 | |
| 9666 | static void nfs4_layoutcommit_release(void *calldata) |
| 9667 | { |
| 9668 | struct nfs4_layoutcommit_data *data = calldata; |
| 9669 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9670 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9671 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9672 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9673 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9674 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9675 | kfree(data); |
| 9676 | } |
| 9677 | |
| 9678 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9679 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9680 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9681 | .rpc_release = nfs4_layoutcommit_release, |
| 9682 | }; |
| 9683 | |
| 9684 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9685 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9686 | { |
| 9687 | struct rpc_message msg = { |
| 9688 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9689 | .rpc_argp = &data->args, |
| 9690 | .rpc_resp = &data->res, |
| 9691 | .rpc_cred = data->cred, |
| 9692 | }; |
| 9693 | struct rpc_task_setup task_setup_data = { |
| 9694 | .task = &data->task, |
| 9695 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9696 | .rpc_message = &msg, |
| 9697 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9698 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9699 | }; |
| 9700 | struct rpc_task *task; |
| 9701 | int status = 0; |
| 9702 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9703 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9704 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9705 | data->args.lastbytewritten, |
| 9706 | data->args.inode->i_ino); |
| 9707 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9708 | if (!sync) { |
| 9709 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9710 | if (data->inode == NULL) { |
| 9711 | nfs4_layoutcommit_release(data); |
| 9712 | return -EAGAIN; |
| 9713 | } |
| 9714 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9715 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9716 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9717 | task = rpc_run_task(&task_setup_data); |
| 9718 | if (IS_ERR(task)) |
| 9719 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9720 | if (sync) |
| 9721 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9722 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9723 | dprintk("%s: status %d\n", __func__, status); |
| 9724 | rpc_put_task(task); |
| 9725 | return status; |
| 9726 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9727 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9728 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9729 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9730 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9731 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9732 | static int |
| 9733 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9734 | struct nfs_fsinfo *info, |
| 9735 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9736 | { |
| 9737 | struct nfs41_secinfo_no_name_args args = { |
| 9738 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9739 | }; |
| 9740 | struct nfs4_secinfo_res res = { |
| 9741 | .flavors = flavors, |
| 9742 | }; |
| 9743 | struct rpc_message msg = { |
| 9744 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9745 | .rpc_argp = &args, |
| 9746 | .rpc_resp = &res, |
| 9747 | }; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9748 | struct nfs4_call_sync_data data = { |
| 9749 | .seq_server = server, |
| 9750 | .seq_args = &args.seq_args, |
| 9751 | .seq_res = &res.seq_res, |
| 9752 | }; |
| 9753 | struct rpc_task_setup task_setup = { |
| 9754 | .rpc_client = server->client, |
| 9755 | .rpc_message = &msg, |
| 9756 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9757 | .callback_data = &data, |
| 9758 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9759 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9760 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9761 | int status; |
| 9762 | |
| 9763 | if (use_integrity) { |
Colin Ian King | 48bb6ec | 2020-06-10 00:22:57 +0100 | [diff] [blame] | 9764 | task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9765 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9766 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9767 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9768 | } |
| 9769 | |
| 9770 | dprintk("--> %s\n", __func__); |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9771 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9772 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9773 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9774 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9775 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9776 | |
| 9777 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9778 | } |
| 9779 | |
| 9780 | static int |
| 9781 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9782 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9783 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9784 | struct nfs4_exception exception = { |
| 9785 | .interruptible = true, |
| 9786 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9787 | int err; |
| 9788 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9789 | /* first try using integrity protection */ |
| 9790 | err = -NFS4ERR_WRONGSEC; |
| 9791 | |
| 9792 | /* try to use integrity protection with machine cred */ |
| 9793 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9794 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9795 | flavors, true); |
| 9796 | |
| 9797 | /* |
| 9798 | * if unable to use integrity protection, or SECINFO with |
| 9799 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9800 | * disallowed by spec, but exists in deployed servers) use |
| 9801 | * the current filesystem's rpc_client and the user cred. |
| 9802 | */ |
| 9803 | if (err == -NFS4ERR_WRONGSEC) |
| 9804 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9805 | flavors, false); |
| 9806 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9807 | switch (err) { |
| 9808 | case 0: |
| 9809 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9810 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9811 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9812 | default: |
| 9813 | err = nfs4_handle_exception(server, err, &exception); |
| 9814 | } |
| 9815 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9816 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9817 | return err; |
| 9818 | } |
| 9819 | |
| 9820 | static int |
| 9821 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9822 | struct nfs_fsinfo *info) |
| 9823 | { |
| 9824 | int err; |
| 9825 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9826 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9827 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9828 | struct nfs4_secinfo4 *secinfo; |
| 9829 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9830 | |
| 9831 | page = alloc_page(GFP_KERNEL); |
| 9832 | if (!page) { |
| 9833 | err = -ENOMEM; |
| 9834 | goto out; |
| 9835 | } |
| 9836 | |
| 9837 | flavors = page_address(page); |
| 9838 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9839 | |
| 9840 | /* |
| 9841 | * Fall back on "guess and check" method if |
| 9842 | * the server doesn't support SECINFO_NO_NAME |
| 9843 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9844 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9845 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9846 | goto out_freepage; |
| 9847 | } |
| 9848 | if (err) |
| 9849 | goto out_freepage; |
| 9850 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9851 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9852 | secinfo = &flavors->flavors[i]; |
| 9853 | |
| 9854 | switch (secinfo->flavor) { |
| 9855 | case RPC_AUTH_NULL: |
| 9856 | case RPC_AUTH_UNIX: |
| 9857 | case RPC_AUTH_GSS: |
| 9858 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9859 | &secinfo->flavor_info); |
| 9860 | break; |
| 9861 | default: |
| 9862 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9863 | break; |
| 9864 | } |
| 9865 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9866 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9867 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9868 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9869 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9870 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9871 | info, flavor); |
| 9872 | if (!err) |
| 9873 | break; |
| 9874 | } |
| 9875 | } |
| 9876 | |
| 9877 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9878 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9879 | |
| 9880 | out_freepage: |
| 9881 | put_page(page); |
| 9882 | if (err == -EACCES) |
| 9883 | return -EPERM; |
| 9884 | out: |
| 9885 | return err; |
| 9886 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9887 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9888 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9889 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9890 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9891 | { |
| 9892 | int status; |
| 9893 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9894 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9895 | }; |
| 9896 | struct nfs41_test_stateid_res res; |
| 9897 | struct rpc_message msg = { |
| 9898 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9899 | .rpc_argp = &args, |
| 9900 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9901 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9902 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9903 | struct rpc_clnt *rpc_client = server->client; |
| 9904 | |
| 9905 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9906 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9907 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9908 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9909 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9910 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9911 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9912 | if (status != NFS_OK) { |
| 9913 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9914 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9915 | } |
| 9916 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9917 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9918 | } |
| 9919 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9920 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9921 | int err, struct nfs4_exception *exception) |
| 9922 | { |
| 9923 | exception->retry = 0; |
| 9924 | switch(err) { |
| 9925 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9926 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9927 | nfs4_handle_exception(server, err, exception); |
| 9928 | break; |
| 9929 | case -NFS4ERR_BADSESSION: |
| 9930 | case -NFS4ERR_BADSLOT: |
| 9931 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9932 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9933 | case -NFS4ERR_DEADSESSION: |
| 9934 | nfs4_do_handle_exception(server, err, exception); |
| 9935 | } |
| 9936 | } |
| 9937 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9938 | /** |
| 9939 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9940 | * |
| 9941 | * @server: server / transport on which to perform the operation |
| 9942 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9943 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9944 | * |
| 9945 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9946 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9947 | * failed or the state ID is not currently valid. |
| 9948 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9949 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9950 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9951 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9952 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9953 | struct nfs4_exception exception = { |
| 9954 | .interruptible = true, |
| 9955 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9956 | int err; |
| 9957 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9958 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9959 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9960 | } while (exception.retry); |
| 9961 | return err; |
| 9962 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9963 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9964 | struct nfs_free_stateid_data { |
| 9965 | struct nfs_server *server; |
| 9966 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9967 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9968 | }; |
| 9969 | |
| 9970 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9971 | { |
| 9972 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9973 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9974 | &data->args.seq_args, |
| 9975 | &data->res.seq_res, |
| 9976 | task); |
| 9977 | } |
| 9978 | |
| 9979 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9980 | { |
| 9981 | struct nfs_free_stateid_data *data = calldata; |
| 9982 | |
| 9983 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9984 | |
| 9985 | switch (task->tk_status) { |
| 9986 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9987 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9988 | rpc_restart_call_prepare(task); |
| 9989 | } |
| 9990 | } |
| 9991 | |
| 9992 | static void nfs41_free_stateid_release(void *calldata) |
| 9993 | { |
| 9994 | kfree(calldata); |
| 9995 | } |
| 9996 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9997 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9998 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9999 | .rpc_call_done = nfs41_free_stateid_done, |
| 10000 | .rpc_release = nfs41_free_stateid_release, |
| 10001 | }; |
| 10002 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10003 | /** |
| 10004 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 10005 | * |
| 10006 | * @server: server / transport on which to perform the operation |
| 10007 | * @stateid: state ID to release |
| 10008 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 10009 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10010 | * |
| 10011 | * Note: this function is always asynchronous. |
| 10012 | */ |
| 10013 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10014 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10015 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10016 | bool privileged) |
| 10017 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10018 | struct rpc_message msg = { |
| 10019 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10020 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10021 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10022 | struct rpc_task_setup task_setup = { |
| 10023 | .rpc_client = server->client, |
| 10024 | .rpc_message = &msg, |
| 10025 | .callback_ops = &nfs41_free_stateid_ops, |
| 10026 | .flags = RPC_TASK_ASYNC, |
| 10027 | }; |
| 10028 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10029 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10030 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10031 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10032 | &task_setup.rpc_client, &msg); |
| 10033 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10034 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10035 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 10036 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10037 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10038 | data->server = server; |
| 10039 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 10040 | |
| 10041 | task_setup.callback_data = data; |
| 10042 | |
| 10043 | msg.rpc_argp = &data->args; |
| 10044 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10045 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, privileged); |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10046 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10047 | if (IS_ERR(task)) |
| 10048 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10049 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10050 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10051 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10052 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 10053 | static void |
| 10054 | nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10055 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10056 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10057 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10058 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10059 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10060 | } |
| 10061 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10062 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 10063 | const nfs4_stateid *s2) |
| 10064 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 10065 | if (s1->type != s2->type) |
| 10066 | return false; |
| 10067 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10068 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10069 | return false; |
| 10070 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10071 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10072 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10073 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 10074 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10075 | } |
| 10076 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 10077 | #endif /* CONFIG_NFS_V4_1 */ |
| 10078 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10079 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 10080 | const nfs4_stateid *s2) |
| 10081 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10082 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10083 | } |
| 10084 | |
| 10085 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10086 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10087 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10088 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10089 | .recover_open = nfs4_open_reclaim, |
| 10090 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10091 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10092 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10093 | }; |
| 10094 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10095 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10096 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10097 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 10098 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 10099 | .recover_open = nfs4_open_reclaim, |
| 10100 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10101 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 10102 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10103 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10104 | }; |
| 10105 | #endif /* CONFIG_NFS_V4_1 */ |
| 10106 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10107 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10108 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10109 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 10110 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10111 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10112 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10113 | }; |
| 10114 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10115 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10116 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10117 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 10118 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 10119 | .recover_open = nfs41_open_expired, |
| 10120 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10121 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10122 | }; |
| 10123 | #endif /* CONFIG_NFS_V4_1 */ |
| 10124 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10125 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10126 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10127 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10128 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10129 | }; |
| 10130 | |
| 10131 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10132 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10133 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10134 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10135 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10136 | }; |
| 10137 | #endif |
| 10138 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10139 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10140 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10141 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10142 | }; |
| 10143 | |
| 10144 | #if defined(CONFIG_NFS_V4_1) |
| 10145 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10146 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10147 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10148 | }; |
| 10149 | #endif /* CONFIG_NFS_V4_1 */ |
| 10150 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10151 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 10152 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10153 | .init_caps = NFS_CAP_READDIRPLUS |
| 10154 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10155 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10156 | .init_client = nfs40_init_client, |
| 10157 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10158 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10159 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10160 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10161 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10162 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10163 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10164 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 10165 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 10166 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10167 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10168 | }; |
| 10169 | |
| 10170 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10171 | static struct nfs_seqid * |
| 10172 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 10173 | { |
| 10174 | return NULL; |
| 10175 | } |
| 10176 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10177 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 10178 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10179 | .init_caps = NFS_CAP_READDIRPLUS |
| 10180 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 10181 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 10182 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10183 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 10184 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10185 | .init_client = nfs41_init_client, |
| 10186 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10187 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10188 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10189 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10190 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10191 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10192 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10193 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10194 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10195 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10196 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10197 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10198 | }; |
| 10199 | #endif |
| 10200 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10201 | #if defined(CONFIG_NFS_V4_2) |
| 10202 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 10203 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10204 | .init_caps = NFS_CAP_READDIRPLUS |
| 10205 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10206 | | NFS_CAP_POSIX_LOCK |
| 10207 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 10208 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10209 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 10210 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 10211 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 10212 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 10213 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 10214 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 10215 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 10216 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 10217 | | NFS_CAP_CLONE |
| 10218 | | NFS_CAP_LAYOUTERROR, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10219 | .init_client = nfs41_init_client, |
| 10220 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10221 | .match_stateid = nfs41_match_stateid, |
| 10222 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10223 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10224 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10225 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10226 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10227 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10228 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10229 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10230 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 10231 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10232 | }; |
| 10233 | #endif |
| 10234 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10235 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 10236 | [0] = &nfs_v4_0_minor_ops, |
| 10237 | #if defined(CONFIG_NFS_V4_1) |
| 10238 | [1] = &nfs_v4_1_minor_ops, |
| 10239 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10240 | #if defined(CONFIG_NFS_V4_2) |
| 10241 | [2] = &nfs_v4_2_minor_ops, |
| 10242 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10243 | }; |
| 10244 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 10245 | static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10246 | { |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10247 | ssize_t error, error2, error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10248 | |
| 10249 | error = generic_listxattr(dentry, list, size); |
| 10250 | if (error < 0) |
| 10251 | return error; |
| 10252 | if (list) { |
| 10253 | list += error; |
| 10254 | size -= error; |
| 10255 | } |
| 10256 | |
| 10257 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10258 | if (error2 < 0) |
| 10259 | return error2; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10260 | |
| 10261 | if (list) { |
| 10262 | list += error2; |
| 10263 | size -= error2; |
| 10264 | } |
| 10265 | |
| 10266 | error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
| 10267 | if (error3 < 0) |
| 10268 | return error3; |
| 10269 | |
| 10270 | return error + error2 + error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10271 | } |
| 10272 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10273 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10274 | .create = nfs_create, |
| 10275 | .lookup = nfs_lookup, |
| 10276 | .atomic_open = nfs_atomic_open, |
| 10277 | .link = nfs_link, |
| 10278 | .unlink = nfs_unlink, |
| 10279 | .symlink = nfs_symlink, |
| 10280 | .mkdir = nfs_mkdir, |
| 10281 | .rmdir = nfs_rmdir, |
| 10282 | .mknod = nfs_mknod, |
| 10283 | .rename = nfs_rename, |
| 10284 | .permission = nfs_permission, |
| 10285 | .getattr = nfs_getattr, |
| 10286 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10287 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10288 | }; |
| 10289 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10290 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10291 | .permission = nfs_permission, |
| 10292 | .getattr = nfs_getattr, |
| 10293 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10294 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10295 | }; |
| 10296 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10297 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10298 | .version = 4, /* protocol version */ |
| 10299 | .dentry_ops = &nfs4_dentry_operations, |
| 10300 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10301 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10302 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10303 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10304 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10305 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10306 | .getattr = nfs4_proc_getattr, |
| 10307 | .setattr = nfs4_proc_setattr, |
| 10308 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10309 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10310 | .access = nfs4_proc_access, |
| 10311 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10312 | .create = nfs4_proc_create, |
| 10313 | .remove = nfs4_proc_remove, |
| 10314 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10315 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10316 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10317 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10318 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10319 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10320 | .link = nfs4_proc_link, |
| 10321 | .symlink = nfs4_proc_symlink, |
| 10322 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10323 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10324 | .readdir = nfs4_proc_readdir, |
| 10325 | .mknod = nfs4_proc_mknod, |
| 10326 | .statfs = nfs4_proc_statfs, |
| 10327 | .fsinfo = nfs4_proc_fsinfo, |
| 10328 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10329 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10330 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10331 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10332 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10333 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10334 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10335 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10336 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10337 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10338 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10339 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10340 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10341 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10342 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10343 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10344 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10345 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10346 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10347 | .create_server = nfs4_create_server, |
| 10348 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10349 | }; |
| 10350 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10351 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10352 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10353 | .list = nfs4_xattr_list_nfs4_acl, |
| 10354 | .get = nfs4_xattr_get_nfs4_acl, |
| 10355 | .set = nfs4_xattr_set_nfs4_acl, |
| 10356 | }; |
| 10357 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10358 | #ifdef CONFIG_NFS_V4_2 |
| 10359 | static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
| 10360 | .prefix = XATTR_USER_PREFIX, |
| 10361 | .get = nfs4_xattr_get_nfs4_user, |
| 10362 | .set = nfs4_xattr_set_nfs4_user, |
| 10363 | }; |
| 10364 | #endif |
| 10365 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10366 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10367 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10368 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10369 | &nfs4_xattr_nfs4_label_handler, |
| 10370 | #endif |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10371 | #ifdef CONFIG_NFS_V4_2 |
| 10372 | &nfs4_xattr_nfs4_user_handler, |
| 10373 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10374 | NULL |
| 10375 | }; |
| 10376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10377 | /* |
| 10378 | * Local variables: |
| 10379 | * c-basic-offset: 8 |
| 10380 | * End: |
| 10381 | */ |