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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 74 | #define NFS4_BITMASK_SZ 3 |
| 75 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 76 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 78 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 79 | /* file attributes which can be mapped to nfs attributes */ |
| 80 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 81 | | ATTR_UID \ |
| 82 | | ATTR_GID \ |
| 83 | | ATTR_SIZE \ |
| 84 | | ATTR_ATIME \ |
| 85 | | ATTR_MTIME \ |
| 86 | | ATTR_CTIME \ |
| 87 | | ATTR_ATIME_SET \ |
| 88 | | ATTR_MTIME_SET) |
| 89 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 90 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 91 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | 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] | 93 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 94 | 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] | 95 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 97 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 100 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 101 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 102 | struct nfs4_slot *slot, |
| 103 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 104 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 105 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 106 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 107 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 108 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 109 | |
| 110 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 111 | static inline struct nfs4_label * |
| 112 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 113 | struct iattr *sattr, struct nfs4_label *label) |
| 114 | { |
| 115 | int err; |
| 116 | |
| 117 | if (label == NULL) |
| 118 | return NULL; |
| 119 | |
| 120 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 121 | return NULL; |
| 122 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 123 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 124 | &dentry->d_name, (void **)&label->label, &label->len); |
| 125 | if (err == 0) |
| 126 | return label; |
| 127 | |
| 128 | return NULL; |
| 129 | } |
| 130 | static inline void |
| 131 | nfs4_label_release_security(struct nfs4_label *label) |
| 132 | { |
| 133 | if (label) |
| 134 | security_release_secctx(label->label, label->len); |
| 135 | } |
| 136 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 137 | { |
| 138 | if (label) |
| 139 | return server->attr_bitmask; |
| 140 | |
| 141 | return server->attr_bitmask_nl; |
| 142 | } |
| 143 | #else |
| 144 | static inline struct nfs4_label * |
| 145 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 146 | struct iattr *sattr, struct nfs4_label *l) |
| 147 | { return NULL; } |
| 148 | static inline void |
| 149 | nfs4_label_release_security(struct nfs4_label *label) |
| 150 | { return; } |
| 151 | static inline u32 * |
| 152 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 153 | { return server->attr_bitmask; } |
| 154 | #endif |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 157 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 159 | if (err >= -1000) |
| 160 | return err; |
| 161 | switch (err) { |
| 162 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 163 | case -NFS4ERR_LAYOUTTRYLATER: |
| 164 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 165 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 166 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 167 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 168 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 169 | case -NFS4ERR_BADOWNER: |
| 170 | case -NFS4ERR_BADNAME: |
| 171 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 172 | case -NFS4ERR_SHARE_DENIED: |
| 173 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 174 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 175 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 176 | case -NFS4ERR_FILE_OPEN: |
| 177 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 178 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 180 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 181 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 183 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /* |
| 187 | * This is our standard bitmap for GETATTR requests. |
| 188 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 189 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | FATTR4_WORD0_TYPE |
| 191 | | FATTR4_WORD0_CHANGE |
| 192 | | FATTR4_WORD0_SIZE |
| 193 | | FATTR4_WORD0_FSID |
| 194 | | FATTR4_WORD0_FILEID, |
| 195 | FATTR4_WORD1_MODE |
| 196 | | FATTR4_WORD1_NUMLINKS |
| 197 | | FATTR4_WORD1_OWNER |
| 198 | | FATTR4_WORD1_OWNER_GROUP |
| 199 | | FATTR4_WORD1_RAWDEV |
| 200 | | FATTR4_WORD1_SPACE_USED |
| 201 | | FATTR4_WORD1_TIME_ACCESS |
| 202 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 203 | | FATTR4_WORD1_TIME_MODIFY |
| 204 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 205 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 206 | FATTR4_WORD2_SECURITY_LABEL |
| 207 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 210 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 211 | FATTR4_WORD0_TYPE |
| 212 | | FATTR4_WORD0_CHANGE |
| 213 | | FATTR4_WORD0_SIZE |
| 214 | | FATTR4_WORD0_FSID |
| 215 | | FATTR4_WORD0_FILEID, |
| 216 | FATTR4_WORD1_MODE |
| 217 | | FATTR4_WORD1_NUMLINKS |
| 218 | | FATTR4_WORD1_OWNER |
| 219 | | FATTR4_WORD1_OWNER_GROUP |
| 220 | | FATTR4_WORD1_RAWDEV |
| 221 | | FATTR4_WORD1_SPACE_USED |
| 222 | | FATTR4_WORD1_TIME_ACCESS |
| 223 | | FATTR4_WORD1_TIME_METADATA |
| 224 | | FATTR4_WORD1_TIME_MODIFY, |
| 225 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 226 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 227 | | FATTR4_WORD2_SECURITY_LABEL |
| 228 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 229 | }; |
| 230 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 231 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 232 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 233 | | FATTR4_WORD0_FILEID, |
| 234 | }; |
| 235 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 236 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | FATTR4_WORD0_FILES_AVAIL |
| 238 | | FATTR4_WORD0_FILES_FREE |
| 239 | | FATTR4_WORD0_FILES_TOTAL, |
| 240 | FATTR4_WORD1_SPACE_AVAIL |
| 241 | | FATTR4_WORD1_SPACE_FREE |
| 242 | | FATTR4_WORD1_SPACE_TOTAL |
| 243 | }; |
| 244 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 245 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | FATTR4_WORD0_MAXLINK |
| 247 | | FATTR4_WORD0_MAXNAME, |
| 248 | 0 |
| 249 | }; |
| 250 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 251 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | | FATTR4_WORD0_MAXREAD |
| 253 | | FATTR4_WORD0_MAXWRITE |
| 254 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 255 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 256 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 257 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 258 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | }; |
| 260 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 261 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 262 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 263 | | FATTR4_WORD0_SIZE |
| 264 | | FATTR4_WORD0_FSID |
| 265 | | FATTR4_WORD0_FILEID |
| 266 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 267 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 277 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 278 | struct inode *inode) |
| 279 | { |
| 280 | unsigned long cache_validity; |
| 281 | |
| 282 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 283 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 284 | return; |
| 285 | |
| 286 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 287 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 288 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 289 | | NFS_INO_INVALID_SIZE); |
| 290 | |
| 291 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 292 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 293 | |
| 294 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 295 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 296 | } |
| 297 | |
| 298 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 299 | const __u32 *src, struct inode *inode) |
| 300 | { |
| 301 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 302 | } |
| 303 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 304 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | struct nfs4_readdir_arg *readdir) |
| 306 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 307 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 308 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 311 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | readdir->cookie = 0; |
| 317 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 318 | if (cookie == 2) |
| 319 | return; |
| 320 | |
| 321 | /* |
| 322 | * NFSv4 servers do not return entries for '.' and '..' |
| 323 | * Therefore, we fake these entries here. We let '.' |
| 324 | * have cookie 0 and '..' have cookie 1. Note that |
| 325 | * when talking to the server, we always send cookie 0 |
| 326 | * instead of 1 or 2. |
| 327 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 328 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | if (cookie == 0) { |
| 331 | *p++ = xdr_one; /* next */ |
| 332 | *p++ = xdr_zero; /* cookie, first word */ |
| 333 | *p++ = xdr_one; /* cookie, second word */ |
| 334 | *p++ = xdr_one; /* entry len */ |
| 335 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 336 | p++; |
| 337 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 338 | *p++ = htonl(attrs); /* bitmap */ |
| 339 | *p++ = htonl(12); /* attribute buffer length */ |
| 340 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 341 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | *p++ = xdr_one; /* next */ |
| 345 | *p++ = xdr_zero; /* cookie, first word */ |
| 346 | *p++ = xdr_two; /* cookie, second word */ |
| 347 | *p++ = xdr_two; /* entry len */ |
| 348 | memcpy(p, "..\0\0", 4); /* entry */ |
| 349 | p++; |
| 350 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 351 | *p++ = htonl(attrs); /* bitmap */ |
| 352 | *p++ = htonl(12); /* attribute buffer length */ |
| 353 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 354 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | readdir->pgbase = (char *)p - (char *)start; |
| 357 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 358 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 361 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 362 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 363 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 364 | { |
| 365 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 366 | |
| 367 | ops->test_and_free_expired(server, stateid, cred); |
| 368 | } |
| 369 | |
| 370 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 371 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 372 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 373 | { |
| 374 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 375 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 376 | } |
| 377 | |
| 378 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 379 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 380 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 381 | { |
| 382 | nfs4_stateid tmp; |
| 383 | |
| 384 | nfs4_stateid_copy(&tmp, stateid); |
| 385 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 386 | } |
| 387 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 388 | static long nfs4_update_delay(long *timeout) |
| 389 | { |
| 390 | long ret; |
| 391 | if (!timeout) |
| 392 | return NFS4_POLL_RETRY_MAX; |
| 393 | if (*timeout <= 0) |
| 394 | *timeout = NFS4_POLL_RETRY_MIN; |
| 395 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 396 | *timeout = NFS4_POLL_RETRY_MAX; |
| 397 | ret = *timeout; |
| 398 | *timeout <<= 1; |
| 399 | return ret; |
| 400 | } |
| 401 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 402 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 403 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | might_sleep(); |
| 405 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 406 | freezable_schedule_timeout_killable_unsafe( |
| 407 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 408 | if (!__fatal_signal_pending(current)) |
| 409 | return 0; |
| 410 | return -EINTR; |
| 411 | } |
| 412 | |
| 413 | static int nfs4_delay_interruptible(long *timeout) |
| 414 | { |
| 415 | might_sleep(); |
| 416 | |
| 417 | freezable_schedule_timeout_interruptible(nfs4_update_delay(timeout)); |
| 418 | if (!signal_pending(current)) |
| 419 | return 0; |
| 420 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 421 | } |
| 422 | |
| 423 | static int nfs4_delay(long *timeout, bool interruptible) |
| 424 | { |
| 425 | if (interruptible) |
| 426 | return nfs4_delay_interruptible(timeout); |
| 427 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 428 | } |
| 429 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 430 | static const nfs4_stateid * |
| 431 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 432 | { |
| 433 | if (!stateid) |
| 434 | return NULL; |
| 435 | switch (stateid->type) { |
| 436 | case NFS4_OPEN_STATEID_TYPE: |
| 437 | case NFS4_LOCK_STATEID_TYPE: |
| 438 | case NFS4_DELEGATION_STATEID_TYPE: |
| 439 | return stateid; |
| 440 | default: |
| 441 | break; |
| 442 | } |
| 443 | return NULL; |
| 444 | } |
| 445 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 446 | /* This is the error handling routine for processes that are allowed |
| 447 | * to sleep. |
| 448 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 449 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 450 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 451 | { |
| 452 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 453 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 454 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 455 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 456 | int ret = errorcode; |
| 457 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 458 | exception->delay = 0; |
| 459 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 460 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 461 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 462 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 463 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 464 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 465 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 466 | switch(errorcode) { |
| 467 | case 0: |
| 468 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 469 | case -NFS4ERR_BADHANDLE: |
| 470 | case -ESTALE: |
| 471 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 472 | pnfs_destroy_layout(NFS_I(inode)); |
| 473 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 474 | case -NFS4ERR_DELEG_REVOKED: |
| 475 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 476 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 477 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 478 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 479 | if (inode != NULL && stateid != NULL) { |
| 480 | nfs_inode_find_state_and_recover(inode, |
| 481 | stateid); |
| 482 | goto wait_on_recovery; |
| 483 | } |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 484 | /* Fall through */ |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 485 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 486 | if (inode) { |
| 487 | int err; |
| 488 | |
| 489 | err = nfs_async_inode_return_delegation(inode, |
| 490 | stateid); |
| 491 | if (err == 0) |
| 492 | goto wait_on_recovery; |
| 493 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 494 | exception->retry = 1; |
| 495 | break; |
| 496 | } |
| 497 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 498 | if (state == NULL) |
| 499 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 500 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 501 | if (ret < 0) |
| 502 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 503 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 504 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 505 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 506 | nfs4_schedule_lease_recovery(clp); |
| 507 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 508 | case -NFS4ERR_MOVED: |
| 509 | ret = nfs4_schedule_migration_recovery(server); |
| 510 | if (ret < 0) |
| 511 | break; |
| 512 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 513 | case -NFS4ERR_LEASE_MOVED: |
| 514 | nfs4_schedule_lease_moved_recovery(clp); |
| 515 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 516 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 517 | case -NFS4ERR_BADSESSION: |
| 518 | case -NFS4ERR_BADSLOT: |
| 519 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 520 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 521 | case -NFS4ERR_DEADSESSION: |
| 522 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 523 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 524 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 525 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 526 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 527 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 528 | if (exception->timeout > HZ) { |
| 529 | /* We have retried a decent amount, time to |
| 530 | * fail |
| 531 | */ |
| 532 | ret = -EBUSY; |
| 533 | break; |
| 534 | } |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 535 | /* Fall through */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 536 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 537 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 538 | /* Fall through */ |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 539 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 540 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 541 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 542 | exception->delay = 1; |
| 543 | return 0; |
| 544 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 545 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 546 | case -NFS4ERR_OLD_STATEID: |
| 547 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 548 | break; |
| 549 | case -NFS4ERR_BADOWNER: |
| 550 | /* The following works around a Linux server bug! */ |
| 551 | case -NFS4ERR_BADNAME: |
| 552 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 553 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 554 | exception->retry = 1; |
| 555 | printk(KERN_WARNING "NFS: v4 server %s " |
| 556 | "does not accept raw " |
| 557 | "uid/gids. " |
| 558 | "Reenabling the idmapper.\n", |
| 559 | server->nfs_client->cl_hostname); |
| 560 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 561 | } |
| 562 | /* We failed to handle the error */ |
| 563 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 564 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 565 | exception->recovering = 1; |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | /* This is the error handling routine for processes that are allowed |
| 570 | * to sleep. |
| 571 | */ |
| 572 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 573 | { |
| 574 | struct nfs_client *clp = server->nfs_client; |
| 575 | int ret; |
| 576 | |
| 577 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 578 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 579 | ret = nfs4_delay(&exception->timeout, |
| 580 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 581 | goto out_retry; |
| 582 | } |
| 583 | if (exception->recovering) { |
| 584 | ret = nfs4_wait_clnt_recover(clp); |
| 585 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 586 | return -EIO; |
| 587 | goto out_retry; |
| 588 | } |
| 589 | return ret; |
| 590 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 591 | if (ret == 0) |
| 592 | exception->retry = 1; |
| 593 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 594 | } |
| 595 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 596 | static int |
| 597 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 598 | int errorcode, struct nfs4_exception *exception) |
| 599 | { |
| 600 | struct nfs_client *clp = server->nfs_client; |
| 601 | int ret; |
| 602 | |
| 603 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 604 | if (exception->delay) { |
| 605 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 606 | goto out_retry; |
| 607 | } |
| 608 | if (exception->recovering) { |
| 609 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 610 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 611 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 612 | goto out_retry; |
| 613 | } |
| 614 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 615 | ret = -EIO; |
| 616 | return ret; |
| 617 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 618 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 619 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 620 | /* |
| 621 | * For NFS4ERR_MOVED, the client transport will need to |
| 622 | * be recomputed after migration recovery has completed. |
| 623 | */ |
| 624 | if (errorcode == -NFS4ERR_MOVED) |
| 625 | rpc_task_release_transport(task); |
| 626 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 627 | return ret; |
| 628 | } |
| 629 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 630 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 631 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 632 | struct nfs4_state *state, long *timeout) |
| 633 | { |
| 634 | struct nfs4_exception exception = { |
| 635 | .state = state, |
| 636 | }; |
| 637 | |
| 638 | if (task->tk_status >= 0) |
| 639 | return 0; |
| 640 | if (timeout) |
| 641 | exception.timeout = *timeout; |
| 642 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 643 | task->tk_status, |
| 644 | &exception); |
| 645 | if (exception.delay && timeout) |
| 646 | *timeout = exception.timeout; |
| 647 | if (exception.retry) |
| 648 | return -EAGAIN; |
| 649 | return 0; |
| 650 | } |
| 651 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 652 | /* |
| 653 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 654 | * or 'false' otherwise. |
| 655 | */ |
| 656 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 657 | { |
| 658 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 659 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 660 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 661 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 662 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | spin_lock(&clp->cl_lock); |
| 665 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 666 | clp->cl_last_renewal = timestamp; |
| 667 | spin_unlock(&clp->cl_lock); |
| 668 | } |
| 669 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 670 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 671 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 672 | struct nfs_client *clp = server->nfs_client; |
| 673 | |
| 674 | if (!nfs4_has_session(clp)) |
| 675 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 676 | } |
| 677 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 678 | struct nfs4_call_sync_data { |
| 679 | const struct nfs_server *seq_server; |
| 680 | struct nfs4_sequence_args *seq_args; |
| 681 | struct nfs4_sequence_res *seq_res; |
| 682 | }; |
| 683 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 684 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 685 | struct nfs4_sequence_res *res, int cache_reply, |
| 686 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 687 | { |
| 688 | args->sa_slot = NULL; |
| 689 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 690 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 691 | |
| 692 | res->sr_slot = NULL; |
| 693 | } |
| 694 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 695 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 696 | { |
| 697 | struct nfs4_slot *slot = res->sr_slot; |
| 698 | struct nfs4_slot_table *tbl; |
| 699 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 700 | tbl = slot->table; |
| 701 | spin_lock(&tbl->slot_tbl_lock); |
| 702 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 703 | nfs4_free_slot(tbl, slot); |
| 704 | spin_unlock(&tbl->slot_tbl_lock); |
| 705 | |
| 706 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | static int nfs40_sequence_done(struct rpc_task *task, |
| 710 | struct nfs4_sequence_res *res) |
| 711 | { |
| 712 | if (res->sr_slot != NULL) |
| 713 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 714 | return 1; |
| 715 | } |
| 716 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 717 | #if defined(CONFIG_NFS_V4_1) |
| 718 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 719 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 720 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 721 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 722 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 723 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 724 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 725 | if (!slot) |
| 726 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 727 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 728 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 729 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 730 | /* Bump the slot sequence number */ |
| 731 | if (slot->seq_done) |
| 732 | slot->seq_nr++; |
| 733 | slot->seq_done = 0; |
| 734 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 735 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 736 | /* Be nice to the server: try to ensure that the last transmitted |
| 737 | * value for highest_user_slotid <= target_highest_slotid |
| 738 | */ |
| 739 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 740 | send_new_highest_used_slotid = true; |
| 741 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 742 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 743 | send_new_highest_used_slotid = false; |
| 744 | goto out_unlock; |
| 745 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 746 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 747 | |
| 748 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 749 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 750 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 751 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 752 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 753 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 754 | if (waitqueue_active(&tbl->slot_waitq)) |
| 755 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 756 | } |
| 757 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 758 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 759 | { |
| 760 | nfs41_release_slot(res->sr_slot); |
| 761 | res->sr_slot = NULL; |
| 762 | } |
| 763 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 764 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 765 | u32 seqnr) |
| 766 | { |
| 767 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 768 | slot->seq_nr_highest_sent = seqnr; |
| 769 | } |
| 770 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 771 | u32 seqnr) |
| 772 | { |
| 773 | slot->seq_nr_highest_sent = seqnr; |
| 774 | slot->seq_nr_last_acked = seqnr; |
| 775 | } |
| 776 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 777 | static int nfs41_sequence_process(struct rpc_task *task, |
| 778 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 779 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 780 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 781 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 782 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 783 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 784 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 785 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 786 | if (slot == NULL) |
| 787 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 788 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 789 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 790 | goto out; |
| 791 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 792 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 793 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 794 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 795 | |
| 796 | status = res->sr_status; |
| 797 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 798 | status = -NFS4ERR_DEADSESSION; |
| 799 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 800 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 801 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 802 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 803 | /* Mark this sequence number as having been acked */ |
| 804 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 805 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 806 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 807 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 808 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 809 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 810 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 811 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 812 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 813 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 814 | case 1: |
| 815 | /* |
| 816 | * sr_status remains 1 if an RPC level error occurred. |
| 817 | * The server may or may not have processed the sequence |
| 818 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 819 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 820 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 821 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 822 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 823 | case -NFS4ERR_DELAY: |
| 824 | /* The server detected a resend of the RPC call and |
| 825 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 826 | * of RFC5661. |
| 827 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 828 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 829 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 830 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 831 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 832 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 833 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 834 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 835 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 836 | /* |
| 837 | * The server thinks we tried to replay a request. |
| 838 | * Retry the call after bumping the sequence ID. |
| 839 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 840 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 841 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 842 | case -NFS4ERR_BADSLOT: |
| 843 | /* |
| 844 | * The slot id we used was probably retired. Try again |
| 845 | * using a different slot id. |
| 846 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 847 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 848 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 849 | goto retry_nowait; |
| 850 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 851 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 852 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 853 | * Were one or more calls using this slot interrupted? |
| 854 | * If the server never received the request, then our |
| 855 | * transmitted slot sequence number may be too high. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 856 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 857 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 858 | slot->seq_nr--; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 859 | goto retry_nowait; |
| 860 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 861 | /* |
| 862 | * RFC5661: |
| 863 | * A retry might be sent while the original request is |
| 864 | * still in progress on the replier. The replier SHOULD |
| 865 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 866 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 867 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 868 | * |
| 869 | * Restart the search after a delay. |
| 870 | */ |
| 871 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 872 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 873 | case -NFS4ERR_BADSESSION: |
| 874 | case -NFS4ERR_DEADSESSION: |
| 875 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 876 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 877 | default: |
| 878 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 879 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 880 | } |
| 881 | out: |
| 882 | /* The session may be reset by one of the error handlers. */ |
| 883 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 884 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 885 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 886 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 887 | nfs4_schedule_session_recovery(session, status); |
| 888 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 889 | nfs41_sequence_free_slot(res); |
| 890 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 891 | retry_new_seq: |
| 892 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 893 | retry_nowait: |
| 894 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 895 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 896 | task->tk_status = 0; |
| 897 | ret = 0; |
| 898 | } |
| 899 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 900 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 901 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 902 | goto out; |
| 903 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 904 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 905 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 906 | |
| 907 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 908 | { |
| 909 | if (!nfs41_sequence_process(task, res)) |
| 910 | return 0; |
| 911 | if (res->sr_slot != NULL) |
| 912 | nfs41_sequence_free_slot(res); |
| 913 | return 1; |
| 914 | |
| 915 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 916 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 917 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 918 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 919 | { |
| 920 | if (res->sr_slot == NULL) |
| 921 | return 1; |
| 922 | if (res->sr_slot->table->session != NULL) |
| 923 | return nfs41_sequence_process(task, res); |
| 924 | return nfs40_sequence_done(task, res); |
| 925 | } |
| 926 | |
| 927 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 928 | { |
| 929 | if (res->sr_slot != NULL) { |
| 930 | if (res->sr_slot->table->session != NULL) |
| 931 | nfs41_sequence_free_slot(res); |
| 932 | else |
| 933 | nfs40_sequence_free_slot(res); |
| 934 | } |
| 935 | } |
| 936 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 937 | 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] | 938 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 939 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 940 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 941 | if (!res->sr_slot->table->session) |
| 942 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 943 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 944 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 945 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 946 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 947 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 948 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 949 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 950 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 951 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 952 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 953 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 954 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 957 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 958 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 959 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 960 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 961 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 962 | } |
| 963 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 964 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 965 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 966 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 967 | }; |
| 968 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 969 | #else /* !CONFIG_NFS_V4_1 */ |
| 970 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 971 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 972 | { |
| 973 | return nfs40_sequence_done(task, res); |
| 974 | } |
| 975 | |
| 976 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 977 | { |
| 978 | if (res->sr_slot != NULL) |
| 979 | nfs40_sequence_free_slot(res); |
| 980 | } |
| 981 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 982 | int nfs4_sequence_done(struct rpc_task *task, |
| 983 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 984 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 985 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 986 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 987 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 988 | |
| 989 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 990 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 991 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 992 | { |
| 993 | res->sr_timestamp = jiffies; |
| 994 | res->sr_status_flags = 0; |
| 995 | res->sr_status = 1; |
| 996 | } |
| 997 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 998 | static |
| 999 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1000 | struct nfs4_sequence_res *res, |
| 1001 | struct nfs4_slot *slot) |
| 1002 | { |
| 1003 | if (!slot) |
| 1004 | return; |
| 1005 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1006 | args->sa_slot = slot; |
| 1007 | |
| 1008 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1012 | struct nfs4_sequence_args *args, |
| 1013 | struct nfs4_sequence_res *res, |
| 1014 | struct rpc_task *task) |
| 1015 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1016 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1017 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1018 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1019 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1020 | /* slot already allocated? */ |
| 1021 | if (res->sr_slot != NULL) |
| 1022 | goto out_start; |
| 1023 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1024 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1025 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1026 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1027 | spin_lock(&tbl->slot_tbl_lock); |
| 1028 | /* The state manager will wait until the slot table is empty */ |
| 1029 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1030 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1031 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1032 | slot = nfs4_alloc_slot(tbl); |
| 1033 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1034 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1035 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1036 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1037 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1038 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1039 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1040 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1041 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1042 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1043 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1044 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1045 | rpc_call_start(task); |
| 1046 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1047 | out_sleep_timeout: |
| 1048 | /* Try again in 1/4 second */ |
| 1049 | if (args->sa_privileged) |
| 1050 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1051 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1052 | else |
| 1053 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1054 | NULL, jiffies + (HZ >> 2)); |
| 1055 | spin_unlock(&tbl->slot_tbl_lock); |
| 1056 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1057 | out_sleep: |
| 1058 | if (args->sa_privileged) |
| 1059 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1060 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1061 | else |
| 1062 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1063 | spin_unlock(&tbl->slot_tbl_lock); |
| 1064 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1065 | } |
| 1066 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1067 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1068 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1069 | { |
| 1070 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1071 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1072 | data->seq_args, data->seq_res, task); |
| 1073 | } |
| 1074 | |
| 1075 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1076 | { |
| 1077 | struct nfs4_call_sync_data *data = calldata; |
| 1078 | nfs4_sequence_done(task, data->seq_res); |
| 1079 | } |
| 1080 | |
| 1081 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1082 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1083 | .rpc_call_done = nfs40_call_sync_done, |
| 1084 | }; |
| 1085 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1086 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1087 | { |
| 1088 | int ret; |
| 1089 | struct rpc_task *task; |
| 1090 | |
| 1091 | task = rpc_run_task(task_setup); |
| 1092 | if (IS_ERR(task)) |
| 1093 | return PTR_ERR(task); |
| 1094 | |
| 1095 | ret = task->tk_status; |
| 1096 | rpc_put_task(task); |
| 1097 | return ret; |
| 1098 | } |
| 1099 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1100 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1101 | struct nfs_server *server, |
| 1102 | struct rpc_message *msg, |
| 1103 | struct nfs4_sequence_args *args, |
| 1104 | struct nfs4_sequence_res *res, |
| 1105 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1106 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1107 | struct nfs_client *clp = server->nfs_client; |
| 1108 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1109 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1110 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1111 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1112 | }; |
| 1113 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1114 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1115 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1116 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1117 | .callback_data = &data, |
| 1118 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1119 | }; |
| 1120 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1121 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1124 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1125 | struct nfs_server *server, |
| 1126 | struct rpc_message *msg, |
| 1127 | struct nfs4_sequence_args *args, |
| 1128 | struct nfs4_sequence_res *res) |
| 1129 | { |
| 1130 | return nfs4_do_call_sync(clnt, server, msg, args, res, 0); |
| 1131 | } |
| 1132 | |
| 1133 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1134 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1135 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1136 | struct rpc_message *msg, |
| 1137 | struct nfs4_sequence_args *args, |
| 1138 | struct nfs4_sequence_res *res, |
| 1139 | int cache_reply) |
| 1140 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1141 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1142 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1145 | static void |
| 1146 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1147 | { |
| 1148 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1149 | inc_nlink(inode); |
| 1150 | } |
| 1151 | |
| 1152 | static void |
| 1153 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1154 | { |
| 1155 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1156 | drop_nlink(inode); |
| 1157 | } |
| 1158 | |
| 1159 | static void |
| 1160 | update_changeattr_locked(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1161 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
| 1163 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1164 | |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1165 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1166 | | NFS_INO_INVALID_MTIME |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1167 | | NFS_INO_INVALID_DATA |
| 1168 | | cache_validity; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1169 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1170 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1171 | nfsi->attrtimeo_timestamp = jiffies; |
| 1172 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | nfs_force_lookup_revalidate(dir); |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1174 | if (cinfo->before != inode_peek_iversion_raw(dir)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1175 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1176 | NFS_INO_INVALID_ACL; |
| 1177 | } |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1178 | inode_set_iversion_raw(dir, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1179 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1180 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1181 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1182 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | static void |
| 1186 | update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1187 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1188 | { |
| 1189 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1190 | update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | spin_unlock(&dir->i_lock); |
| 1192 | } |
| 1193 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1194 | struct nfs4_open_createattrs { |
| 1195 | struct nfs4_label *label; |
| 1196 | struct iattr *sattr; |
| 1197 | const __u32 verf[2]; |
| 1198 | }; |
| 1199 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1200 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1201 | int err, struct nfs4_exception *exception) |
| 1202 | { |
| 1203 | if (err != -EINVAL) |
| 1204 | return false; |
| 1205 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1206 | return false; |
| 1207 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1208 | exception->retry = 1; |
| 1209 | return true; |
| 1210 | } |
| 1211 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1212 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1213 | { |
| 1214 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1215 | } |
| 1216 | |
| 1217 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1218 | { |
| 1219 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1220 | |
| 1221 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1222 | } |
| 1223 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1224 | static u32 |
| 1225 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1226 | fmode_t fmode, int openflags) |
| 1227 | { |
| 1228 | u32 res = 0; |
| 1229 | |
| 1230 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1231 | case FMODE_READ: |
| 1232 | res = NFS4_SHARE_ACCESS_READ; |
| 1233 | break; |
| 1234 | case FMODE_WRITE: |
| 1235 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1236 | break; |
| 1237 | case FMODE_READ|FMODE_WRITE: |
| 1238 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1239 | } |
| 1240 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1241 | goto out; |
| 1242 | /* Want no delegation if we're using O_DIRECT */ |
| 1243 | if (openflags & O_DIRECT) |
| 1244 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1245 | out: |
| 1246 | return res; |
| 1247 | } |
| 1248 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1249 | static enum open_claim_type4 |
| 1250 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1251 | enum open_claim_type4 claim) |
| 1252 | { |
| 1253 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1254 | return claim; |
| 1255 | switch (claim) { |
| 1256 | default: |
| 1257 | return claim; |
| 1258 | case NFS4_OPEN_CLAIM_FH: |
| 1259 | return NFS4_OPEN_CLAIM_NULL; |
| 1260 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1261 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1262 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1263 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1264 | } |
| 1265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
| 1267 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1268 | { |
| 1269 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1270 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1271 | p->o_res.seqid = p->o_arg.seqid; |
| 1272 | p->c_res.seqid = p->c_arg.seqid; |
| 1273 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1274 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1275 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1276 | 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] | 1277 | } |
| 1278 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1279 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1280 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1281 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1282 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1283 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1284 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1285 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1286 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1287 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1288 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1289 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1290 | struct nfs4_opendata *p; |
| 1291 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1292 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1293 | if (p == NULL) |
| 1294 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1295 | |
| 1296 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1297 | if (IS_ERR(p->f_label)) |
| 1298 | goto err_free_p; |
| 1299 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1300 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1301 | if (IS_ERR(p->a_label)) |
| 1302 | goto err_free_f; |
| 1303 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1304 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1305 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1306 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1307 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1308 | nfs_sb_active(dentry->d_sb); |
| 1309 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1310 | p->dir = parent; |
| 1311 | p->owner = sp; |
| 1312 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1313 | p->o_arg.open_flags = flags; |
| 1314 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1315 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1316 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1317 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1318 | if (flags & O_CREAT) { |
| 1319 | p->o_arg.umask = current_umask(); |
| 1320 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1321 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1322 | p->o_arg.u.attrs = &p->attrs; |
| 1323 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1324 | |
| 1325 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1326 | sizeof(p->o_arg.u.verifier.data)); |
| 1327 | } |
| 1328 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1329 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1330 | * will return permission denied for all bits until close */ |
| 1331 | if (!(flags & O_EXCL)) { |
| 1332 | /* ask server to check for all possible rights as results |
| 1333 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1334 | switch (p->o_arg.claim) { |
| 1335 | default: |
| 1336 | break; |
| 1337 | case NFS4_OPEN_CLAIM_NULL: |
| 1338 | case NFS4_OPEN_CLAIM_FH: |
| 1339 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1340 | NFS4_ACCESS_MODIFY | |
| 1341 | NFS4_ACCESS_EXTEND | |
| 1342 | NFS4_ACCESS_EXECUTE; |
| 1343 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1344 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1345 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1346 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1347 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1348 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1349 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1350 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1351 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1352 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1353 | case NFS4_OPEN_CLAIM_NULL: |
| 1354 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1355 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1356 | p->o_arg.fh = NFS_FH(dir); |
| 1357 | break; |
| 1358 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1359 | case NFS4_OPEN_CLAIM_FH: |
| 1360 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1361 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1362 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1363 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1364 | p->c_arg.fh = &p->o_res.fh; |
| 1365 | p->c_arg.stateid = &p->o_res.stateid; |
| 1366 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1367 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1368 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1369 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1370 | |
| 1371 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1372 | nfs4_label_free(p->a_label); |
| 1373 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1374 | nfs4_label_free(p->f_label); |
| 1375 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1376 | kfree(p); |
| 1377 | err: |
| 1378 | dput(parent); |
| 1379 | return NULL; |
| 1380 | } |
| 1381 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1382 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1383 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1384 | struct nfs4_opendata *p = container_of(kref, |
| 1385 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1386 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1387 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1388 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1389 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1390 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1391 | if (p->state != NULL) |
| 1392 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1393 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1394 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1395 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1396 | nfs4_label_free(p->f_label); |
| 1397 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1398 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1399 | dput(p->dentry); |
| 1400 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1401 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1402 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1403 | kfree(p); |
| 1404 | } |
| 1405 | |
| 1406 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1407 | { |
| 1408 | if (p != NULL) |
| 1409 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1412 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1413 | fmode_t fmode) |
| 1414 | { |
| 1415 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1416 | case FMODE_READ|FMODE_WRITE: |
| 1417 | return state->n_rdwr != 0; |
| 1418 | case FMODE_WRITE: |
| 1419 | return state->n_wronly != 0; |
| 1420 | case FMODE_READ: |
| 1421 | return state->n_rdonly != 0; |
| 1422 | } |
| 1423 | WARN_ON_ONCE(1); |
| 1424 | return false; |
| 1425 | } |
| 1426 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1427 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1428 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1429 | { |
| 1430 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1431 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1432 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1433 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1434 | switch (claim) { |
| 1435 | case NFS4_OPEN_CLAIM_NULL: |
| 1436 | case NFS4_OPEN_CLAIM_FH: |
| 1437 | goto out; |
| 1438 | default: |
| 1439 | break; |
| 1440 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1441 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1442 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1443 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1444 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1445 | break; |
| 1446 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1447 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1448 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1449 | break; |
| 1450 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1451 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1452 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1453 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1454 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1455 | return ret; |
| 1456 | } |
| 1457 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1458 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1459 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1460 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1461 | if (delegation == NULL) |
| 1462 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1463 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1464 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1465 | switch (claim) { |
| 1466 | case NFS4_OPEN_CLAIM_NULL: |
| 1467 | case NFS4_OPEN_CLAIM_FH: |
| 1468 | break; |
| 1469 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1470 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1471 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 1472 | /* Fall through */ |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1473 | default: |
| 1474 | return 0; |
| 1475 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1476 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1477 | return 1; |
| 1478 | } |
| 1479 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1480 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1481 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1482 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1483 | case FMODE_WRITE: |
| 1484 | state->n_wronly++; |
| 1485 | break; |
| 1486 | case FMODE_READ: |
| 1487 | state->n_rdonly++; |
| 1488 | break; |
| 1489 | case FMODE_READ|FMODE_WRITE: |
| 1490 | state->n_rdwr++; |
| 1491 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1492 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1493 | } |
| 1494 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1495 | #ifdef CONFIG_NFS_V4_1 |
| 1496 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1497 | { |
| 1498 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1499 | return true; |
| 1500 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1501 | return true; |
| 1502 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1503 | return true; |
| 1504 | return false; |
| 1505 | } |
| 1506 | #endif /* CONFIG_NFS_V4_1 */ |
| 1507 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1508 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1509 | { |
| 1510 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1511 | wake_up_all(&state->waitq); |
| 1512 | } |
| 1513 | |
| 1514 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1515 | const nfs4_stateid *stateid) |
| 1516 | { |
| 1517 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1518 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1519 | |
| 1520 | if (stateid_seqid == state_seqid + 1U || |
| 1521 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1522 | nfs_state_log_update_open_stateid(state); |
| 1523 | else |
| 1524 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1525 | } |
| 1526 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1527 | 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] | 1528 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1529 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1530 | bool need_recover = false; |
| 1531 | |
| 1532 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1533 | need_recover = true; |
| 1534 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1535 | need_recover = true; |
| 1536 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1537 | need_recover = true; |
| 1538 | if (need_recover) |
| 1539 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1540 | } |
| 1541 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1542 | /* |
| 1543 | * Check for whether or not the caller may update the open stateid |
| 1544 | * to the value passed in by stateid. |
| 1545 | * |
| 1546 | * Note: This function relies heavily on the server implementing |
| 1547 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1548 | * correctly. |
| 1549 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1550 | * are then incremented on every state transition. |
| 1551 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1552 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1553 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1554 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1555 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1556 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1557 | if (stateid->seqid == cpu_to_be32(1)) |
| 1558 | nfs_state_log_update_open_stateid(state); |
| 1559 | else |
| 1560 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1561 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1562 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1563 | |
| 1564 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1565 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1566 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1567 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1568 | return false; |
| 1569 | } |
| 1570 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1571 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1572 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1573 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1574 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1575 | if (state->n_wronly) |
| 1576 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1577 | if (state->n_rdonly) |
| 1578 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1579 | if (state->n_rdwr) |
| 1580 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1581 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1582 | } |
| 1583 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1584 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1585 | nfs4_stateid *stateid, fmode_t fmode) |
| 1586 | { |
| 1587 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1588 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1589 | case FMODE_WRITE: |
| 1590 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1591 | break; |
| 1592 | case FMODE_READ: |
| 1593 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1594 | break; |
| 1595 | case 0: |
| 1596 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1597 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1598 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1599 | } |
| 1600 | if (stateid == NULL) |
| 1601 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1602 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1603 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1604 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1605 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1606 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1607 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1608 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1609 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1610 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1611 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1612 | out: |
| 1613 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1614 | } |
| 1615 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1616 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1617 | nfs4_stateid *arg_stateid, |
| 1618 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1619 | { |
| 1620 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1621 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1622 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1623 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1624 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1625 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1626 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1627 | } |
| 1628 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1629 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1630 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1631 | __must_hold(&state->owner->so_lock) |
| 1632 | __must_hold(&state->seqlock) |
| 1633 | __must_hold(RCU) |
| 1634 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1635 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1636 | DEFINE_WAIT(wait); |
| 1637 | int status = 0; |
| 1638 | for (;;) { |
| 1639 | |
| 1640 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1641 | return; |
| 1642 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1643 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1644 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1645 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1646 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1647 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1648 | break; |
| 1649 | |
| 1650 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1651 | /* |
| 1652 | * Ensure we process the state changes in the same order |
| 1653 | * in which the server processed them by delaying the |
| 1654 | * update of the stateid until we are in sequence. |
| 1655 | */ |
| 1656 | write_sequnlock(&state->seqlock); |
| 1657 | spin_unlock(&state->owner->so_lock); |
| 1658 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1659 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1660 | if (!signal_pending(current)) { |
| 1661 | if (schedule_timeout(5*HZ) == 0) |
| 1662 | status = -EAGAIN; |
| 1663 | else |
| 1664 | status = 0; |
| 1665 | } else |
| 1666 | status = -EINTR; |
| 1667 | finish_wait(&state->waitq, &wait); |
| 1668 | rcu_read_lock(); |
| 1669 | spin_lock(&state->owner->so_lock); |
| 1670 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1671 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1672 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1673 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1674 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1675 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1676 | nfs_test_and_clear_all_open_stateid(state); |
| 1677 | } |
| 1678 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1679 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1680 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1681 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1682 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1683 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1684 | } |
| 1685 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1686 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1687 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1688 | fmode_t fmode, |
| 1689 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1691 | /* |
| 1692 | * Protect the call to nfs4_state_set_mode_locked and |
| 1693 | * serialise the stateid update |
| 1694 | */ |
| 1695 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1696 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1697 | switch (fmode) { |
| 1698 | case FMODE_READ: |
| 1699 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1700 | break; |
| 1701 | case FMODE_WRITE: |
| 1702 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1703 | break; |
| 1704 | case FMODE_READ|FMODE_WRITE: |
| 1705 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1706 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1707 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1708 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1709 | } |
| 1710 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1711 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1712 | { |
| 1713 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1714 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1715 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1716 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1717 | } |
| 1718 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1719 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1720 | const nfs4_stateid *deleg_stateid, |
| 1721 | fmode_t fmode) |
| 1722 | { |
| 1723 | /* |
| 1724 | * Protect the call to nfs4_state_set_mode_locked and |
| 1725 | * serialise the stateid update |
| 1726 | */ |
| 1727 | write_seqlock(&state->seqlock); |
| 1728 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1729 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1730 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1733 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1734 | { |
| 1735 | write_seqlock(&state->seqlock); |
| 1736 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1737 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1738 | write_sequnlock(&state->seqlock); |
| 1739 | } |
| 1740 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1741 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1742 | const nfs4_stateid *open_stateid, |
| 1743 | const nfs4_stateid *delegation, |
| 1744 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1745 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1746 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1747 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1748 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1749 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1750 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1751 | int ret = 0; |
| 1752 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1753 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1754 | |
| 1755 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1756 | spin_lock(&state->owner->so_lock); |
| 1757 | if (open_stateid != NULL) { |
| 1758 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1759 | ret = 1; |
| 1760 | } |
| 1761 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1762 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1763 | if (deleg_cur == NULL) |
| 1764 | goto no_delegation; |
| 1765 | |
| 1766 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1767 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1768 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1769 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1770 | goto no_delegation_unlock; |
| 1771 | |
| 1772 | if (delegation == NULL) |
| 1773 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1774 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1775 | goto no_delegation_unlock; |
| 1776 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1777 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1778 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1779 | ret = 1; |
| 1780 | no_delegation_unlock: |
| 1781 | spin_unlock(&deleg_cur->lock); |
| 1782 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1783 | if (ret) |
| 1784 | update_open_stateflags(state, fmode); |
| 1785 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1786 | rcu_read_unlock(); |
| 1787 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1788 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1789 | nfs4_schedule_state_manager(clp); |
| 1790 | if (freeme.type != 0) |
| 1791 | nfs4_test_and_free_stateid(server, &freeme, |
| 1792 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1793 | |
| 1794 | return ret; |
| 1795 | } |
| 1796 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1797 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1798 | const nfs4_stateid *stateid) |
| 1799 | { |
| 1800 | struct nfs4_state *state = lsp->ls_state; |
| 1801 | bool ret = false; |
| 1802 | |
| 1803 | spin_lock(&state->state_lock); |
| 1804 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1805 | goto out_noupdate; |
| 1806 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1807 | goto out_noupdate; |
| 1808 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1809 | ret = true; |
| 1810 | out_noupdate: |
| 1811 | spin_unlock(&state->state_lock); |
| 1812 | return ret; |
| 1813 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1814 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1815 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1816 | { |
| 1817 | struct nfs_delegation *delegation; |
| 1818 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1819 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1820 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1821 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1822 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1823 | rcu_read_unlock(); |
| 1824 | return; |
| 1825 | } |
| 1826 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1827 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1828 | } |
| 1829 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1830 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1831 | { |
| 1832 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1833 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1834 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1835 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1836 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1837 | nfs4_stateid stateid; |
| 1838 | int ret = -EAGAIN; |
| 1839 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1840 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1841 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1842 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1843 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1844 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1845 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1846 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1847 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1848 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1849 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1850 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1851 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1852 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1853 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1854 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1855 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1856 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1857 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1858 | if (!opendata->is_recover) { |
| 1859 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1860 | if (ret != 0) |
| 1861 | goto out; |
| 1862 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1863 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1864 | |
| 1865 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1866 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1867 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1868 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1869 | out: |
| 1870 | return ERR_PTR(ret); |
| 1871 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1872 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1873 | return state; |
| 1874 | } |
| 1875 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1876 | static void |
| 1877 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1878 | { |
| 1879 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1880 | struct nfs_delegation *delegation; |
| 1881 | int delegation_flags = 0; |
| 1882 | |
| 1883 | rcu_read_lock(); |
| 1884 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1885 | if (delegation) |
| 1886 | delegation_flags = delegation->flags; |
| 1887 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1888 | switch (data->o_arg.claim) { |
| 1889 | default: |
| 1890 | break; |
| 1891 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1892 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1893 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1894 | "returning a delegation for " |
| 1895 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1896 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1897 | return; |
| 1898 | } |
| 1899 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1900 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1901 | data->owner->so_cred, |
| 1902 | data->o_res.delegation_type, |
| 1903 | &data->o_res.delegation, |
| 1904 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1905 | else |
| 1906 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1907 | data->owner->so_cred, |
| 1908 | data->o_res.delegation_type, |
| 1909 | &data->o_res.delegation, |
| 1910 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1911 | |
| 1912 | if (data->o_res.do_recall) |
| 1913 | nfs_async_inode_return_delegation(state->inode, |
| 1914 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | /* |
| 1918 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1919 | * and update the nfs4_state. |
| 1920 | */ |
| 1921 | static struct nfs4_state * |
| 1922 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1923 | { |
| 1924 | struct inode *inode = data->state->inode; |
| 1925 | struct nfs4_state *state = data->state; |
| 1926 | int ret; |
| 1927 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1928 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1929 | if (data->rpc_status) |
| 1930 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1931 | /* cached opens have already been processed */ |
| 1932 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1933 | } |
| 1934 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1935 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1936 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1937 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1938 | |
| 1939 | if (data->o_res.delegation_type != 0) |
| 1940 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1941 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1942 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1943 | NULL, data->o_arg.fmode)) |
| 1944 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1945 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1946 | |
| 1947 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1948 | } |
| 1949 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1950 | static struct inode * |
| 1951 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1952 | { |
| 1953 | struct inode *inode; |
| 1954 | |
| 1955 | switch (data->o_arg.claim) { |
| 1956 | case NFS4_OPEN_CLAIM_NULL: |
| 1957 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1958 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1959 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1960 | return ERR_PTR(-EAGAIN); |
| 1961 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1962 | &data->f_attr, data->f_label); |
| 1963 | break; |
| 1964 | default: |
| 1965 | inode = d_inode(data->dentry); |
| 1966 | ihold(inode); |
| 1967 | nfs_refresh_inode(inode, &data->f_attr); |
| 1968 | } |
| 1969 | return inode; |
| 1970 | } |
| 1971 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1972 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1973 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1974 | { |
| 1975 | struct nfs4_state *state; |
| 1976 | struct inode *inode; |
| 1977 | |
| 1978 | inode = nfs4_opendata_get_inode(data); |
| 1979 | if (IS_ERR(inode)) |
| 1980 | return ERR_CAST(inode); |
| 1981 | if (data->state != NULL && data->state->inode == inode) { |
| 1982 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1983 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1984 | } else |
| 1985 | state = nfs4_get_open_state(inode, data->owner); |
| 1986 | iput(inode); |
| 1987 | if (state == NULL) |
| 1988 | state = ERR_PTR(-ENOMEM); |
| 1989 | return state; |
| 1990 | } |
| 1991 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1992 | static struct nfs4_state * |
| 1993 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1994 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1995 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1996 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1997 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1998 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1999 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2000 | goto out; |
| 2001 | } |
| 2002 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2003 | state = nfs4_opendata_find_nfs4_state(data); |
| 2004 | if (IS_ERR(state)) |
| 2005 | goto out; |
| 2006 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2007 | if (data->o_res.delegation_type != 0) |
| 2008 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2009 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2010 | NULL, data->o_arg.fmode)) { |
| 2011 | nfs4_put_open_state(state); |
| 2012 | state = ERR_PTR(-EAGAIN); |
| 2013 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2014 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2015 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2016 | return state; |
| 2017 | } |
| 2018 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2019 | static struct nfs4_state * |
| 2020 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2021 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2022 | struct nfs4_state *ret; |
| 2023 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2024 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2025 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2026 | else |
| 2027 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2028 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2029 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2030 | } |
| 2031 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2032 | static struct nfs_open_context * |
| 2033 | 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] | 2034 | { |
| 2035 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2036 | struct nfs_open_context *ctx; |
| 2037 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2038 | rcu_read_lock(); |
| 2039 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2040 | if (ctx->state != state) |
| 2041 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2042 | if ((ctx->mode & mode) != mode) |
| 2043 | continue; |
| 2044 | if (!get_nfs_open_context(ctx)) |
| 2045 | continue; |
| 2046 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2047 | return ctx; |
| 2048 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2049 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2050 | return ERR_PTR(-ENOENT); |
| 2051 | } |
| 2052 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2053 | static struct nfs_open_context * |
| 2054 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2055 | { |
| 2056 | struct nfs_open_context *ctx; |
| 2057 | |
| 2058 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2059 | if (!IS_ERR(ctx)) |
| 2060 | return ctx; |
| 2061 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2062 | if (!IS_ERR(ctx)) |
| 2063 | return ctx; |
| 2064 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2065 | } |
| 2066 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2067 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2068 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2069 | { |
| 2070 | struct nfs4_opendata *opendata; |
| 2071 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2072 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2073 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2074 | if (opendata == NULL) |
| 2075 | return ERR_PTR(-ENOMEM); |
| 2076 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2077 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2078 | return opendata; |
| 2079 | } |
| 2080 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2081 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2082 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2083 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2084 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2085 | int ret; |
| 2086 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2087 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2088 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2089 | opendata->o_arg.open_flags = 0; |
| 2090 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2091 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2092 | NFS_SB(opendata->dentry->d_sb), |
| 2093 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2094 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2095 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2096 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2097 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2098 | if (ret != 0) |
| 2099 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2100 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2101 | if (IS_ERR(newstate)) |
| 2102 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2103 | if (newstate != opendata->state) |
| 2104 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2105 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2106 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2110 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2111 | int ret; |
| 2112 | |
| 2113 | /* memory barrier prior to reading state->n_* */ |
| 2114 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2115 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2116 | if (ret != 0) |
| 2117 | return ret; |
| 2118 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2119 | if (ret != 0) |
| 2120 | return ret; |
| 2121 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2122 | if (ret != 0) |
| 2123 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2124 | /* |
| 2125 | * We may have performed cached opens for all three recoveries. |
| 2126 | * Check if we need to update the current stateid. |
| 2127 | */ |
| 2128 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2129 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2130 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2131 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2132 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2133 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2134 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2135 | return 0; |
| 2136 | } |
| 2137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | /* |
| 2139 | * OPEN_RECLAIM: |
| 2140 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2142 | 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] | 2143 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2144 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2145 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2146 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | int status; |
| 2148 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2149 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2150 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2151 | if (IS_ERR(opendata)) |
| 2152 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2153 | rcu_read_lock(); |
| 2154 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2155 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2156 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2157 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2158 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2159 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2160 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | return status; |
| 2162 | } |
| 2163 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2164 | 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] | 2165 | { |
| 2166 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2167 | struct nfs4_exception exception = { }; |
| 2168 | int err; |
| 2169 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2170 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2171 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2172 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2173 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2174 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2175 | break; |
| 2176 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } while (exception.retry); |
| 2178 | return err; |
| 2179 | } |
| 2180 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2181 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2182 | { |
| 2183 | struct nfs_open_context *ctx; |
| 2184 | int ret; |
| 2185 | |
| 2186 | ctx = nfs4_state_find_open_context(state); |
| 2187 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2188 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2189 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2190 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2191 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2192 | put_nfs_open_context(ctx); |
| 2193 | return ret; |
| 2194 | } |
| 2195 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2196 | 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] | 2197 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2198 | switch (err) { |
| 2199 | default: |
| 2200 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2201 | "%d.\n", __func__, err); |
| 2202 | case 0: |
| 2203 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2204 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2205 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2206 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2207 | break; |
| 2208 | case -NFS4ERR_BADSESSION: |
| 2209 | case -NFS4ERR_BADSLOT: |
| 2210 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2211 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2212 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2213 | return -EAGAIN; |
| 2214 | case -NFS4ERR_STALE_CLIENTID: |
| 2215 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2216 | /* Don't recall a delegation if it was lost */ |
| 2217 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2218 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2219 | case -NFS4ERR_MOVED: |
| 2220 | nfs4_schedule_migration_recovery(server); |
| 2221 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2222 | case -NFS4ERR_LEASE_MOVED: |
| 2223 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2224 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2225 | case -NFS4ERR_DELEG_REVOKED: |
| 2226 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2227 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2228 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2229 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2230 | nfs_inode_find_state_and_recover(state->inode, |
| 2231 | stateid); |
| 2232 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2233 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2234 | case -NFS4ERR_DELAY: |
| 2235 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2236 | ssleep(1); |
| 2237 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2238 | case -ENOMEM: |
| 2239 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2240 | if (fl) { |
| 2241 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2242 | if (lsp) |
| 2243 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2244 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2245 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | return err; |
| 2248 | } |
| 2249 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2250 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2251 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2252 | { |
| 2253 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2254 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2255 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2256 | |
| 2257 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2258 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2259 | if (IS_ERR(opendata)) |
| 2260 | return PTR_ERR(opendata); |
| 2261 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2262 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2263 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2264 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2265 | goto out; |
| 2266 | } |
| 2267 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2268 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2269 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2270 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2271 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2272 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2273 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2274 | if (err) |
| 2275 | goto out; |
| 2276 | } |
| 2277 | nfs_state_clear_delegation(state); |
| 2278 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2279 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2280 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2283 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2284 | { |
| 2285 | struct nfs4_opendata *data = calldata; |
| 2286 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2287 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2288 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2289 | } |
| 2290 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2291 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2292 | { |
| 2293 | struct nfs4_opendata *data = calldata; |
| 2294 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2295 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2296 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2297 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2298 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2299 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2300 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2301 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2302 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2303 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | static void nfs4_open_confirm_release(void *calldata) |
| 2307 | { |
| 2308 | struct nfs4_opendata *data = calldata; |
| 2309 | struct nfs4_state *state = NULL; |
| 2310 | |
| 2311 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2312 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2313 | goto out_free; |
| 2314 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2315 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2316 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2317 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2318 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2319 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2320 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2321 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2325 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2326 | .rpc_call_done = nfs4_open_confirm_done, |
| 2327 | .rpc_release = nfs4_open_confirm_release, |
| 2328 | }; |
| 2329 | |
| 2330 | /* |
| 2331 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2332 | */ |
| 2333 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2334 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2335 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2336 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2337 | struct rpc_message msg = { |
| 2338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2339 | .rpc_argp = &data->c_arg, |
| 2340 | .rpc_resp = &data->c_res, |
| 2341 | .rpc_cred = data->owner->so_cred, |
| 2342 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2343 | struct rpc_task_setup task_setup_data = { |
| 2344 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2345 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2346 | .callback_ops = &nfs4_open_confirm_ops, |
| 2347 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2348 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2349 | .flags = RPC_TASK_ASYNC, |
| 2350 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | int status; |
| 2352 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2353 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2354 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2355 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2356 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2357 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2358 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2359 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2360 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2361 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2362 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2363 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2364 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2365 | smp_wmb(); |
| 2366 | } else |
| 2367 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2368 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | return status; |
| 2370 | } |
| 2371 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2372 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2374 | struct nfs4_opendata *data = calldata; |
| 2375 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2376 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2377 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2378 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2379 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2380 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2381 | /* |
| 2382 | * Check if we still need to send an OPEN call, or if we can use |
| 2383 | * a delegation instead. |
| 2384 | */ |
| 2385 | if (data->state != NULL) { |
| 2386 | struct nfs_delegation *delegation; |
| 2387 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2388 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2389 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2390 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2391 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2392 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2393 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2394 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2395 | rcu_read_unlock(); |
| 2396 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2397 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2398 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2399 | switch (claim) { |
| 2400 | default: |
| 2401 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2402 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2403 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2404 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2405 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 2406 | /* Fall through */ |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2407 | case NFS4_OPEN_CLAIM_FH: |
| 2408 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2409 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2410 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2411 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2412 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2413 | &data->o_res.seq_res, |
| 2414 | task) != 0) |
| 2415 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2416 | |
| 2417 | /* Set the create mode (note dependency on the session type) */ |
| 2418 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2419 | if (data->o_arg.open_flags & O_EXCL) { |
| 2420 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2421 | if (nfs4_has_persistent_session(clp)) |
| 2422 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2423 | else if (clp->cl_mvops->minor_version > 0) |
| 2424 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2425 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2426 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2427 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2428 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2429 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2430 | out_no_action: |
| 2431 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2432 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2433 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2434 | } |
| 2435 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2436 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2437 | { |
| 2438 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2440 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2441 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2442 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2443 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2444 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2445 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2446 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2447 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2448 | case S_IFREG: |
| 2449 | break; |
| 2450 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2451 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2452 | break; |
| 2453 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2454 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2455 | break; |
| 2456 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2457 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2458 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2459 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2460 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2461 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2462 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2463 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2464 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2465 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2466 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2467 | static void nfs4_open_release(void *calldata) |
| 2468 | { |
| 2469 | struct nfs4_opendata *data = calldata; |
| 2470 | struct nfs4_state *state = NULL; |
| 2471 | |
| 2472 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2473 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2474 | goto out_free; |
| 2475 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2476 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2477 | goto out_free; |
| 2478 | /* In case we need an open_confirm, no cleanup! */ |
| 2479 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2480 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2481 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2482 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2483 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2484 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2485 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2489 | .rpc_call_prepare = nfs4_open_prepare, |
| 2490 | .rpc_call_done = nfs4_open_done, |
| 2491 | .rpc_release = nfs4_open_release, |
| 2492 | }; |
| 2493 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2494 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2495 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2496 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2497 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2498 | struct nfs_server *server = NFS_SERVER(dir); |
| 2499 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2500 | struct nfs_openres *o_res = &data->o_res; |
| 2501 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2502 | struct rpc_message msg = { |
| 2503 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2504 | .rpc_argp = o_arg, |
| 2505 | .rpc_resp = o_res, |
| 2506 | .rpc_cred = data->owner->so_cred, |
| 2507 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2508 | struct rpc_task_setup task_setup_data = { |
| 2509 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2510 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2511 | .callback_ops = &nfs4_open_ops, |
| 2512 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2513 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2514 | .flags = RPC_TASK_ASYNC, |
| 2515 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2516 | int status; |
| 2517 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2518 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2519 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2520 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2521 | data->cancelled = false; |
| 2522 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2523 | if (!ctx) { |
| 2524 | 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] | 2525 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2526 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2527 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2528 | 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] | 2529 | pnfs_lgopen_prepare(data, ctx); |
| 2530 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2531 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2532 | if (IS_ERR(task)) |
| 2533 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2534 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2535 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2536 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2537 | smp_wmb(); |
| 2538 | } else |
| 2539 | status = data->rpc_status; |
| 2540 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2541 | |
| 2542 | return status; |
| 2543 | } |
| 2544 | |
| 2545 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2546 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2547 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2548 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2549 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2550 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2551 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2552 | if (status != 0 || !data->rpc_done) |
| 2553 | return status; |
| 2554 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2555 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2556 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2557 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2558 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2559 | |
| 2560 | return status; |
| 2561 | } |
| 2562 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2563 | /* |
| 2564 | * Additional permission checks in order to distinguish between an |
| 2565 | * open for read, and an open for execute. This works around the |
| 2566 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2567 | * the same. |
| 2568 | * Note that in the non-execute case, we want to turn off permission |
| 2569 | * checking if we just created a new file (POSIX open() semantics). |
| 2570 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2571 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2572 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2573 | struct nfs4_state *state, fmode_t fmode, |
| 2574 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2575 | { |
| 2576 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2577 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2578 | |
| 2579 | /* access call failed or for some reason the server doesn't |
| 2580 | * support any access modes -- defer access call until later */ |
| 2581 | if (opendata->o_res.access_supported == 0) |
| 2582 | return 0; |
| 2583 | |
| 2584 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2585 | /* |
| 2586 | * Use openflags to check for exec, because fmode won't |
| 2587 | * always have FMODE_EXEC set when file open for exec. |
| 2588 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2589 | if (openflags & __FMODE_EXEC) { |
| 2590 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2591 | if (S_ISDIR(state->inode->i_mode)) |
| 2592 | mask = NFS4_ACCESS_LOOKUP; |
| 2593 | else |
| 2594 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2595 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2596 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2597 | |
| 2598 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2599 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2600 | nfs_access_add_cache(state->inode, &cache); |
| 2601 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2602 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2603 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2604 | return 0; |
| 2605 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2606 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2607 | } |
| 2608 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2609 | /* |
| 2610 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2611 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2612 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2613 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2614 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2615 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2616 | struct nfs_server *server = NFS_SERVER(dir); |
| 2617 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2618 | struct nfs_openres *o_res = &data->o_res; |
| 2619 | int status; |
| 2620 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2621 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2622 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2623 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2624 | if (status != 0) { |
| 2625 | if (status == -NFS4ERR_BADNAME && |
| 2626 | !(o_arg->open_flags & O_CREAT)) |
| 2627 | return -ENOENT; |
| 2628 | return status; |
| 2629 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2630 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2631 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2632 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2633 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2634 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2635 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2636 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2637 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2638 | if (data->file_created || |
| 2639 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2640 | update_changeattr(dir, &o_res->cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 2641 | o_res->f_attr->time_start, 0); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2642 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2643 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2644 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2646 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2648 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2650 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2651 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2652 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2653 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2654 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2655 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | /* |
| 2659 | * OPEN_EXPIRED: |
| 2660 | * reclaim state on the server after a network partition. |
| 2661 | * Assumes caller holds the appropriate lock |
| 2662 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2663 | 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] | 2664 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2665 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2666 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2668 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2669 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2670 | if (IS_ERR(opendata)) |
| 2671 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2672 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2673 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2674 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2675 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2676 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2679 | 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] | 2680 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2681 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2682 | struct nfs4_exception exception = { }; |
| 2683 | int err; |
| 2684 | |
| 2685 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2686 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2687 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2688 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2689 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2690 | switch (err) { |
| 2691 | default: |
| 2692 | goto out; |
| 2693 | case -NFS4ERR_GRACE: |
| 2694 | case -NFS4ERR_DELAY: |
| 2695 | nfs4_handle_exception(server, err, &exception); |
| 2696 | err = 0; |
| 2697 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2698 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2699 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2700 | return err; |
| 2701 | } |
| 2702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2704 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2706 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2708 | ctx = nfs4_state_find_open_context(state); |
| 2709 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2710 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2711 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2712 | put_nfs_open_context(ctx); |
| 2713 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2716 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2717 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2718 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2719 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2720 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2724 | { |
| 2725 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2726 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2730 | { |
| 2731 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2732 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2733 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2734 | return nfs4_open_expired(sp, state); |
| 2735 | } |
| 2736 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2737 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2738 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2739 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2740 | { |
| 2741 | return -NFS4ERR_BAD_STATEID; |
| 2742 | } |
| 2743 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2744 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2745 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2746 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2747 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2748 | { |
| 2749 | int status; |
| 2750 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2751 | switch (stateid->type) { |
| 2752 | default: |
| 2753 | break; |
| 2754 | case NFS4_INVALID_STATEID_TYPE: |
| 2755 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2756 | return -NFS4ERR_BAD_STATEID; |
| 2757 | case NFS4_REVOKED_STATEID_TYPE: |
| 2758 | goto out_free; |
| 2759 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2760 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2761 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2762 | switch (status) { |
| 2763 | case -NFS4ERR_EXPIRED: |
| 2764 | case -NFS4ERR_ADMIN_REVOKED: |
| 2765 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2766 | break; |
| 2767 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2768 | return status; |
| 2769 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2770 | out_free: |
| 2771 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2772 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2773 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2774 | } |
| 2775 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2776 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2777 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2778 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2779 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2780 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2781 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2782 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2783 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2784 | /* Get the delegation credential for use by test/free_stateid */ |
| 2785 | rcu_read_lock(); |
| 2786 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2787 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2788 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2789 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2790 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2794 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2795 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2796 | &delegation->flags)) { |
| 2797 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2798 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2799 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2800 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2801 | if (delegation->cred) |
| 2802 | cred = get_cred(delegation->cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2803 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2804 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2805 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2806 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2807 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2808 | else |
| 2809 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2810 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2811 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2812 | return ret; |
| 2813 | } |
| 2814 | |
| 2815 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2816 | { |
| 2817 | nfs4_stateid tmp; |
| 2818 | |
| 2819 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2820 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2821 | &tmp, NULL) && |
| 2822 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2823 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2824 | else |
| 2825 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2829 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2830 | * |
| 2831 | * @state: NFSv4 state for an inode |
| 2832 | * |
| 2833 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2834 | * Otherwise a negative NFS4ERR value is returned. |
| 2835 | */ |
| 2836 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2837 | { |
| 2838 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2839 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2840 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2841 | |
| 2842 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2843 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2844 | |
| 2845 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2846 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2847 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2848 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2849 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2850 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2851 | spin_unlock(&state->state_lock); |
| 2852 | |
| 2853 | nfs4_put_lock_state(prev); |
| 2854 | prev = lsp; |
| 2855 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2856 | status = nfs41_test_and_free_expired_stateid(server, |
| 2857 | &lsp->ls_stateid, |
| 2858 | cred); |
| 2859 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2860 | if (status == -NFS4ERR_EXPIRED || |
| 2861 | status == -NFS4ERR_BAD_STATEID) { |
| 2862 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2863 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2864 | if (!recover_lost_locks) |
| 2865 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2866 | } else if (status != NFS_OK) { |
| 2867 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2868 | nfs4_put_lock_state(prev); |
| 2869 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2870 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2871 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2872 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2873 | } |
| 2874 | spin_unlock(&state->state_lock); |
| 2875 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2876 | out: |
| 2877 | return ret; |
| 2878 | } |
| 2879 | |
| 2880 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2881 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2882 | * |
| 2883 | * @state: NFSv4 state for an inode |
| 2884 | * |
| 2885 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2886 | * Otherwise a negative NFS4ERR value is returned. |
| 2887 | */ |
| 2888 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2889 | { |
| 2890 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2891 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2892 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2893 | int status; |
| 2894 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2895 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2896 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2897 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2898 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2899 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2900 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2901 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2902 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2903 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2904 | if (nfs_open_stateid_recover_openmode(state)) |
| 2905 | return -NFS4ERR_OPENMODE; |
| 2906 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2910 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2911 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2912 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2913 | status = nfs41_check_delegation_stateid(state); |
| 2914 | if (status != NFS_OK) |
| 2915 | return status; |
| 2916 | nfs41_delegation_recover_stateid(state); |
| 2917 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2918 | status = nfs41_check_expired_locks(state); |
| 2919 | if (status != NFS_OK) |
| 2920 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2921 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2922 | if (status != NFS_OK) |
| 2923 | status = nfs4_open_expired(sp, state); |
| 2924 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2925 | } |
| 2926 | #endif |
| 2927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2929 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2930 | * fields corresponding to attributes that were used to store the verifier. |
| 2931 | * Make sure we clobber those fields in the later setattr call |
| 2932 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2933 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2934 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2935 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2936 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2937 | __u32 attrset[3]; |
| 2938 | unsigned ret; |
| 2939 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2940 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2941 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2942 | attrset[i] = opendata->o_res.attrset[i]; |
| 2943 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2944 | attrset[i] &= ~bitmask[i]; |
| 2945 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2946 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2947 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2948 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2949 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2950 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2951 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2952 | ret |= ATTR_ATIME_SET; |
| 2953 | else |
| 2954 | ret |= ATTR_ATIME; |
| 2955 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2956 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2957 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2958 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2959 | ret |= ATTR_MTIME_SET; |
| 2960 | else |
| 2961 | ret |= ATTR_MTIME; |
| 2962 | } |
| 2963 | |
| 2964 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2965 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2966 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2967 | } |
| 2968 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2969 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 2970 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2971 | { |
| 2972 | struct nfs4_state_owner *sp = opendata->owner; |
| 2973 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2974 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2975 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 2976 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2977 | unsigned int seq; |
| 2978 | int ret; |
| 2979 | |
| 2980 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2981 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2982 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2983 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2984 | goto out; |
| 2985 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2986 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2987 | ret = PTR_ERR(state); |
| 2988 | if (IS_ERR(state)) |
| 2989 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2990 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2991 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2992 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2993 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2994 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2995 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2996 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2997 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2998 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2999 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3000 | alias = d_exact_alias(dentry, state->inode); |
| 3001 | if (!alias) |
| 3002 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3003 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3004 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3005 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3006 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3007 | } |
| 3008 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3009 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3010 | } |
| 3011 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3012 | /* Parse layoutget results before we check for access */ |
| 3013 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3014 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3015 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3016 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3017 | if (ret != 0) |
| 3018 | goto out; |
| 3019 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3020 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3021 | nfs_inode_attach_open_context(ctx); |
| 3022 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3023 | nfs4_schedule_stateid_recovery(server, state); |
| 3024 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3025 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3026 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3027 | if (!opendata->cancelled) |
| 3028 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3029 | return ret; |
| 3030 | } |
| 3031 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3032 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3033 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3035 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3036 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3037 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3038 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3039 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | { |
| 3041 | struct nfs4_state_owner *sp; |
| 3042 | struct nfs4_state *state = NULL; |
| 3043 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3044 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3045 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3046 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3047 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3048 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3049 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3050 | struct iattr *sattr = c->sattr; |
| 3051 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3052 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3053 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | |
| 3055 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3057 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3058 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3060 | goto out_err; |
| 3061 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3062 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3063 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3064 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3065 | if (d_really_is_positive(dentry)) |
| 3066 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3067 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3068 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3069 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3070 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3071 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3072 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3073 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3075 | if (label) { |
| 3076 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 3077 | if (IS_ERR(olabel)) { |
| 3078 | status = PTR_ERR(olabel); |
| 3079 | goto err_opendata_put; |
| 3080 | } |
| 3081 | } |
| 3082 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3083 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3084 | if (!opendata->f_attr.mdsthreshold) { |
| 3085 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3086 | if (!opendata->f_attr.mdsthreshold) |
| 3087 | goto err_free_label; |
| 3088 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3089 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3090 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3091 | if (d_really_is_positive(dentry)) |
| 3092 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3093 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3094 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3095 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3096 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3097 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3098 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3099 | 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] | 3100 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3101 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3102 | /* |
| 3103 | * send create attributes which was not set by open |
| 3104 | * with an extra setattr. |
| 3105 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3106 | if (attrs || label) { |
| 3107 | unsigned ia_old = sattr->ia_valid; |
| 3108 | |
| 3109 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3110 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3111 | status = nfs4_do_setattr(state->inode, cred, |
| 3112 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3113 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3114 | if (status == 0) { |
| 3115 | nfs_setattr_update_inode(state->inode, sattr, |
| 3116 | opendata->o_res.f_attr); |
| 3117 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 3118 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3119 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3120 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3121 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3122 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3123 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3124 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3125 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3126 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3127 | opendata->f_attr.mdsthreshold = NULL; |
| 3128 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3129 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3130 | nfs4_label_free(olabel); |
| 3131 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3132 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3135 | err_free_label: |
| 3136 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3137 | err_opendata_put: |
| 3138 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3139 | err_put_state_owner: |
| 3140 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | return status; |
| 3143 | } |
| 3144 | |
| 3145 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3146 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3147 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3148 | int flags, |
| 3149 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3150 | struct nfs4_label *label, |
| 3151 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3153 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3154 | struct nfs4_exception exception = { |
| 3155 | .interruptible = true, |
| 3156 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3158 | struct nfs4_open_createattrs c = { |
| 3159 | .label = label, |
| 3160 | .sattr = sattr, |
| 3161 | .verf = { |
| 3162 | [0] = (__u32)jiffies, |
| 3163 | [1] = (__u32)current->pid, |
| 3164 | }, |
| 3165 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | int status; |
| 3167 | |
| 3168 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3169 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3170 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3171 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | if (status == 0) |
| 3173 | break; |
| 3174 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3175 | * book-keeping w.r.t. state-changing operations |
| 3176 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3177 | * It is actually a sign of a bug on the client or on the server. |
| 3178 | * |
| 3179 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3180 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | * have unhashed the old state_owner for us, and that we can |
| 3182 | * therefore safely retry using a new one. We should still warn |
| 3183 | * the user though... |
| 3184 | */ |
| 3185 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3186 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3187 | " returned a bad sequence-id error!\n", |
| 3188 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | exception.retry = 1; |
| 3190 | continue; |
| 3191 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3192 | /* |
| 3193 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3194 | * state before it received the OPEN_CONFIRM. |
| 3195 | * Recover by retrying the request as per the discussion |
| 3196 | * on Page 181 of RFC3530. |
| 3197 | */ |
| 3198 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3199 | exception.retry = 1; |
| 3200 | continue; |
| 3201 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame^] | 3202 | if (status == -NFS4ERR_EXPIRED) { |
| 3203 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3204 | exception.retry = 1; |
| 3205 | continue; |
| 3206 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3207 | if (status == -EAGAIN) { |
| 3208 | /* We must have found a delegation */ |
| 3209 | exception.retry = 1; |
| 3210 | continue; |
| 3211 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3212 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3213 | continue; |
| 3214 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | status, &exception)); |
| 3216 | } while (exception.retry); |
| 3217 | return res; |
| 3218 | } |
| 3219 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3220 | static int _nfs4_do_setattr(struct inode *inode, |
| 3221 | struct nfs_setattrargs *arg, |
| 3222 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3223 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3224 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3225 | { |
| 3226 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3227 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3228 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3229 | .rpc_argp = arg, |
| 3230 | .rpc_resp = res, |
| 3231 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3232 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3233 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3234 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3235 | bool truncate; |
| 3236 | int status; |
| 3237 | |
| 3238 | nfs_fattr_init(res->fattr); |
| 3239 | |
| 3240 | /* Servers should only apply open mode checks for file size changes */ |
| 3241 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3242 | if (!truncate) |
| 3243 | goto zero_stateid; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3244 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3245 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3246 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3247 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3248 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3249 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3250 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3251 | l_ctx = nfs_get_lock_context(ctx); |
| 3252 | if (IS_ERR(l_ctx)) |
| 3253 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3254 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3255 | &arg->stateid, &delegation_cred); |
| 3256 | nfs_put_lock_context(l_ctx); |
| 3257 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3258 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3259 | else if (status == -EAGAIN) |
| 3260 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3261 | } else { |
| 3262 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3263 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3264 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3265 | if (delegation_cred) |
| 3266 | msg.rpc_cred = delegation_cred; |
| 3267 | |
| 3268 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3269 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3270 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3271 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3272 | renew_lease(server, timestamp); |
| 3273 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3274 | return status; |
| 3275 | } |
| 3276 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3277 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3278 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3279 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3280 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3282 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3283 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3284 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3285 | struct nfs_setattrargs arg = { |
| 3286 | .fh = NFS_FH(inode), |
| 3287 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3289 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3290 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3291 | }; |
| 3292 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3294 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3296 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3297 | struct nfs4_exception exception = { |
| 3298 | .state = state, |
| 3299 | .inode = inode, |
| 3300 | .stateid = &arg.stateid, |
| 3301 | }; |
| 3302 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3305 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3306 | nfs4_bitmask(server, olabel), |
| 3307 | inode); |
| 3308 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3309 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3310 | switch (err) { |
| 3311 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3312 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3313 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3314 | "applying open mode checks to " |
| 3315 | "a SETATTR that is not " |
| 3316 | "changing file size.\n", |
| 3317 | server->nfs_client->cl_hostname); |
| 3318 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3319 | if (state && !(state->state & FMODE_WRITE)) { |
| 3320 | err = -EBADF; |
| 3321 | if (sattr->ia_valid & ATTR_OPEN) |
| 3322 | err = -EACCES; |
| 3323 | goto out; |
| 3324 | } |
| 3325 | } |
| 3326 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3328 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | return err; |
| 3330 | } |
| 3331 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3332 | static bool |
| 3333 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3334 | { |
| 3335 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3336 | return false; |
| 3337 | |
| 3338 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3339 | } |
| 3340 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3341 | /* |
| 3342 | * Update the seqid of an open stateid |
| 3343 | */ |
| 3344 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3345 | struct nfs4_state *state) |
| 3346 | { |
| 3347 | __be32 seqid_open; |
| 3348 | u32 dst_seqid; |
| 3349 | int seq; |
| 3350 | |
| 3351 | for (;;) { |
| 3352 | if (!nfs4_valid_open_stateid(state)) |
| 3353 | break; |
| 3354 | seq = read_seqbegin(&state->seqlock); |
| 3355 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3356 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3357 | if (read_seqretry(&state->seqlock, seq)) |
| 3358 | continue; |
| 3359 | break; |
| 3360 | } |
| 3361 | seqid_open = state->open_stateid.seqid; |
| 3362 | if (read_seqretry(&state->seqlock, seq)) |
| 3363 | continue; |
| 3364 | |
| 3365 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3366 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3367 | dst->seqid = seqid_open; |
| 3368 | break; |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | /* |
| 3373 | * Update the seqid of an open stateid after receiving |
| 3374 | * NFS4ERR_OLD_STATEID |
| 3375 | */ |
| 3376 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3377 | struct nfs4_state *state) |
| 3378 | { |
| 3379 | __be32 seqid_open; |
| 3380 | u32 dst_seqid; |
| 3381 | bool ret; |
| 3382 | int seq; |
| 3383 | |
| 3384 | for (;;) { |
| 3385 | ret = false; |
| 3386 | if (!nfs4_valid_open_stateid(state)) |
| 3387 | break; |
| 3388 | seq = read_seqbegin(&state->seqlock); |
| 3389 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3390 | if (read_seqretry(&state->seqlock, seq)) |
| 3391 | continue; |
| 3392 | break; |
| 3393 | } |
| 3394 | seqid_open = state->open_stateid.seqid; |
| 3395 | if (read_seqretry(&state->seqlock, seq)) |
| 3396 | continue; |
| 3397 | |
| 3398 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3399 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) >= 0) |
| 3400 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
| 3401 | else |
| 3402 | dst->seqid = seqid_open; |
| 3403 | ret = true; |
| 3404 | break; |
| 3405 | } |
| 3406 | |
| 3407 | return ret; |
| 3408 | } |
| 3409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | struct nfs4_closedata { |
| 3411 | struct inode *inode; |
| 3412 | struct nfs4_state *state; |
| 3413 | struct nfs_closeargs arg; |
| 3414 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3415 | struct { |
| 3416 | struct nfs4_layoutreturn_args arg; |
| 3417 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3418 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3419 | u32 roc_barrier; |
| 3420 | bool roc; |
| 3421 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3422 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3423 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | }; |
| 3425 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3426 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3427 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3428 | struct nfs4_closedata *calldata = data; |
| 3429 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3430 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3431 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3432 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3433 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3434 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3435 | nfs4_put_open_state(calldata->state); |
| 3436 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3437 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3438 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3439 | kfree(calldata); |
| 3440 | } |
| 3441 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3442 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3444 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3447 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3448 | struct nfs4_exception exception = { |
| 3449 | .state = state, |
| 3450 | .inode = calldata->inode, |
| 3451 | .stateid = &calldata->arg.stateid, |
| 3452 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3454 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3455 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3456 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3457 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3458 | |
| 3459 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3460 | if (pnfs_roc_done(task, calldata->inode, |
| 3461 | &calldata->arg.lr_args, |
| 3462 | &calldata->res.lr_res, |
| 3463 | &calldata->res.lr_ret) == -EAGAIN) |
| 3464 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3465 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3466 | /* 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] | 3467 | * the state_owner. we keep this around to process errors |
| 3468 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | switch (task->tk_status) { |
| 3470 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3471 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3472 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3473 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3474 | case -NFS4ERR_ACCESS: |
| 3475 | if (calldata->arg.bitmask != NULL) { |
| 3476 | calldata->arg.bitmask = NULL; |
| 3477 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3478 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3479 | |
| 3480 | } |
| 3481 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3482 | case -NFS4ERR_OLD_STATEID: |
| 3483 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3484 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3485 | state)) |
| 3486 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3487 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3488 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3490 | case -NFS4ERR_EXPIRED: |
| 3491 | nfs4_free_revoked_stateid(server, |
| 3492 | &calldata->arg.stateid, |
| 3493 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3494 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3495 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3496 | if (calldata->arg.fmode == 0) |
| 3497 | break; |
| 3498 | /* Fallthrough */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3500 | task->tk_status = nfs4_async_handle_exception(task, |
| 3501 | server, task->tk_status, &exception); |
| 3502 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3503 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3505 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3506 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3507 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3508 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3509 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3510 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3511 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3512 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3513 | out_restart: |
| 3514 | task->tk_status = 0; |
| 3515 | rpc_restart_call_prepare(task); |
| 3516 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3519 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3521 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3522 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3523 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3524 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3525 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3526 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3527 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3528 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3529 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3530 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3531 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3532 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3533 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3534 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3535 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3536 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3537 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3538 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3539 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3540 | if (state->n_rdonly == 0) |
| 3541 | call_close |= is_rdonly; |
| 3542 | else if (is_rdonly) |
| 3543 | calldata->arg.fmode |= FMODE_READ; |
| 3544 | if (state->n_wronly == 0) |
| 3545 | call_close |= is_wronly; |
| 3546 | else if (is_wronly) |
| 3547 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3548 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3549 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3550 | } else if (is_rdwr) |
| 3551 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3552 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3553 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3554 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3555 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3556 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3557 | |
| 3558 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3559 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3560 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3561 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3562 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3563 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3564 | nfs_release_seqid(calldata->arg.seqid); |
| 3565 | goto out_wait; |
| 3566 | } |
| 3567 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3568 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3569 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3570 | calldata->arg.lr_args = NULL; |
| 3571 | calldata->res.lr_res = NULL; |
| 3572 | } |
| 3573 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3574 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3575 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3576 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3577 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3578 | /* Close-to-open cache consistency revalidation */ |
| 3579 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3580 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3581 | else |
| 3582 | calldata->arg.bitmask = NULL; |
| 3583 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3584 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3585 | calldata->arg.share_access = |
| 3586 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3587 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3588 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3589 | if (calldata->res.fattr == NULL) |
| 3590 | calldata->arg.bitmask = NULL; |
| 3591 | else if (calldata->arg.bitmask == NULL) |
| 3592 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3593 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3594 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3595 | &calldata->arg.seq_args, |
| 3596 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3597 | task) != 0) |
| 3598 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3599 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3600 | return; |
| 3601 | out_no_action: |
| 3602 | task->tk_action = NULL; |
| 3603 | out_wait: |
| 3604 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3607 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3608 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3609 | .rpc_call_done = nfs4_close_done, |
| 3610 | .rpc_release = nfs4_free_closedata, |
| 3611 | }; |
| 3612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | /* |
| 3614 | * It is possible for data to be read/written from a mem-mapped file |
| 3615 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3616 | * This means that we can't safely call nfsv4 close on a file until |
| 3617 | * the inode is cleared. This in turn means that we are not good |
| 3618 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3619 | * share state even when we are done with one of the three share |
| 3620 | * stateid's in the inode. |
| 3621 | * |
| 3622 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3623 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3624 | 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] | 3625 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3626 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3627 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3629 | struct nfs4_state_owner *sp = state->owner; |
| 3630 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3631 | struct rpc_message msg = { |
| 3632 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3633 | .rpc_cred = state->owner->so_cred, |
| 3634 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3635 | struct rpc_task_setup task_setup_data = { |
| 3636 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3637 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3638 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3639 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3640 | .flags = RPC_TASK_ASYNC, |
| 3641 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3642 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3644 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3645 | &task_setup_data.rpc_client, &msg); |
| 3646 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3647 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3649 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3650 | 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] | 3651 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3653 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3654 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3655 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3657 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3658 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3659 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3660 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3661 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3662 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3663 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3664 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3665 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3666 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3667 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3668 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3669 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3670 | if (calldata->lr.roc) { |
| 3671 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3672 | calldata->res.lr_res = &calldata->lr.res; |
| 3673 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3674 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3675 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3676 | msg.rpc_argp = &calldata->arg; |
| 3677 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3678 | task_setup_data.callback_data = calldata; |
| 3679 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3680 | if (IS_ERR(task)) |
| 3681 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3682 | status = 0; |
| 3683 | if (wait) |
| 3684 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3685 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3686 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3687 | out_free_calldata: |
| 3688 | kfree(calldata); |
| 3689 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3690 | nfs4_put_open_state(state); |
| 3691 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3692 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3695 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3696 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3697 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3700 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3701 | |
| 3702 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3704 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3705 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3706 | |
| 3707 | nfs4_label_release_security(label); |
| 3708 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3709 | if (IS_ERR(state)) |
| 3710 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3711 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | } |
| 3713 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3714 | 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] | 3715 | { |
| 3716 | if (ctx->state == NULL) |
| 3717 | return; |
| 3718 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3719 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3720 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3721 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3724 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3725 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3726 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3729 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3730 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3731 | struct nfs4_server_caps_arg args = { |
| 3732 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3733 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3734 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | struct nfs4_server_caps_res res = {}; |
| 3736 | struct rpc_message msg = { |
| 3737 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3738 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | .rpc_resp = &res, |
| 3740 | }; |
| 3741 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3742 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3744 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3745 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3746 | FATTR4_WORD0_LINK_SUPPORT | |
| 3747 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3748 | FATTR4_WORD0_ACLSUPPORT; |
| 3749 | if (minorversion) |
| 3750 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3751 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3752 | 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] | 3753 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3754 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3755 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3756 | case 0: |
| 3757 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3758 | res.attr_bitmask[2] = 0; |
| 3759 | break; |
| 3760 | case 1: |
| 3761 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3762 | break; |
| 3763 | case 2: |
| 3764 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3767 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3768 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3769 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3770 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3771 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3772 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3773 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3774 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | server->caps |= NFS_CAP_ACLS; |
| 3776 | if (res.has_links != 0) |
| 3777 | server->caps |= NFS_CAP_HARDLINKS; |
| 3778 | if (res.has_symlinks != 0) |
| 3779 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3780 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3781 | server->caps |= NFS_CAP_FILEID; |
| 3782 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3783 | server->caps |= NFS_CAP_MODE; |
| 3784 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3785 | server->caps |= NFS_CAP_NLINK; |
| 3786 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3787 | server->caps |= NFS_CAP_OWNER; |
| 3788 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3789 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3790 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3791 | server->caps |= NFS_CAP_ATIME; |
| 3792 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3793 | server->caps |= NFS_CAP_CTIME; |
| 3794 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3795 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3796 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3797 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3798 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3799 | #endif |
| 3800 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3801 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3802 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3803 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3804 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3805 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3806 | 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] | 3807 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3808 | |
| 3809 | /* Avoid a regression due to buggy server */ |
| 3810 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3811 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3812 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3813 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3816 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | return status; |
| 3820 | } |
| 3821 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3822 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3824 | struct nfs4_exception exception = { |
| 3825 | .interruptible = true, |
| 3826 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | int err; |
| 3828 | do { |
| 3829 | err = nfs4_handle_exception(server, |
| 3830 | _nfs4_server_capabilities(server, fhandle), |
| 3831 | &exception); |
| 3832 | } while (exception.retry); |
| 3833 | return err; |
| 3834 | } |
| 3835 | |
| 3836 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3837 | struct nfs_fsinfo *info) |
| 3838 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3839 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3841 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | }; |
| 3843 | struct nfs4_lookup_res res = { |
| 3844 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3845 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | .fh = fhandle, |
| 3847 | }; |
| 3848 | struct rpc_message msg = { |
| 3849 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3850 | .rpc_argp = &args, |
| 3851 | .rpc_resp = &res, |
| 3852 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3853 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3854 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3855 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3856 | /* |
| 3857 | * Process the label in the upcoming getfattr |
| 3858 | */ |
| 3859 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3860 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3861 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3862 | 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] | 3863 | } |
| 3864 | |
| 3865 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3866 | struct nfs_fsinfo *info) |
| 3867 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3868 | struct nfs4_exception exception = { |
| 3869 | .interruptible = true, |
| 3870 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | int err; |
| 3872 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3873 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3874 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3875 | switch (err) { |
| 3876 | case 0: |
| 3877 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3878 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3879 | default: |
| 3880 | err = nfs4_handle_exception(server, err, &exception); |
| 3881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3883 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | return err; |
| 3885 | } |
| 3886 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3887 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3888 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3889 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3890 | struct rpc_auth_create_args auth_args = { |
| 3891 | .pseudoflavor = flavor, |
| 3892 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3893 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3894 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3895 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3896 | if (IS_ERR(auth)) |
| 3897 | return -EACCES; |
| 3898 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3901 | /* |
| 3902 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3903 | * |
| 3904 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3905 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3906 | * |
| 3907 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3908 | * negative errno value. |
| 3909 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3910 | 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] | 3911 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3913 | /* Per 3530bis 15.33.5 */ |
| 3914 | static const rpc_authflavor_t flav_array[] = { |
| 3915 | RPC_AUTH_GSS_KRB5P, |
| 3916 | RPC_AUTH_GSS_KRB5I, |
| 3917 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3918 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3919 | RPC_AUTH_NULL, |
| 3920 | }; |
| 3921 | int status = -EPERM; |
| 3922 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3924 | if (server->auth_info.flavor_len > 0) { |
| 3925 | /* try each flavor specified by user */ |
| 3926 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3927 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3928 | server->auth_info.flavors[i]); |
| 3929 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3930 | continue; |
| 3931 | break; |
| 3932 | } |
| 3933 | } else { |
| 3934 | /* no flavors specified by user, try default list */ |
| 3935 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3936 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3937 | flav_array[i]); |
| 3938 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3939 | continue; |
| 3940 | break; |
| 3941 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3942 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3943 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3944 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 3945 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3946 | * to access the mount. It could also mean that we tried to mount |
| 3947 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3948 | * existing mount programs don't handle -EACCES very well so it should |
| 3949 | * be mapped to -EPERM instead. |
| 3950 | */ |
| 3951 | if (status == -EACCES) |
| 3952 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3953 | return status; |
| 3954 | } |
| 3955 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3956 | /** |
| 3957 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3958 | * @server: initialized nfs_server handle |
| 3959 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3960 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3961 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3962 | * |
| 3963 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3964 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3965 | 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] | 3966 | struct nfs_fsinfo *info, |
| 3967 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3968 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3969 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3970 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3971 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3972 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3973 | |
| 3974 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3975 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3976 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | if (status == 0) |
| 3979 | status = nfs4_server_capabilities(server, fhandle); |
| 3980 | if (status == 0) |
| 3981 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3982 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3983 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3986 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3987 | struct nfs_fsinfo *info) |
| 3988 | { |
| 3989 | int error; |
| 3990 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3991 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3992 | |
| 3993 | error = nfs4_server_capabilities(server, mntfh); |
| 3994 | if (error < 0) { |
| 3995 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3996 | return error; |
| 3997 | } |
| 3998 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3999 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4000 | if (IS_ERR(label)) |
| 4001 | return PTR_ERR(label); |
| 4002 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4003 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4004 | if (error < 0) { |
| 4005 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4006 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4010 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4011 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4012 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4013 | err_free_label: |
| 4014 | nfs4_label_free(label); |
| 4015 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4016 | return error; |
| 4017 | } |
| 4018 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4019 | /* |
| 4020 | * Get locations and (maybe) other attributes of a referral. |
| 4021 | * Note that we'll actually follow the referral later when |
| 4022 | * we detect fsid mismatch in inode revalidation |
| 4023 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4024 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4025 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4026 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4027 | { |
| 4028 | int status = -ENOMEM; |
| 4029 | struct page *page = NULL; |
| 4030 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4031 | |
| 4032 | page = alloc_page(GFP_KERNEL); |
| 4033 | if (page == NULL) |
| 4034 | goto out; |
| 4035 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4036 | if (locations == NULL) |
| 4037 | goto out; |
| 4038 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4039 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4040 | if (status != 0) |
| 4041 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4042 | |
| 4043 | /* |
| 4044 | * If the fsid didn't change, this is a migration event, not a |
| 4045 | * referral. Cause us to drop into the exception handler, which |
| 4046 | * will kick off migration recovery. |
| 4047 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4048 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4049 | dprintk("%s: server did not return a different fsid for" |
| 4050 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4051 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4052 | goto out; |
| 4053 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4054 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4055 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4056 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4057 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4058 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4059 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4060 | out: |
| 4061 | if (page) |
| 4062 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4063 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4064 | return status; |
| 4065 | } |
| 4066 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4067 | 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] | 4068 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4069 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4071 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | struct nfs4_getattr_arg args = { |
| 4073 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4074 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | }; |
| 4076 | struct nfs4_getattr_res res = { |
| 4077 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4078 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | .server = server, |
| 4080 | }; |
| 4081 | struct rpc_message msg = { |
| 4082 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4083 | .rpc_argp = &args, |
| 4084 | .rpc_resp = &res, |
| 4085 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4086 | unsigned short task_flags = 0; |
| 4087 | |
| 4088 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4089 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4090 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4091 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4092 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4093 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4094 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4095 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4096 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4097 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4100 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4101 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4102 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4104 | struct nfs4_exception exception = { |
| 4105 | .interruptible = true, |
| 4106 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | int err; |
| 4108 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4109 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4110 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4111 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | &exception); |
| 4113 | } while (exception.retry); |
| 4114 | return err; |
| 4115 | } |
| 4116 | |
| 4117 | /* |
| 4118 | * The file is not closed if it is opened due to the a request to change |
| 4119 | * the size of the file. The open call will not be needed once the |
| 4120 | * VFS layer lookup-intents are implemented. |
| 4121 | * |
| 4122 | * Close is called when the inode is destroyed. |
| 4123 | * If we haven't opened the file for O_WRONLY, we |
| 4124 | * need to in the size_change case to obtain a stateid. |
| 4125 | * |
| 4126 | * Got race? |
| 4127 | * Because OPEN is always done by name in nfsv4, it is |
| 4128 | * possible that we opened a different file by the same |
| 4129 | * name. We can recognize this race condition, but we |
| 4130 | * can't do anything about it besides returning an error. |
| 4131 | * |
| 4132 | * This will be fixed with VFS changes (lookup-intent). |
| 4133 | */ |
| 4134 | static int |
| 4135 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4136 | struct iattr *sattr) |
| 4137 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4138 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4139 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4140 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4141 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | int status; |
| 4143 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4144 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4145 | sattr->ia_valid & ATTR_SIZE && |
| 4146 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4147 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4148 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4149 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4151 | /* Deal with open(O_TRUNC) */ |
| 4152 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4153 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4154 | |
| 4155 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4156 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4157 | return 0; |
| 4158 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4159 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4160 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4161 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4162 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4163 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4164 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4165 | } |
| 4166 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4167 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4168 | if (IS_ERR(label)) |
| 4169 | return PTR_ERR(label); |
| 4170 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4171 | /* Return any delegations if we're going to change ACLs */ |
| 4172 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4173 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4174 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4175 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4176 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4177 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4178 | nfs_setsecurity(inode, fattr, label); |
| 4179 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4180 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | return status; |
| 4182 | } |
| 4183 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4184 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4185 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4186 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4187 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4188 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4189 | int status; |
| 4190 | struct nfs4_lookup_arg args = { |
| 4191 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4192 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4193 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4194 | }; |
| 4195 | struct nfs4_lookup_res res = { |
| 4196 | .server = server, |
| 4197 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4198 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4199 | .fh = fhandle, |
| 4200 | }; |
| 4201 | struct rpc_message msg = { |
| 4202 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4203 | .rpc_argp = &args, |
| 4204 | .rpc_resp = &res, |
| 4205 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4206 | unsigned short task_flags = 0; |
| 4207 | |
| 4208 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4209 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4210 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4211 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4212 | args.bitmask = nfs4_bitmask(server, label); |
| 4213 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4214 | nfs_fattr_init(fattr); |
| 4215 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4216 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4217 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4218 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4219 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | dprintk("NFS reply lookup: %d\n", status); |
| 4221 | return status; |
| 4222 | } |
| 4223 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4224 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4225 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4226 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4227 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4228 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4229 | fattr->nlink = 2; |
| 4230 | } |
| 4231 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4232 | 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] | 4233 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4234 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4235 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4236 | struct nfs4_exception exception = { |
| 4237 | .interruptible = true, |
| 4238 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4239 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4240 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4241 | int err; |
| 4242 | do { |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4243 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4244 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4245 | switch (err) { |
| 4246 | case -NFS4ERR_BADNAME: |
| 4247 | err = -ENOENT; |
| 4248 | goto out; |
| 4249 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4250 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4251 | if (err == -NFS4ERR_MOVED) |
| 4252 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4253 | goto out; |
| 4254 | case -NFS4ERR_WRONGSEC: |
| 4255 | err = -EPERM; |
| 4256 | if (client != *clnt) |
| 4257 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4258 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4259 | if (IS_ERR(client)) |
| 4260 | return PTR_ERR(client); |
| 4261 | |
| 4262 | exception.retry = 1; |
| 4263 | break; |
| 4264 | default: |
| 4265 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4266 | } |
| 4267 | } while (exception.retry); |
| 4268 | |
| 4269 | out: |
| 4270 | if (err == 0) |
| 4271 | *clnt = client; |
| 4272 | else if (client != *clnt) |
| 4273 | rpc_shutdown_client(client); |
| 4274 | |
| 4275 | return err; |
| 4276 | } |
| 4277 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4278 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4279 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4280 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4282 | int status; |
| 4283 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4284 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4285 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4286 | if (client != NFS_CLIENT(dir)) { |
| 4287 | rpc_shutdown_client(client); |
| 4288 | nfs_fixup_secinfo_attributes(fattr); |
| 4289 | } |
| 4290 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | } |
| 4292 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4293 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4294 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4295 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4296 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4297 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4298 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4299 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4300 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4301 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4302 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4303 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4304 | } |
| 4305 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4306 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4307 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4308 | struct nfs4_label *label) |
| 4309 | { |
| 4310 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4311 | struct nfs_server *server = NFS_SERVER(inode); |
| 4312 | int status; |
| 4313 | struct nfs4_lookupp_arg args = { |
| 4314 | .bitmask = server->attr_bitmask, |
| 4315 | .fh = NFS_FH(inode), |
| 4316 | }; |
| 4317 | struct nfs4_lookupp_res res = { |
| 4318 | .server = server, |
| 4319 | .fattr = fattr, |
| 4320 | .label = label, |
| 4321 | .fh = fhandle, |
| 4322 | }; |
| 4323 | struct rpc_message msg = { |
| 4324 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4325 | .rpc_argp = &args, |
| 4326 | .rpc_resp = &res, |
| 4327 | }; |
| 4328 | |
| 4329 | args.bitmask = nfs4_bitmask(server, label); |
| 4330 | |
| 4331 | nfs_fattr_init(fattr); |
| 4332 | |
| 4333 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4334 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4335 | &res.seq_res, 0); |
| 4336 | dprintk("NFS reply lookupp: %d\n", status); |
| 4337 | return status; |
| 4338 | } |
| 4339 | |
| 4340 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4341 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4342 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4343 | struct nfs4_exception exception = { |
| 4344 | .interruptible = true, |
| 4345 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4346 | int err; |
| 4347 | do { |
| 4348 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4349 | trace_nfs4_lookupp(inode, err); |
| 4350 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4351 | &exception); |
| 4352 | } while (exception.retry); |
| 4353 | return err; |
| 4354 | } |
| 4355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4357 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4358 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | struct nfs4_accessargs args = { |
| 4360 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4361 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4363 | struct nfs4_accessres res = { |
| 4364 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4365 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | struct rpc_message msg = { |
| 4367 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4368 | .rpc_argp = &args, |
| 4369 | .rpc_resp = &res, |
| 4370 | .rpc_cred = entry->cred, |
| 4371 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4372 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4374 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4375 | res.fattr = nfs_alloc_fattr(); |
| 4376 | if (res.fattr == NULL) |
| 4377 | return -ENOMEM; |
| 4378 | args.bitmask = server->cache_consistency_bitmask; |
| 4379 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4380 | 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] | 4381 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4382 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4383 | if (res.fattr) |
| 4384 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4386 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | return status; |
| 4388 | } |
| 4389 | |
| 4390 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4391 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4392 | struct nfs4_exception exception = { |
| 4393 | .interruptible = true, |
| 4394 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | int err; |
| 4396 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4397 | err = _nfs4_proc_access(inode, entry); |
| 4398 | trace_nfs4_access(inode, err); |
| 4399 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | &exception); |
| 4401 | } while (exception.retry); |
| 4402 | return err; |
| 4403 | } |
| 4404 | |
| 4405 | /* |
| 4406 | * TODO: For the time being, we don't try to get any attributes |
| 4407 | * along with any of the zero-copy operations READ, READDIR, |
| 4408 | * READLINK, WRITE. |
| 4409 | * |
| 4410 | * In the case of the first three, we want to put the GETATTR |
| 4411 | * after the read-type operation -- this is because it is hard |
| 4412 | * to predict the length of a GETATTR response in v4, and thus |
| 4413 | * align the READ data correctly. This means that the GETATTR |
| 4414 | * may end up partially falling into the page cache, and we should |
| 4415 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4416 | * To do this efficiently, we need to know the total length |
| 4417 | * of data received, which doesn't seem to be available outside |
| 4418 | * of the RPC layer. |
| 4419 | * |
| 4420 | * In the case of WRITE, we also want to put the GETATTR after |
| 4421 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4422 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | * |
| 4424 | * Both of these changes to the XDR layer would in fact be quite |
| 4425 | * minor, but I decided to leave them for a subsequent patch. |
| 4426 | */ |
| 4427 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4428 | unsigned int pgbase, unsigned int pglen) |
| 4429 | { |
| 4430 | struct nfs4_readlink args = { |
| 4431 | .fh = NFS_FH(inode), |
| 4432 | .pgbase = pgbase, |
| 4433 | .pglen = pglen, |
| 4434 | .pages = &page, |
| 4435 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4436 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | struct rpc_message msg = { |
| 4438 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4439 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4440 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | }; |
| 4442 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4443 | 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] | 4444 | } |
| 4445 | |
| 4446 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4447 | unsigned int pgbase, unsigned int pglen) |
| 4448 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4449 | struct nfs4_exception exception = { |
| 4450 | .interruptible = true, |
| 4451 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | int err; |
| 4453 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4454 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4455 | trace_nfs4_readlink(inode, err); |
| 4456 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | &exception); |
| 4458 | } while (exception.retry); |
| 4459 | return err; |
| 4460 | } |
| 4461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4463 | * 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] | 4464 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | static int |
| 4466 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4467 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4469 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4470 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4471 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | int status = 0; |
| 4474 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4475 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4476 | if (IS_ERR(ctx)) |
| 4477 | return PTR_ERR(ctx); |
| 4478 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4479 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4480 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4481 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4482 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4483 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | if (IS_ERR(state)) { |
| 4485 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4486 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4489 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4490 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | return status; |
| 4492 | } |
| 4493 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4494 | static int |
| 4495 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4497 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4498 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4500 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4502 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4503 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4504 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4506 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4507 | .rpc_argp = &args, |
| 4508 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4510 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4511 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4512 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4513 | 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] | 4514 | if (status == 0) { |
| 4515 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4516 | update_changeattr_locked(dir, &res.cinfo, timestamp, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4517 | /* Removing a directory decrements nlink in the parent */ |
| 4518 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4519 | nfs4_dec_nlink_locked(dir); |
| 4520 | spin_unlock(&dir->i_lock); |
| 4521 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | return status; |
| 4523 | } |
| 4524 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4525 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4526 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4527 | struct nfs4_exception exception = { |
| 4528 | .interruptible = true, |
| 4529 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4530 | struct inode *inode = d_inode(dentry); |
| 4531 | int err; |
| 4532 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4533 | if (inode) { |
| 4534 | if (inode->i_nlink == 1) |
| 4535 | nfs4_inode_return_delegation(inode); |
| 4536 | else |
| 4537 | nfs4_inode_make_writeable(inode); |
| 4538 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4539 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4540 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4541 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4542 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4543 | &exception); |
| 4544 | } while (exception.retry); |
| 4545 | return err; |
| 4546 | } |
| 4547 | |
| 4548 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4550 | struct nfs4_exception exception = { |
| 4551 | .interruptible = true, |
| 4552 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4556 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4557 | trace_nfs4_remove(dir, name, err); |
| 4558 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | &exception); |
| 4560 | } while (exception.retry); |
| 4561 | return err; |
| 4562 | } |
| 4563 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4564 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4565 | struct dentry *dentry, |
| 4566 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4568 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4569 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4571 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4573 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4574 | |
| 4575 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4576 | |
| 4577 | if (inode) |
| 4578 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | } |
| 4580 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4581 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4582 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4583 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4584 | &data->args.seq_args, |
| 4585 | &data->res.seq_res, |
| 4586 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | } |
| 4588 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4589 | 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] | 4590 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4591 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4592 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4593 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4594 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4595 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4596 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4597 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4598 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4599 | if (task->tk_status == 0) |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4600 | update_changeattr(dir, &res->cinfo, |
| 4601 | res->dir_attr->time_start, 0); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4602 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | } |
| 4604 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4605 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4606 | struct dentry *old_dentry, |
| 4607 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4608 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4609 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4610 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4611 | struct inode *old_inode = d_inode(old_dentry); |
| 4612 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4613 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4614 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4615 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4616 | if (new_inode) |
| 4617 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4618 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4619 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4620 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4621 | } |
| 4622 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4623 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4624 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4625 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4626 | &data->args.seq_args, |
| 4627 | &data->res.seq_res, |
| 4628 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4632 | struct inode *new_dir) |
| 4633 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4634 | struct nfs_renamedata *data = task->tk_calldata; |
| 4635 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4636 | |
| 4637 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4638 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4639 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4640 | return 0; |
| 4641 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4642 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4643 | if (new_dir != old_dir) { |
| 4644 | /* Note: If we moved a directory, nlink will change */ |
| 4645 | update_changeattr(old_dir, &res->old_cinfo, |
| 4646 | res->old_fattr->time_start, |
| 4647 | NFS_INO_INVALID_OTHER); |
| 4648 | update_changeattr(new_dir, &res->new_cinfo, |
| 4649 | res->new_fattr->time_start, |
| 4650 | NFS_INO_INVALID_OTHER); |
| 4651 | } else |
| 4652 | update_changeattr(old_dir, &res->old_cinfo, |
| 4653 | res->old_fattr->time_start, |
| 4654 | 0); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4655 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4656 | return 1; |
| 4657 | } |
| 4658 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4659 | 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] | 4660 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4661 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4662 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | struct nfs4_link_arg arg = { |
| 4664 | .fh = NFS_FH(inode), |
| 4665 | .dir_fh = NFS_FH(dir), |
| 4666 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4667 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4669 | struct nfs4_link_res res = { |
| 4670 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4671 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4672 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | struct rpc_message msg = { |
| 4674 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4675 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4676 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4678 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4680 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4681 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4682 | goto out; |
| 4683 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4684 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4685 | if (IS_ERR(res.label)) { |
| 4686 | status = PTR_ERR(res.label); |
| 4687 | goto out; |
| 4688 | } |
| 4689 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4690 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4691 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4692 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4693 | 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] | 4694 | if (!status) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4695 | update_changeattr(dir, &res.cinfo, res.fattr->time_start, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4696 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4697 | if (!status) |
| 4698 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4699 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4700 | |
| 4701 | |
| 4702 | nfs4_label_free(res.label); |
| 4703 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4704 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4705 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | return status; |
| 4707 | } |
| 4708 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4709 | 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] | 4710 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4711 | struct nfs4_exception exception = { |
| 4712 | .interruptible = true, |
| 4713 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | int err; |
| 4715 | do { |
| 4716 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4717 | _nfs4_proc_link(inode, dir, name), |
| 4718 | &exception); |
| 4719 | } while (exception.retry); |
| 4720 | return err; |
| 4721 | } |
| 4722 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4723 | struct nfs4_createdata { |
| 4724 | struct rpc_message msg; |
| 4725 | struct nfs4_create_arg arg; |
| 4726 | struct nfs4_create_res res; |
| 4727 | struct nfs_fh fh; |
| 4728 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4729 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4730 | }; |
| 4731 | |
| 4732 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4733 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4734 | { |
| 4735 | struct nfs4_createdata *data; |
| 4736 | |
| 4737 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4738 | if (data != NULL) { |
| 4739 | struct nfs_server *server = NFS_SERVER(dir); |
| 4740 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4741 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4742 | if (IS_ERR(data->label)) |
| 4743 | goto out_free; |
| 4744 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4745 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4746 | data->msg.rpc_argp = &data->arg; |
| 4747 | data->msg.rpc_resp = &data->res; |
| 4748 | data->arg.dir_fh = NFS_FH(dir); |
| 4749 | data->arg.server = server; |
| 4750 | data->arg.name = name; |
| 4751 | data->arg.attrs = sattr; |
| 4752 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4753 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4754 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4755 | data->res.server = server; |
| 4756 | data->res.fh = &data->fh; |
| 4757 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4758 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4759 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4760 | } |
| 4761 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4762 | out_free: |
| 4763 | kfree(data); |
| 4764 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4768 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4769 | 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] | 4770 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4771 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4772 | spin_lock(&dir->i_lock); |
| 4773 | update_changeattr_locked(dir, &data->res.dir_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4774 | data->res.fattr->time_start, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4775 | /* Creating a directory bumps nlink in the parent */ |
| 4776 | if (data->arg.ftype == NF4DIR) |
| 4777 | nfs4_inc_nlink_locked(dir); |
| 4778 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4779 | 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] | 4780 | } |
| 4781 | return status; |
| 4782 | } |
| 4783 | |
| 4784 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4785 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4786 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4787 | kfree(data); |
| 4788 | } |
| 4789 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4790 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4791 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4792 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4794 | struct nfs4_createdata *data; |
| 4795 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4797 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4798 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4799 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4800 | status = -ENOMEM; |
| 4801 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4802 | if (data == NULL) |
| 4803 | goto out; |
| 4804 | |
| 4805 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4806 | data->arg.u.symlink.pages = &page; |
| 4807 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4808 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4810 | status = nfs4_do_create(dir, dentry, data); |
| 4811 | |
| 4812 | nfs4_free_createdata(data); |
| 4813 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | return status; |
| 4815 | } |
| 4816 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4817 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4818 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4820 | struct nfs4_exception exception = { |
| 4821 | .interruptible = true, |
| 4822 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4823 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4825 | |
| 4826 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4829 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4830 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4831 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | &exception); |
| 4833 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4834 | |
| 4835 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | return err; |
| 4837 | } |
| 4838 | |
| 4839 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4840 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4842 | struct nfs4_createdata *data; |
| 4843 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4845 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4846 | if (data == NULL) |
| 4847 | goto out; |
| 4848 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4849 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4850 | status = nfs4_do_create(dir, dentry, data); |
| 4851 | |
| 4852 | nfs4_free_createdata(data); |
| 4853 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4854 | return status; |
| 4855 | } |
| 4856 | |
| 4857 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4858 | struct iattr *sattr) |
| 4859 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4860 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4861 | struct nfs4_exception exception = { |
| 4862 | .interruptible = true, |
| 4863 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4864 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4866 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4867 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4868 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4869 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4870 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4872 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4873 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4874 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | &exception); |
| 4876 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4877 | nfs4_label_release_security(label); |
| 4878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | return err; |
| 4880 | } |
| 4881 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4882 | static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4883 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4885 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | struct nfs4_readdir_arg args = { |
| 4887 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4888 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | .pgbase = 0, |
| 4890 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4891 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4892 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | }; |
| 4894 | struct nfs4_readdir_res res; |
| 4895 | struct rpc_message msg = { |
| 4896 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4897 | .rpc_argp = &args, |
| 4898 | .rpc_resp = &res, |
| 4899 | .rpc_cred = cred, |
| 4900 | }; |
| 4901 | int status; |
| 4902 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4903 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4904 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4905 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4906 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4908 | 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] | 4909 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4910 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4911 | status += args.pgbase; |
| 4912 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4913 | |
| 4914 | nfs_invalidate_atime(dir); |
| 4915 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4916 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | return status; |
| 4918 | } |
| 4919 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4920 | static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4921 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4923 | struct nfs4_exception exception = { |
| 4924 | .interruptible = true, |
| 4925 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | int err; |
| 4927 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4928 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4929 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4930 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4931 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | &exception); |
| 4933 | } while (exception.retry); |
| 4934 | return err; |
| 4935 | } |
| 4936 | |
| 4937 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4938 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4940 | struct nfs4_createdata *data; |
| 4941 | int mode = sattr->ia_mode; |
| 4942 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4944 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4945 | if (data == NULL) |
| 4946 | goto out; |
| 4947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4949 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4951 | data->arg.ftype = NF4BLK; |
| 4952 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4953 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | } |
| 4955 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4956 | data->arg.ftype = NF4CHR; |
| 4957 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4958 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4959 | } else if (!S_ISSOCK(mode)) { |
| 4960 | status = -EINVAL; |
| 4961 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4963 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4964 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4965 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4966 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4967 | nfs4_free_createdata(data); |
| 4968 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | return status; |
| 4970 | } |
| 4971 | |
| 4972 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4973 | struct iattr *sattr, dev_t rdev) |
| 4974 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4975 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4976 | struct nfs4_exception exception = { |
| 4977 | .interruptible = true, |
| 4978 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4979 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4981 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4982 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4983 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4984 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4985 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4987 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4988 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4989 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | &exception); |
| 4991 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4992 | |
| 4993 | nfs4_label_release_security(label); |
| 4994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | return err; |
| 4996 | } |
| 4997 | |
| 4998 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4999 | struct nfs_fsstat *fsstat) |
| 5000 | { |
| 5001 | struct nfs4_statfs_arg args = { |
| 5002 | .fh = fhandle, |
| 5003 | .bitmask = server->attr_bitmask, |
| 5004 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5005 | struct nfs4_statfs_res res = { |
| 5006 | .fsstat = fsstat, |
| 5007 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | struct rpc_message msg = { |
| 5009 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5010 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5011 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | }; |
| 5013 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5014 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5015 | 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] | 5016 | } |
| 5017 | |
| 5018 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5019 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5020 | struct nfs4_exception exception = { |
| 5021 | .interruptible = true, |
| 5022 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | int err; |
| 5024 | do { |
| 5025 | err = nfs4_handle_exception(server, |
| 5026 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5027 | &exception); |
| 5028 | } while (exception.retry); |
| 5029 | return err; |
| 5030 | } |
| 5031 | |
| 5032 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5033 | struct nfs_fsinfo *fsinfo) |
| 5034 | { |
| 5035 | struct nfs4_fsinfo_arg args = { |
| 5036 | .fh = fhandle, |
| 5037 | .bitmask = server->attr_bitmask, |
| 5038 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5039 | struct nfs4_fsinfo_res res = { |
| 5040 | .fsinfo = fsinfo, |
| 5041 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | struct rpc_message msg = { |
| 5043 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5044 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5045 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | }; |
| 5047 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5048 | 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] | 5049 | } |
| 5050 | |
| 5051 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5052 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5053 | struct nfs4_exception exception = { |
| 5054 | .interruptible = true, |
| 5055 | }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5056 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5057 | int err; |
| 5058 | |
| 5059 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5060 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5061 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5062 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 5063 | nfs4_set_lease_period(server->nfs_client, |
| 5064 | fsinfo->lease_time * HZ, |
| 5065 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5066 | break; |
| 5067 | } |
| 5068 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | } while (exception.retry); |
| 5070 | return err; |
| 5071 | } |
| 5072 | |
| 5073 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5074 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5075 | int error; |
| 5076 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5077 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5078 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5079 | if (error == 0) { |
| 5080 | /* block layout checks this! */ |
| 5081 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5082 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5083 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5084 | |
| 5085 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5089 | struct nfs_pathconf *pathconf) |
| 5090 | { |
| 5091 | struct nfs4_pathconf_arg args = { |
| 5092 | .fh = fhandle, |
| 5093 | .bitmask = server->attr_bitmask, |
| 5094 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5095 | struct nfs4_pathconf_res res = { |
| 5096 | .pathconf = pathconf, |
| 5097 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | struct rpc_message msg = { |
| 5099 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5100 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5101 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | }; |
| 5103 | |
| 5104 | /* None of the pathconf attributes are mandatory to implement */ |
| 5105 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5106 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5107 | return 0; |
| 5108 | } |
| 5109 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5110 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5111 | 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] | 5112 | } |
| 5113 | |
| 5114 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5115 | struct nfs_pathconf *pathconf) |
| 5116 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5117 | struct nfs4_exception exception = { |
| 5118 | .interruptible = true, |
| 5119 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | int err; |
| 5121 | |
| 5122 | do { |
| 5123 | err = nfs4_handle_exception(server, |
| 5124 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5125 | &exception); |
| 5126 | } while (exception.retry); |
| 5127 | return err; |
| 5128 | } |
| 5129 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5130 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5131 | const struct nfs_open_context *ctx, |
| 5132 | const struct nfs_lock_context *l_ctx, |
| 5133 | fmode_t fmode) |
| 5134 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5135 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5136 | } |
| 5137 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5138 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5139 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5140 | const struct nfs_open_context *ctx, |
| 5141 | const struct nfs_lock_context *l_ctx, |
| 5142 | fmode_t fmode) |
| 5143 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5144 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5145 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5146 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5147 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5148 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5149 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5150 | } |
| 5151 | |
| 5152 | static bool nfs4_error_stateid_expired(int err) |
| 5153 | { |
| 5154 | switch (err) { |
| 5155 | case -NFS4ERR_DELEG_REVOKED: |
| 5156 | case -NFS4ERR_ADMIN_REVOKED: |
| 5157 | case -NFS4ERR_BAD_STATEID: |
| 5158 | case -NFS4ERR_STALE_STATEID: |
| 5159 | case -NFS4ERR_OLD_STATEID: |
| 5160 | case -NFS4ERR_OPENMODE: |
| 5161 | case -NFS4ERR_EXPIRED: |
| 5162 | return true; |
| 5163 | } |
| 5164 | return false; |
| 5165 | } |
| 5166 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5167 | 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] | 5168 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5169 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5170 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5171 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5172 | if (task->tk_status < 0) { |
| 5173 | struct nfs4_exception exception = { |
| 5174 | .inode = hdr->inode, |
| 5175 | .state = hdr->args.context->state, |
| 5176 | .stateid = &hdr->args.stateid, |
| 5177 | }; |
| 5178 | task->tk_status = nfs4_async_handle_exception(task, |
| 5179 | server, task->tk_status, &exception); |
| 5180 | if (exception.retry) { |
| 5181 | rpc_restart_call_prepare(task); |
| 5182 | return -EAGAIN; |
| 5183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5187 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5188 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5191 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5192 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5193 | { |
| 5194 | |
| 5195 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5196 | nfs4_stateid_is_current(&args->stateid, |
| 5197 | args->context, |
| 5198 | args->lock_context, |
| 5199 | FMODE_READ)) |
| 5200 | return false; |
| 5201 | rpc_restart_call_prepare(task); |
| 5202 | return true; |
| 5203 | } |
| 5204 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5205 | 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] | 5206 | { |
| 5207 | |
| 5208 | dprintk("--> %s\n", __func__); |
| 5209 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5210 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5211 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5212 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5213 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5214 | if (task->tk_status > 0) |
| 5215 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5216 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5217 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5218 | } |
| 5219 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5220 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5221 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5223 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5224 | if (!hdr->pgio_done_cb) |
| 5225 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5226 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5227 | 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] | 5228 | } |
| 5229 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5230 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5231 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5232 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5233 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5234 | &hdr->args.seq_args, |
| 5235 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5236 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5237 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5238 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5239 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5240 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5241 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5242 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5243 | return -EIO; |
| 5244 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5245 | } |
| 5246 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5247 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5248 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5249 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5250 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5251 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5252 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5253 | if (task->tk_status < 0) { |
| 5254 | struct nfs4_exception exception = { |
| 5255 | .inode = hdr->inode, |
| 5256 | .state = hdr->args.context->state, |
| 5257 | .stateid = &hdr->args.stateid, |
| 5258 | }; |
| 5259 | task->tk_status = nfs4_async_handle_exception(task, |
| 5260 | NFS_SERVER(inode), task->tk_status, |
| 5261 | &exception); |
| 5262 | if (exception.retry) { |
| 5263 | rpc_restart_call_prepare(task); |
| 5264 | return -EAGAIN; |
| 5265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5266 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5267 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5268 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5269 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5270 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5271 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | } |
| 5273 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5274 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5275 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5276 | { |
| 5277 | |
| 5278 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5279 | nfs4_stateid_is_current(&args->stateid, |
| 5280 | args->context, |
| 5281 | args->lock_context, |
| 5282 | FMODE_WRITE)) |
| 5283 | return false; |
| 5284 | rpc_restart_call_prepare(task); |
| 5285 | return true; |
| 5286 | } |
| 5287 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5288 | 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] | 5289 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5290 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5291 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5292 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5293 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5294 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5295 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5296 | } |
| 5297 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5298 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5299 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5300 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5301 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5302 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5303 | return false; |
| 5304 | /* Otherwise, request attributes if and only if we don't hold |
| 5305 | * a delegation |
| 5306 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5307 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5308 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5309 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5310 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5311 | struct rpc_message *msg, |
| 5312 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5314 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5315 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5316 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5317 | hdr->args.bitmask = NULL; |
| 5318 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5319 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5320 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5321 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5322 | if (!hdr->pgio_done_cb) |
| 5323 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5324 | hdr->res.server = server; |
| 5325 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5327 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5328 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1, 0); |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5329 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | } |
| 5331 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5332 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5333 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5334 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5335 | &data->args.seq_args, |
| 5336 | &data->res.seq_res, |
| 5337 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5340 | 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] | 5341 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5343 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5344 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5345 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5346 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5347 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5348 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5350 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | } |
| 5352 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5353 | 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] | 5354 | { |
| 5355 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5356 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5357 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5360 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5361 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5363 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5364 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5365 | if (data->commit_done_cb == NULL) |
| 5366 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5367 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5368 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5369 | 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] | 5370 | 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] | 5371 | } |
| 5372 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5373 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5374 | struct nfs_commitres *res) |
| 5375 | { |
| 5376 | struct inode *dst_inode = file_inode(dst); |
| 5377 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5378 | struct rpc_message msg = { |
| 5379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5380 | .rpc_argp = args, |
| 5381 | .rpc_resp = res, |
| 5382 | }; |
| 5383 | |
| 5384 | args->fh = NFS_FH(dst_inode); |
| 5385 | return nfs4_call_sync(server->client, server, &msg, |
| 5386 | &args->seq_args, &res->seq_res, 1); |
| 5387 | } |
| 5388 | |
| 5389 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5390 | { |
| 5391 | struct nfs_commitargs args = { |
| 5392 | .offset = offset, |
| 5393 | .count = count, |
| 5394 | }; |
| 5395 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5396 | struct nfs4_exception exception = { }; |
| 5397 | int status; |
| 5398 | |
| 5399 | do { |
| 5400 | status = _nfs4_proc_commit(dst, &args, res); |
| 5401 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5402 | } while (exception.retry); |
| 5403 | |
| 5404 | return status; |
| 5405 | } |
| 5406 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5407 | struct nfs4_renewdata { |
| 5408 | struct nfs_client *client; |
| 5409 | unsigned long timestamp; |
| 5410 | }; |
| 5411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | /* |
| 5413 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5414 | * standalone procedure for queueing an asynchronous RENEW. |
| 5415 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5416 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5417 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5418 | struct nfs4_renewdata *data = calldata; |
| 5419 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5420 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5421 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5422 | nfs4_schedule_state_renewal(clp); |
| 5423 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5424 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5427 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5428 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5429 | struct nfs4_renewdata *data = calldata; |
| 5430 | struct nfs_client *clp = data->client; |
| 5431 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5433 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5434 | switch (task->tk_status) { |
| 5435 | case 0: |
| 5436 | break; |
| 5437 | case -NFS4ERR_LEASE_MOVED: |
| 5438 | nfs4_schedule_lease_moved_recovery(clp); |
| 5439 | break; |
| 5440 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5441 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5442 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5443 | return; |
| 5444 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5445 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5446 | return; |
| 5447 | } |
| 5448 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5450 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5451 | } |
| 5452 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5453 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5454 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5455 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5456 | }; |
| 5457 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5458 | 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] | 5459 | { |
| 5460 | struct rpc_message msg = { |
| 5461 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5462 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5463 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5465 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5467 | if (renew_flags == 0) |
| 5468 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5469 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5470 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5471 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5472 | if (data == NULL) { |
| 5473 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5474 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5475 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5476 | data->client = clp; |
| 5477 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5478 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5479 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | } |
| 5481 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5482 | 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] | 5483 | { |
| 5484 | struct rpc_message msg = { |
| 5485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5486 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5487 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | }; |
| 5489 | unsigned long now = jiffies; |
| 5490 | int status; |
| 5491 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5492 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | if (status < 0) |
| 5494 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5495 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | return 0; |
| 5497 | } |
| 5498 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5499 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5500 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5501 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5502 | } |
| 5503 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5504 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5505 | * 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] | 5506 | * the stack. |
| 5507 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5508 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5509 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5510 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5511 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5512 | { |
| 5513 | struct page *newpage, **spages; |
| 5514 | int rc = 0; |
| 5515 | size_t len; |
| 5516 | spages = pages; |
| 5517 | |
| 5518 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5519 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5520 | newpage = alloc_page(GFP_KERNEL); |
| 5521 | |
| 5522 | if (newpage == NULL) |
| 5523 | goto unwind; |
| 5524 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5525 | buf += len; |
| 5526 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5527 | *pages++ = newpage; |
| 5528 | rc++; |
| 5529 | } while (buflen != 0); |
| 5530 | |
| 5531 | return rc; |
| 5532 | |
| 5533 | unwind: |
| 5534 | for(; rc > 0; rc--) |
| 5535 | __free_page(spages[rc-1]); |
| 5536 | return -ENOMEM; |
| 5537 | } |
| 5538 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5539 | struct nfs4_cached_acl { |
| 5540 | int cached; |
| 5541 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5542 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5543 | }; |
| 5544 | |
| 5545 | 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] | 5546 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5547 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5548 | |
| 5549 | spin_lock(&inode->i_lock); |
| 5550 | kfree(nfsi->nfs4_acl); |
| 5551 | nfsi->nfs4_acl = acl; |
| 5552 | spin_unlock(&inode->i_lock); |
| 5553 | } |
| 5554 | |
| 5555 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5556 | { |
| 5557 | nfs4_set_cached_acl(inode, NULL); |
| 5558 | } |
| 5559 | |
| 5560 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5561 | { |
| 5562 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5563 | struct nfs4_cached_acl *acl; |
| 5564 | int ret = -ENOENT; |
| 5565 | |
| 5566 | spin_lock(&inode->i_lock); |
| 5567 | acl = nfsi->nfs4_acl; |
| 5568 | if (acl == NULL) |
| 5569 | goto out; |
| 5570 | if (buf == NULL) /* user is just asking for length */ |
| 5571 | goto out_len; |
| 5572 | if (acl->cached == 0) |
| 5573 | goto out; |
| 5574 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5575 | if (acl->len > buflen) |
| 5576 | goto out; |
| 5577 | memcpy(buf, acl->data, acl->len); |
| 5578 | out_len: |
| 5579 | ret = acl->len; |
| 5580 | out: |
| 5581 | spin_unlock(&inode->i_lock); |
| 5582 | return ret; |
| 5583 | } |
| 5584 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5585 | 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] | 5586 | { |
| 5587 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5588 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5589 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5590 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5591 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5592 | if (acl == NULL) |
| 5593 | goto out; |
| 5594 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5595 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5596 | } else { |
| 5597 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5598 | if (acl == NULL) |
| 5599 | goto out; |
| 5600 | acl->cached = 0; |
| 5601 | } |
| 5602 | acl->len = acl_len; |
| 5603 | out: |
| 5604 | nfs4_set_cached_acl(inode, acl); |
| 5605 | } |
| 5606 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5607 | /* |
| 5608 | * The getxattr API returns the required buffer length when called with a |
| 5609 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5610 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5611 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5612 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5613 | * the cache. If not so, we throw away the page, and cache the required |
| 5614 | * length. The next getxattr call will then produce another round trip to |
| 5615 | * the server, this time with the input buf of the required size. |
| 5616 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5617 | 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] | 5618 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5619 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5620 | struct nfs_getaclargs args = { |
| 5621 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5622 | .acl_len = buflen, |
| 5623 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5624 | struct nfs_getaclres res = { |
| 5625 | .acl_len = buflen, |
| 5626 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5627 | struct rpc_message msg = { |
| 5628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5629 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5630 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5631 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5632 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5633 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5634 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5635 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5636 | if (buflen == 0) |
| 5637 | buflen = server->rsize; |
| 5638 | |
| 5639 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5640 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5641 | if (!pages) |
| 5642 | return -ENOMEM; |
| 5643 | |
| 5644 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5645 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5646 | for (i = 0; i < npages; i++) { |
| 5647 | pages[i] = alloc_page(GFP_KERNEL); |
| 5648 | if (!pages[i]) |
| 5649 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5650 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5651 | |
| 5652 | /* for decoding across pages */ |
| 5653 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5654 | if (!res.acl_scratch) |
| 5655 | goto out_free; |
| 5656 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5657 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5658 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5659 | 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] | 5660 | __func__, buf, buflen, npages, args.acl_len); |
| 5661 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5662 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5663 | if (ret) |
| 5664 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5665 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5666 | /* Handle the case where the passed-in buffer is too short */ |
| 5667 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5668 | /* Did the user only issue a request for the acl length? */ |
| 5669 | if (buf == NULL) |
| 5670 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5671 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5672 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5673 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5674 | 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] | 5675 | if (buf) { |
| 5676 | if (res.acl_len > buflen) { |
| 5677 | ret = -ERANGE; |
| 5678 | goto out_free; |
| 5679 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5680 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5681 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5682 | out_ok: |
| 5683 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5684 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5685 | for (i = 0; i < npages; i++) |
| 5686 | if (pages[i]) |
| 5687 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5688 | if (res.acl_scratch) |
| 5689 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5690 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5691 | return ret; |
| 5692 | } |
| 5693 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5694 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5695 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5696 | struct nfs4_exception exception = { |
| 5697 | .interruptible = true, |
| 5698 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5699 | ssize_t ret; |
| 5700 | do { |
| 5701 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5702 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5703 | if (ret >= 0) |
| 5704 | break; |
| 5705 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5706 | } while (exception.retry); |
| 5707 | return ret; |
| 5708 | } |
| 5709 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5710 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5711 | { |
| 5712 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5713 | int ret; |
| 5714 | |
| 5715 | if (!nfs4_server_supports_acls(server)) |
| 5716 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5717 | ret = nfs_revalidate_inode(server, inode); |
| 5718 | if (ret < 0) |
| 5719 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5720 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5721 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5722 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5723 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5724 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5725 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5726 | return ret; |
| 5727 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5730 | 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] | 5731 | { |
| 5732 | struct nfs_server *server = NFS_SERVER(inode); |
| 5733 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5734 | struct nfs_setaclargs arg = { |
| 5735 | .fh = NFS_FH(inode), |
| 5736 | .acl_pages = pages, |
| 5737 | .acl_len = buflen, |
| 5738 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5739 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5740 | struct rpc_message msg = { |
| 5741 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5742 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5743 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5744 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5745 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5746 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5747 | |
| 5748 | if (!nfs4_server_supports_acls(server)) |
| 5749 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5750 | if (npages > ARRAY_SIZE(pages)) |
| 5751 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5752 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5753 | if (i < 0) |
| 5754 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5755 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5756 | 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] | 5757 | |
| 5758 | /* |
| 5759 | * Free each page after tx, so the only ref left is |
| 5760 | * held by the network stack |
| 5761 | */ |
| 5762 | for (; i > 0; i--) |
| 5763 | put_page(pages[i-1]); |
| 5764 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5765 | /* |
| 5766 | * Acl update can result in inode attribute update. |
| 5767 | * so mark the attribute cache invalid. |
| 5768 | */ |
| 5769 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5770 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5771 | | NFS_INO_INVALID_CTIME |
| 5772 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5773 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5774 | nfs_access_zap_cache(inode); |
| 5775 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5776 | return ret; |
| 5777 | } |
| 5778 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5779 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5780 | { |
| 5781 | struct nfs4_exception exception = { }; |
| 5782 | int err; |
| 5783 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5784 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5785 | trace_nfs4_set_acl(inode, err); |
| 5786 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5787 | &exception); |
| 5788 | } while (exception.retry); |
| 5789 | return err; |
| 5790 | } |
| 5791 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5792 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5793 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5794 | size_t buflen) |
| 5795 | { |
| 5796 | struct nfs_server *server = NFS_SERVER(inode); |
| 5797 | struct nfs_fattr fattr; |
| 5798 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5799 | |
| 5800 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5801 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5802 | .fh = NFS_FH(inode), |
| 5803 | .bitmask = bitmask, |
| 5804 | }; |
| 5805 | struct nfs4_getattr_res res = { |
| 5806 | .fattr = &fattr, |
| 5807 | .label = &label, |
| 5808 | .server = server, |
| 5809 | }; |
| 5810 | struct rpc_message msg = { |
| 5811 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5812 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5813 | .rpc_resp = &res, |
| 5814 | }; |
| 5815 | int ret; |
| 5816 | |
| 5817 | nfs_fattr_init(&fattr); |
| 5818 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5819 | 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] | 5820 | if (ret) |
| 5821 | return ret; |
| 5822 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5823 | return -ENOENT; |
| 5824 | if (buflen < label.len) |
| 5825 | return -ERANGE; |
| 5826 | return 0; |
| 5827 | } |
| 5828 | |
| 5829 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5830 | size_t buflen) |
| 5831 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5832 | struct nfs4_exception exception = { |
| 5833 | .interruptible = true, |
| 5834 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5835 | int err; |
| 5836 | |
| 5837 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5838 | return -EOPNOTSUPP; |
| 5839 | |
| 5840 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5841 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5842 | trace_nfs4_get_security_label(inode, err); |
| 5843 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5844 | &exception); |
| 5845 | } while (exception.retry); |
| 5846 | return err; |
| 5847 | } |
| 5848 | |
| 5849 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5850 | struct nfs4_label *ilabel, |
| 5851 | struct nfs_fattr *fattr, |
| 5852 | struct nfs4_label *olabel) |
| 5853 | { |
| 5854 | |
| 5855 | struct iattr sattr = {0}; |
| 5856 | struct nfs_server *server = NFS_SERVER(inode); |
| 5857 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5858 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5859 | .fh = NFS_FH(inode), |
| 5860 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5861 | .server = server, |
| 5862 | .bitmask = bitmask, |
| 5863 | .label = ilabel, |
| 5864 | }; |
| 5865 | struct nfs_setattrres res = { |
| 5866 | .fattr = fattr, |
| 5867 | .label = olabel, |
| 5868 | .server = server, |
| 5869 | }; |
| 5870 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5871 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5872 | .rpc_argp = &arg, |
| 5873 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5874 | }; |
| 5875 | int status; |
| 5876 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5877 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5878 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5879 | 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] | 5880 | if (status) |
| 5881 | dprintk("%s failed: %d\n", __func__, status); |
| 5882 | |
| 5883 | return status; |
| 5884 | } |
| 5885 | |
| 5886 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5887 | struct nfs4_label *ilabel, |
| 5888 | struct nfs_fattr *fattr, |
| 5889 | struct nfs4_label *olabel) |
| 5890 | { |
| 5891 | struct nfs4_exception exception = { }; |
| 5892 | int err; |
| 5893 | |
| 5894 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5895 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5896 | fattr, olabel); |
| 5897 | trace_nfs4_set_security_label(inode, err); |
| 5898 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5899 | &exception); |
| 5900 | } while (exception.retry); |
| 5901 | return err; |
| 5902 | } |
| 5903 | |
| 5904 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5905 | 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] | 5906 | { |
| 5907 | struct nfs4_label ilabel, *olabel = NULL; |
| 5908 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5909 | int status; |
| 5910 | |
| 5911 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5912 | return -EOPNOTSUPP; |
| 5913 | |
| 5914 | nfs_fattr_init(&fattr); |
| 5915 | |
| 5916 | ilabel.pi = 0; |
| 5917 | ilabel.lfs = 0; |
| 5918 | ilabel.label = (char *)buf; |
| 5919 | ilabel.len = buflen; |
| 5920 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5921 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5922 | if (IS_ERR(olabel)) { |
| 5923 | status = -PTR_ERR(olabel); |
| 5924 | goto out; |
| 5925 | } |
| 5926 | |
| 5927 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5928 | if (status == 0) |
| 5929 | nfs_setsecurity(inode, &fattr, olabel); |
| 5930 | |
| 5931 | nfs4_label_free(olabel); |
| 5932 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5933 | return status; |
| 5934 | } |
| 5935 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5936 | |
| 5937 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5938 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5939 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5940 | { |
| 5941 | __be32 verf[2]; |
| 5942 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5943 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5944 | /* An impossible timestamp guarantees this value |
| 5945 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5946 | verf[0] = cpu_to_be32(U32_MAX); |
| 5947 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5948 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5949 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5950 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5951 | |
| 5952 | verf[0] = cpu_to_be32(ns >> 32); |
| 5953 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5954 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5955 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5956 | } |
| 5957 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5958 | static int |
| 5959 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5960 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5961 | size_t len; |
| 5962 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5963 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5964 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5965 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5966 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5967 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5968 | len = 14 + |
| 5969 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5970 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5971 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5972 | 1; |
| 5973 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5974 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5975 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5976 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5977 | return -EINVAL; |
| 5978 | |
| 5979 | /* |
| 5980 | * Since this string is allocated at mount time, and held until the |
| 5981 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5982 | * about a memory-reclaim deadlock. |
| 5983 | */ |
| 5984 | str = kmalloc(len, GFP_KERNEL); |
| 5985 | if (!str) |
| 5986 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5987 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5988 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5989 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5990 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5991 | clp->cl_rpcclient->cl_nodename, |
| 5992 | nfs4_client_id_uniquifier, |
| 5993 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5994 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5995 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5996 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5997 | clp->cl_rpcclient->cl_nodename, |
| 5998 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5999 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6000 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6001 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6002 | clp->cl_owner_id = str; |
| 6003 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6004 | } |
| 6005 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6006 | static int |
| 6007 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6008 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6009 | size_t len; |
| 6010 | char *str; |
| 6011 | |
| 6012 | len = 10 + 10 + 1 + 10 + 1 + |
| 6013 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 6014 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6015 | |
| 6016 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6017 | return -EINVAL; |
| 6018 | |
| 6019 | /* |
| 6020 | * Since this string is allocated at mount time, and held until the |
| 6021 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6022 | * about a memory-reclaim deadlock. |
| 6023 | */ |
| 6024 | str = kmalloc(len, GFP_KERNEL); |
| 6025 | if (!str) |
| 6026 | return -ENOMEM; |
| 6027 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 6028 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6029 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6030 | nfs4_client_id_uniquifier, |
| 6031 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6032 | clp->cl_owner_id = str; |
| 6033 | return 0; |
| 6034 | } |
| 6035 | |
| 6036 | static int |
| 6037 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6038 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6039 | size_t len; |
| 6040 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6041 | |
| 6042 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6043 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6044 | |
| 6045 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6046 | return nfs4_init_uniquifier_client_string(clp); |
| 6047 | |
| 6048 | len = 10 + 10 + 1 + 10 + 1 + |
| 6049 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6050 | |
| 6051 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6052 | return -EINVAL; |
| 6053 | |
| 6054 | /* |
| 6055 | * Since this string is allocated at mount time, and held until the |
| 6056 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6057 | * about a memory-reclaim deadlock. |
| 6058 | */ |
| 6059 | str = kmalloc(len, GFP_KERNEL); |
| 6060 | if (!str) |
| 6061 | return -ENOMEM; |
| 6062 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 6063 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6064 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6065 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6066 | clp->cl_owner_id = str; |
| 6067 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6068 | } |
| 6069 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6070 | /* |
| 6071 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6072 | * services. Advertise one based on the address family of the |
| 6073 | * clientaddr. |
| 6074 | */ |
| 6075 | static unsigned int |
| 6076 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6077 | { |
| 6078 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6079 | return scnprintf(buf, len, "tcp6"); |
| 6080 | else |
| 6081 | return scnprintf(buf, len, "tcp"); |
| 6082 | } |
| 6083 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6084 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6085 | { |
| 6086 | struct nfs4_setclientid *sc = calldata; |
| 6087 | |
| 6088 | if (task->tk_status == 0) |
| 6089 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6090 | } |
| 6091 | |
| 6092 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6093 | .rpc_call_done = nfs4_setclientid_done, |
| 6094 | }; |
| 6095 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6096 | /** |
| 6097 | * nfs4_proc_setclientid - Negotiate client ID |
| 6098 | * @clp: state data structure |
| 6099 | * @program: RPC program for NFSv4 callback service |
| 6100 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6101 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6102 | * @res: where to place the result |
| 6103 | * |
| 6104 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6105 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6106 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6107 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6108 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | { |
| 6110 | nfs4_verifier sc_verifier; |
| 6111 | struct nfs4_setclientid setclientid = { |
| 6112 | .sc_verifier = &sc_verifier, |
| 6113 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6114 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6115 | }; |
| 6116 | struct rpc_message msg = { |
| 6117 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6118 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6119 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6120 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6122 | struct rpc_task_setup task_setup_data = { |
| 6123 | .rpc_client = clp->cl_rpcclient, |
| 6124 | .rpc_message = &msg, |
| 6125 | .callback_ops = &nfs4_setclientid_ops, |
| 6126 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6127 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6128 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6129 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6131 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6132 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6133 | |
| 6134 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6135 | status = nfs4_init_uniform_client_string(clp); |
| 6136 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6137 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6138 | |
| 6139 | if (status) |
| 6140 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6141 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6142 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6143 | setclientid.sc_netid_len = |
| 6144 | nfs4_init_callback_netid(clp, |
| 6145 | setclientid.sc_netid, |
| 6146 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6147 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6148 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6149 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6150 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6151 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6152 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6153 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6154 | |
| 6155 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6156 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6157 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6158 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6159 | put_rpccred(setclientid.sc_cred); |
| 6160 | } |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6161 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6162 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6163 | dprintk("NFS reply setclientid: %d\n", status); |
| 6164 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | } |
| 6166 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6167 | /** |
| 6168 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6169 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6170 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6171 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6172 | * |
| 6173 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6174 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6175 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6176 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6177 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6178 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6179 | struct rpc_message msg = { |
| 6180 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6181 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6182 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6183 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | int status; |
| 6185 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6186 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6187 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6188 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6189 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6190 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6191 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6192 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6193 | return status; |
| 6194 | } |
| 6195 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6196 | struct nfs4_delegreturndata { |
| 6197 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6198 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6199 | struct nfs_fh fh; |
| 6200 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6201 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6202 | struct { |
| 6203 | struct nfs4_layoutreturn_args arg; |
| 6204 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6205 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6206 | u32 roc_barrier; |
| 6207 | bool roc; |
| 6208 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6209 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6210 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6211 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6212 | }; |
| 6213 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6214 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6215 | { |
| 6216 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6217 | struct nfs4_exception exception = { |
| 6218 | .inode = data->inode, |
| 6219 | .stateid = &data->stateid, |
| 6220 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6221 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6222 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6223 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6224 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6225 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6226 | |
| 6227 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6228 | if (pnfs_roc_done(task, data->inode, |
| 6229 | &data->args.lr_args, |
| 6230 | &data->res.lr_res, |
| 6231 | &data->res.lr_ret) == -EAGAIN) |
| 6232 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6233 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6234 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6235 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6236 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6237 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6238 | case -NFS4ERR_ADMIN_REVOKED: |
| 6239 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6240 | case -NFS4ERR_EXPIRED: |
| 6241 | nfs4_free_revoked_stateid(data->res.server, |
| 6242 | data->args.stateid, |
| 6243 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6244 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6245 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6246 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6247 | task->tk_status = 0; |
| 6248 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6249 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6250 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6251 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6252 | if (data->args.bitmask) { |
| 6253 | data->args.bitmask = NULL; |
| 6254 | data->res.fattr = NULL; |
| 6255 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6256 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6257 | case -NFS4ERR_ACCESS: |
| 6258 | if (data->args.bitmask) { |
| 6259 | data->args.bitmask = NULL; |
| 6260 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6261 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6262 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6263 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6264 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6265 | task->tk_status = nfs4_async_handle_exception(task, |
| 6266 | data->res.server, task->tk_status, |
| 6267 | &exception); |
| 6268 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6269 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6270 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6271 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6272 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6273 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6274 | out_restart: |
| 6275 | task->tk_status = 0; |
| 6276 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | static void nfs4_delegreturn_release(void *calldata) |
| 6280 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6281 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6282 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6283 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6284 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6285 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6286 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6287 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6288 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6289 | nfs_iput_and_deactive(inode); |
| 6290 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6291 | kfree(calldata); |
| 6292 | } |
| 6293 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6294 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6295 | { |
| 6296 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6297 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6298 | |
| 6299 | d_data = (struct nfs4_delegreturndata *)data; |
| 6300 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6301 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6302 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6303 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6304 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6305 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6306 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6307 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6308 | d_data->args.lr_args = NULL; |
| 6309 | d_data->res.lr_res = NULL; |
| 6310 | } |
| 6311 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6312 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6313 | &d_data->args.seq_args, |
| 6314 | &d_data->res.seq_res, |
| 6315 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6316 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6317 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6318 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6319 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6320 | .rpc_call_done = nfs4_delegreturn_done, |
| 6321 | .rpc_release = nfs4_delegreturn_release, |
| 6322 | }; |
| 6323 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6324 | 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] | 6325 | { |
| 6326 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6327 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6328 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6329 | struct rpc_message msg = { |
| 6330 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6331 | .rpc_cred = cred, |
| 6332 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6333 | struct rpc_task_setup task_setup_data = { |
| 6334 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6335 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6336 | .callback_ops = &nfs4_delegreturn_ops, |
| 6337 | .flags = RPC_TASK_ASYNC, |
| 6338 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6339 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6340 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6341 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6342 | if (data == NULL) |
| 6343 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6344 | 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] | 6345 | |
| 6346 | nfs4_state_protect(server->nfs_client, |
| 6347 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6348 | &task_setup_data.rpc_client, &msg); |
| 6349 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6350 | data->args.fhandle = &data->fh; |
| 6351 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6352 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6353 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6354 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6355 | data->res.fattr = &data->fattr; |
| 6356 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6357 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6358 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6359 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6360 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6361 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6362 | 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] | 6363 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6364 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6365 | if (data->lr.roc) { |
| 6366 | data->args.lr_args = &data->lr.arg; |
| 6367 | data->res.lr_res = &data->lr.res; |
| 6368 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6369 | } else if (data->lr.roc) { |
| 6370 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6371 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6372 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6373 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6374 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6375 | msg.rpc_argp = &data->args; |
| 6376 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6377 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6378 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6379 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6380 | if (!issync) |
| 6381 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6382 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6383 | if (status != 0) |
| 6384 | goto out; |
| 6385 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6386 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6387 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6388 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6389 | } |
| 6390 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6391 | 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] | 6392 | { |
| 6393 | struct nfs_server *server = NFS_SERVER(inode); |
| 6394 | struct nfs4_exception exception = { }; |
| 6395 | int err; |
| 6396 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6397 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6398 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | switch (err) { |
| 6400 | case -NFS4ERR_STALE_STATEID: |
| 6401 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6402 | case 0: |
| 6403 | return 0; |
| 6404 | } |
| 6405 | err = nfs4_handle_exception(server, err, &exception); |
| 6406 | } while (exception.retry); |
| 6407 | return err; |
| 6408 | } |
| 6409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6410 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6411 | { |
| 6412 | struct inode *inode = state->inode; |
| 6413 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6414 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6415 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6416 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6417 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6418 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6419 | struct nfs_lockt_res res = { |
| 6420 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | }; |
| 6422 | struct rpc_message msg = { |
| 6423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6424 | .rpc_argp = &arg, |
| 6425 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6426 | .rpc_cred = state->owner->so_cred, |
| 6427 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6428 | struct nfs4_lock_state *lsp; |
| 6429 | int status; |
| 6430 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6431 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6432 | status = nfs4_set_lock_state(state, request); |
| 6433 | if (status != 0) |
| 6434 | goto out; |
| 6435 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6436 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6437 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6438 | 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] | 6439 | switch (status) { |
| 6440 | case 0: |
| 6441 | request->fl_type = F_UNLCK; |
| 6442 | break; |
| 6443 | case -NFS4ERR_DENIED: |
| 6444 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6445 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6446 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6447 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6448 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6449 | return status; |
| 6450 | } |
| 6451 | |
| 6452 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6453 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6454 | struct nfs4_exception exception = { |
| 6455 | .interruptible = true, |
| 6456 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6457 | int err; |
| 6458 | |
| 6459 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6460 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6461 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6462 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | &exception); |
| 6464 | } while (exception.retry); |
| 6465 | return err; |
| 6466 | } |
| 6467 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6468 | /* |
| 6469 | * Update the seqid of a lock stateid after receiving |
| 6470 | * NFS4ERR_OLD_STATEID |
| 6471 | */ |
| 6472 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6473 | struct nfs4_lock_state *lsp) |
| 6474 | { |
| 6475 | struct nfs4_state *state = lsp->ls_state; |
| 6476 | bool ret = false; |
| 6477 | |
| 6478 | spin_lock(&state->state_lock); |
| 6479 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6480 | goto out; |
| 6481 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6482 | nfs4_stateid_seqid_inc(dst); |
| 6483 | else |
| 6484 | dst->seqid = lsp->ls_stateid.seqid; |
| 6485 | ret = true; |
| 6486 | out: |
| 6487 | spin_unlock(&state->state_lock); |
| 6488 | return ret; |
| 6489 | } |
| 6490 | |
| 6491 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6492 | struct nfs4_lock_state *lsp) |
| 6493 | { |
| 6494 | struct nfs4_state *state = lsp->ls_state; |
| 6495 | bool ret; |
| 6496 | |
| 6497 | spin_lock(&state->state_lock); |
| 6498 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6499 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6500 | spin_unlock(&state->state_lock); |
| 6501 | return ret; |
| 6502 | } |
| 6503 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6504 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6505 | struct nfs_locku_args arg; |
| 6506 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6507 | struct nfs4_lock_state *lsp; |
| 6508 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6509 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6510 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6511 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6512 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6513 | }; |
| 6514 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6515 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6516 | struct nfs_open_context *ctx, |
| 6517 | struct nfs4_lock_state *lsp, |
| 6518 | struct nfs_seqid *seqid) |
| 6519 | { |
| 6520 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6521 | struct nfs4_state *state = lsp->ls_state; |
| 6522 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6523 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6524 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6525 | if (p == NULL) |
| 6526 | return NULL; |
| 6527 | p->arg.fh = NFS_FH(inode); |
| 6528 | p->arg.fl = &p->fl; |
| 6529 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6530 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6531 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6532 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6533 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6534 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6535 | locks_init_lock(&p->fl); |
| 6536 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6537 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6538 | spin_lock(&state->state_lock); |
| 6539 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6540 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6541 | return p; |
| 6542 | } |
| 6543 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6544 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6545 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6546 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6547 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6548 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6549 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6550 | put_nfs_open_context(calldata->ctx); |
| 6551 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6554 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6555 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6556 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6557 | struct nfs4_exception exception = { |
| 6558 | .inode = calldata->lsp->ls_state->inode, |
| 6559 | .stateid = &calldata->arg.stateid, |
| 6560 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6561 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6562 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6563 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6564 | switch (task->tk_status) { |
| 6565 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6566 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6567 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6568 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6569 | &calldata->res.stateid)) |
| 6570 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6571 | /* Fall through */ |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6572 | case -NFS4ERR_ADMIN_REVOKED: |
| 6573 | case -NFS4ERR_EXPIRED: |
| 6574 | nfs4_free_revoked_stateid(calldata->server, |
| 6575 | &calldata->arg.stateid, |
| 6576 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6577 | /* Fall through */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6578 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6579 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6580 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6581 | calldata->lsp)) |
| 6582 | rpc_restart_call_prepare(task); |
| 6583 | break; |
| 6584 | case -NFS4ERR_OLD_STATEID: |
| 6585 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6586 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6587 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6588 | break; |
| 6589 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6590 | task->tk_status = nfs4_async_handle_exception(task, |
| 6591 | calldata->server, task->tk_status, |
| 6592 | &exception); |
| 6593 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6594 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6595 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6596 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6599 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6600 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6601 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6602 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6603 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6604 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6605 | return; |
| 6606 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6607 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6608 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6609 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6610 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6611 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6612 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6613 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6614 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6615 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6616 | &calldata->res.seq_res, |
| 6617 | task) != 0) |
| 6618 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6619 | return; |
| 6620 | out_no_action: |
| 6621 | task->tk_action = NULL; |
| 6622 | out_wait: |
| 6623 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6624 | } |
| 6625 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6626 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6627 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6628 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6629 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6630 | }; |
| 6631 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6632 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6633 | struct nfs_open_context *ctx, |
| 6634 | struct nfs4_lock_state *lsp, |
| 6635 | struct nfs_seqid *seqid) |
| 6636 | { |
| 6637 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6638 | struct rpc_message msg = { |
| 6639 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6640 | .rpc_cred = ctx->cred, |
| 6641 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6642 | struct rpc_task_setup task_setup_data = { |
| 6643 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6644 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6645 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6646 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6647 | .flags = RPC_TASK_ASYNC, |
| 6648 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6649 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6650 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6651 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6652 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6653 | /* Ensure this is an unlock - when canceling a lock, the |
| 6654 | * canceled lock is passed in, and it won't be an unlock. |
| 6655 | */ |
| 6656 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6657 | if (fl->fl_flags & FL_CLOSE) |
| 6658 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6659 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6660 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6661 | if (data == NULL) { |
| 6662 | nfs_free_seqid(seqid); |
| 6663 | return ERR_PTR(-ENOMEM); |
| 6664 | } |
| 6665 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6666 | 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] | 6667 | msg.rpc_argp = &data->arg; |
| 6668 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6669 | task_setup_data.callback_data = data; |
| 6670 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6671 | } |
| 6672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6673 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6674 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6675 | struct inode *inode = state->inode; |
| 6676 | struct nfs4_state_owner *sp = state->owner; |
| 6677 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6678 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6679 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6680 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6681 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6682 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6683 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6684 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6685 | status = nfs4_set_lock_state(state, request); |
| 6686 | /* Unlock _before_ we do the RPC call */ |
| 6687 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6688 | /* Exclude nfs_delegation_claim_locks() */ |
| 6689 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6690 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6691 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6692 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6693 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6694 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6695 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6696 | } |
| 6697 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6698 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6699 | if (status != 0) |
| 6700 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6701 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6702 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6703 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6704 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6705 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6706 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6707 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6708 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6709 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6710 | 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] | 6711 | status = PTR_ERR(task); |
| 6712 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6713 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6714 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6715 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6716 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6717 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6718 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6719 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6720 | } |
| 6721 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6722 | struct nfs4_lockdata { |
| 6723 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6724 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6725 | struct nfs4_lock_state *lsp; |
| 6726 | struct nfs_open_context *ctx; |
| 6727 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6728 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6729 | int rpc_status; |
| 6730 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6731 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6732 | }; |
| 6733 | |
| 6734 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6735 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6736 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6737 | { |
| 6738 | struct nfs4_lockdata *p; |
| 6739 | struct inode *inode = lsp->ls_state->inode; |
| 6740 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6741 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6742 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6743 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6744 | if (p == NULL) |
| 6745 | return NULL; |
| 6746 | |
| 6747 | p->arg.fh = NFS_FH(inode); |
| 6748 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6749 | 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] | 6750 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6751 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6752 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6753 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6754 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6755 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6756 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6757 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6758 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6759 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6760 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6761 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6762 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6763 | locks_init_lock(&p->fl); |
| 6764 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6765 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6766 | out_free_seqid: |
| 6767 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6768 | out_free: |
| 6769 | kfree(p); |
| 6770 | return NULL; |
| 6771 | } |
| 6772 | |
| 6773 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6774 | { |
| 6775 | struct nfs4_lockdata *data = calldata; |
| 6776 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6777 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6778 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6779 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6780 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6781 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6782 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6783 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6784 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6785 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6786 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6787 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6788 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6789 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6790 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6791 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6792 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6793 | &data->lsp->ls_stateid); |
| 6794 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6795 | if (!nfs4_valid_open_stateid(state)) { |
| 6796 | data->rpc_status = -EBADF; |
| 6797 | task->tk_action = NULL; |
| 6798 | goto out_release_open_seqid; |
| 6799 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6800 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6801 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6802 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6803 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6804 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6805 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6806 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6807 | nfs_release_seqid(data->arg.open_seqid); |
| 6808 | out_release_lock_seqid: |
| 6809 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6810 | out_wait: |
| 6811 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6812 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6813 | } |
| 6814 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6815 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6816 | { |
| 6817 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6818 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6819 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6820 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6821 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6822 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6823 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6824 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6825 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6826 | switch (task->tk_status) { |
| 6827 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6828 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6829 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6830 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6831 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6832 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6833 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6834 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6835 | if (data->arg.new_lock_owner != 0) { |
| 6836 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6837 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6838 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6839 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6840 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6841 | break; |
| 6842 | case -NFS4ERR_BAD_STATEID: |
| 6843 | case -NFS4ERR_OLD_STATEID: |
| 6844 | case -NFS4ERR_STALE_STATEID: |
| 6845 | case -NFS4ERR_EXPIRED: |
| 6846 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6847 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6848 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6849 | goto out_restart; |
| 6850 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6851 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6852 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6853 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6854 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6855 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6856 | return; |
| 6857 | out_restart: |
| 6858 | if (!data->cancelled) |
| 6859 | rpc_restart_call_prepare(task); |
| 6860 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6861 | } |
| 6862 | |
| 6863 | static void nfs4_lock_release(void *calldata) |
| 6864 | { |
| 6865 | struct nfs4_lockdata *data = calldata; |
| 6866 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6867 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6868 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6869 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6870 | struct rpc_task *task; |
| 6871 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6872 | data->arg.lock_seqid); |
| 6873 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6874 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6875 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6876 | } else |
| 6877 | nfs_free_seqid(data->arg.lock_seqid); |
| 6878 | nfs4_put_lock_state(data->lsp); |
| 6879 | put_nfs_open_context(data->ctx); |
| 6880 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6881 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6882 | } |
| 6883 | |
| 6884 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6885 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6886 | .rpc_call_done = nfs4_lock_done, |
| 6887 | .rpc_release = nfs4_lock_release, |
| 6888 | }; |
| 6889 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6890 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6891 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6892 | switch (error) { |
| 6893 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6894 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6895 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6896 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6897 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6898 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6899 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6900 | break; |
| 6901 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6902 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6903 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 6904 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6905 | } |
| 6906 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6907 | 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] | 6908 | { |
| 6909 | struct nfs4_lockdata *data; |
| 6910 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6911 | struct rpc_message msg = { |
| 6912 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6913 | .rpc_cred = state->owner->so_cred, |
| 6914 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6915 | struct rpc_task_setup task_setup_data = { |
| 6916 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6917 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6918 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6919 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6920 | .flags = RPC_TASK_ASYNC, |
| 6921 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6922 | int ret; |
| 6923 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6924 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6925 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6926 | fl->fl_u.nfs4_fl.owner, |
| 6927 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6928 | if (data == NULL) |
| 6929 | return -ENOMEM; |
| 6930 | if (IS_SETLKW(cmd)) |
| 6931 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6932 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6933 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6934 | msg.rpc_argp = &data->arg; |
| 6935 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6936 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6937 | if (recovery_type > NFS_LOCK_NEW) { |
| 6938 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6939 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6940 | } else |
| 6941 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6942 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6943 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6944 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6945 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6946 | if (ret == 0) { |
| 6947 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6948 | if (ret) |
| 6949 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6950 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6951 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6952 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6953 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6954 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6955 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6956 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6957 | } |
| 6958 | |
| 6959 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6960 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6961 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6962 | struct nfs4_exception exception = { |
| 6963 | .inode = state->inode, |
| 6964 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6965 | int err; |
| 6966 | |
| 6967 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6968 | /* Cache the lock if possible... */ |
| 6969 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6970 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6971 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6972 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6973 | break; |
| 6974 | nfs4_handle_exception(server, err, &exception); |
| 6975 | } while (exception.retry); |
| 6976 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6977 | } |
| 6978 | |
| 6979 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6980 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6981 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6982 | struct nfs4_exception exception = { |
| 6983 | .inode = state->inode, |
| 6984 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6985 | int err; |
| 6986 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6987 | err = nfs4_set_lock_state(state, request); |
| 6988 | if (err != 0) |
| 6989 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6990 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6991 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6992 | return 0; |
| 6993 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6994 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6995 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6996 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6997 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6998 | switch (err) { |
| 6999 | default: |
| 7000 | goto out; |
| 7001 | case -NFS4ERR_GRACE: |
| 7002 | case -NFS4ERR_DELAY: |
| 7003 | nfs4_handle_exception(server, err, &exception); |
| 7004 | err = 0; |
| 7005 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7006 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7007 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7008 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7009 | } |
| 7010 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7011 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7012 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7013 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7014 | struct nfs4_lock_state *lsp; |
| 7015 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7016 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7017 | status = nfs4_set_lock_state(state, request); |
| 7018 | if (status != 0) |
| 7019 | return status; |
| 7020 | lsp = request->fl_u.nfs4_fl.owner; |
| 7021 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7022 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7023 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7024 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7025 | } |
| 7026 | #endif |
| 7027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7028 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7029 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7030 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7031 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7032 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7033 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7034 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7035 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7036 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7037 | if (status < 0) |
| 7038 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7039 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7040 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7041 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7042 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7043 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7044 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7045 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7046 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7047 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7048 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7049 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7050 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7051 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7052 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7053 | out: |
| 7054 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7055 | return status; |
| 7056 | } |
| 7057 | |
| 7058 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7059 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7060 | struct nfs4_exception exception = { |
| 7061 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7062 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7063 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7064 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7065 | int err; |
| 7066 | |
| 7067 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7068 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7069 | if (err == -NFS4ERR_DENIED) |
| 7070 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7071 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7072 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7073 | } while (exception.retry); |
| 7074 | return err; |
| 7075 | } |
| 7076 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7077 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7078 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7079 | |
| 7080 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7081 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7082 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7083 | { |
| 7084 | int status = -ERESTARTSYS; |
| 7085 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7086 | |
| 7087 | while(!signalled()) { |
| 7088 | status = nfs4_proc_setlk(state, cmd, request); |
| 7089 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7090 | break; |
| 7091 | freezable_schedule_timeout_interruptible(timeout); |
| 7092 | timeout *= 2; |
| 7093 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7094 | status = -ERESTARTSYS; |
| 7095 | } |
| 7096 | return status; |
| 7097 | } |
| 7098 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7099 | #ifdef CONFIG_NFS_V4_1 |
| 7100 | struct nfs4_lock_waiter { |
| 7101 | struct task_struct *task; |
| 7102 | struct inode *inode; |
| 7103 | struct nfs_lowner *owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7104 | }; |
| 7105 | |
| 7106 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7107 | 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] | 7108 | { |
| 7109 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7110 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7111 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7112 | /* NULL key means to wake up everyone */ |
| 7113 | if (key) { |
| 7114 | struct cb_notify_lock_args *cbnl = key; |
| 7115 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 7116 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7117 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7118 | /* Only wake if the callback was for the same owner. */ |
| 7119 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7120 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7121 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7122 | /* Make sure it's for the right inode */ |
| 7123 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7124 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7125 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7126 | |
| 7127 | /* override "private" so we can use default_wake_function */ |
| 7128 | wait->private = waiter->task; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7129 | ret = woken_wake_function(wait, mode, flags, key); |
| 7130 | if (ret) |
| 7131 | list_del_init(&wait->entry); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7132 | wait->private = waiter; |
| 7133 | return ret; |
| 7134 | } |
| 7135 | |
| 7136 | static int |
| 7137 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7138 | { |
| 7139 | int status = -ERESTARTSYS; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7140 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7141 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7142 | struct nfs_client *clp = server->nfs_client; |
| 7143 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 7144 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 7145 | .id = lsp->ls_seqid.owner_id, |
| 7146 | .s_dev = server->s_dev }; |
| 7147 | struct nfs4_lock_waiter waiter = { .task = current, |
| 7148 | .inode = state->inode, |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7149 | .owner = &owner}; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7150 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7151 | |
| 7152 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7153 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7154 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7155 | |
| 7156 | init_wait(&wait); |
| 7157 | wait.private = &waiter; |
| 7158 | wait.func = nfs4_wake_lock_waiter; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7159 | |
| 7160 | while(!signalled()) { |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7161 | add_wait_queue(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7162 | status = nfs4_proc_setlk(state, cmd, request); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7163 | if ((status != -EAGAIN) || IS_SETLK(cmd)) { |
| 7164 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7165 | break; |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7166 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7167 | |
| 7168 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7169 | freezer_do_not_count(); |
| 7170 | wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); |
| 7171 | freezer_count(); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7172 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7173 | } |
| 7174 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7175 | return status; |
| 7176 | } |
| 7177 | #else /* !CONFIG_NFS_V4_1 */ |
| 7178 | static inline int |
| 7179 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7180 | { |
| 7181 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7182 | } |
| 7183 | #endif |
| 7184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7185 | static int |
| 7186 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7187 | { |
| 7188 | struct nfs_open_context *ctx; |
| 7189 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7190 | int status; |
| 7191 | |
| 7192 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7193 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7194 | state = ctx->state; |
| 7195 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7196 | if (IS_GETLK(cmd)) { |
| 7197 | if (state != NULL) |
| 7198 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7199 | return 0; |
| 7200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7201 | |
| 7202 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7203 | return -EINVAL; |
| 7204 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7205 | if (request->fl_type == F_UNLCK) { |
| 7206 | if (state != NULL) |
| 7207 | return nfs4_proc_unlck(state, cmd, request); |
| 7208 | return 0; |
| 7209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7210 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7211 | if (state == NULL) |
| 7212 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7213 | |
| 7214 | if ((request->fl_flags & FL_POSIX) && |
| 7215 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7216 | return -ENOLCK; |
| 7217 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7218 | /* |
| 7219 | * Don't rely on the VFS having checked the file open mode, |
| 7220 | * since it won't do this for flock() locks. |
| 7221 | */ |
| 7222 | switch (request->fl_type) { |
| 7223 | case F_RDLCK: |
| 7224 | if (!(filp->f_mode & FMODE_READ)) |
| 7225 | return -EBADF; |
| 7226 | break; |
| 7227 | case F_WRLCK: |
| 7228 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7229 | return -EBADF; |
| 7230 | } |
| 7231 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7232 | status = nfs4_set_lock_state(state, request); |
| 7233 | if (status != 0) |
| 7234 | return status; |
| 7235 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7236 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7237 | } |
| 7238 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7239 | 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] | 7240 | { |
| 7241 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7242 | int err; |
| 7243 | |
| 7244 | err = nfs4_set_lock_state(state, fl); |
| 7245 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7246 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 7247 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7248 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7249 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7250 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7251 | struct nfs_release_lockowner_data { |
| 7252 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7253 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7254 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7255 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7256 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7257 | }; |
| 7258 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7259 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7260 | { |
| 7261 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7262 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7263 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7264 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7265 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7266 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7267 | } |
| 7268 | |
| 7269 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7270 | { |
| 7271 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7272 | struct nfs_server *server = data->server; |
| 7273 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7274 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7275 | |
| 7276 | switch (task->tk_status) { |
| 7277 | case 0: |
| 7278 | renew_lease(server, data->timestamp); |
| 7279 | break; |
| 7280 | case -NFS4ERR_STALE_CLIENTID: |
| 7281 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7282 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7283 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7284 | case -NFS4ERR_LEASE_MOVED: |
| 7285 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7286 | if (nfs4_async_handle_error(task, server, |
| 7287 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7288 | rpc_restart_call_prepare(task); |
| 7289 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7290 | } |
| 7291 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7292 | static void nfs4_release_lockowner_release(void *calldata) |
| 7293 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7294 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7295 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7296 | kfree(calldata); |
| 7297 | } |
| 7298 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7299 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7300 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7301 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7302 | .rpc_release = nfs4_release_lockowner_release, |
| 7303 | }; |
| 7304 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7305 | static void |
| 7306 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7307 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7308 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7309 | struct rpc_message msg = { |
| 7310 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7311 | }; |
| 7312 | |
| 7313 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7314 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7315 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7316 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7317 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7318 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7319 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7320 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7321 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7322 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7323 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7324 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7325 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7326 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7327 | 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] | 7328 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7329 | } |
| 7330 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7331 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7332 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7333 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7334 | struct dentry *unused, struct inode *inode, |
| 7335 | const char *key, const void *buf, |
| 7336 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7337 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7338 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7339 | } |
| 7340 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7341 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7342 | struct dentry *unused, struct inode *inode, |
| 7343 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7344 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7345 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7348 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7349 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7350 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7351 | } |
| 7352 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7353 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7354 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7355 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7356 | struct dentry *unused, struct inode *inode, |
| 7357 | const char *key, const void *buf, |
| 7358 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7359 | { |
| 7360 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7361 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7362 | |
| 7363 | return -EOPNOTSUPP; |
| 7364 | } |
| 7365 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7366 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7367 | struct dentry *unused, struct inode *inode, |
| 7368 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7369 | { |
| 7370 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7371 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7372 | return -EOPNOTSUPP; |
| 7373 | } |
| 7374 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7375 | static ssize_t |
| 7376 | 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] | 7377 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7378 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7379 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7380 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7381 | len = security_inode_listsecurity(inode, list, list_len); |
| 7382 | if (list_len && len > list_len) |
| 7383 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7384 | } |
| 7385 | return len; |
| 7386 | } |
| 7387 | |
| 7388 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7389 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7390 | .get = nfs4_xattr_get_nfs4_label, |
| 7391 | .set = nfs4_xattr_set_nfs4_label, |
| 7392 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7393 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7394 | #else |
| 7395 | |
| 7396 | static ssize_t |
| 7397 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7398 | { |
| 7399 | return 0; |
| 7400 | } |
| 7401 | |
| 7402 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7403 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7404 | /* |
| 7405 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7406 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7407 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7408 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7409 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7410 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7411 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7412 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7413 | return; |
| 7414 | |
| 7415 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7416 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7417 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7418 | fattr->nlink = 2; |
| 7419 | } |
| 7420 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7421 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7422 | const struct qstr *name, |
| 7423 | struct nfs4_fs_locations *fs_locations, |
| 7424 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7425 | { |
| 7426 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7427 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7428 | struct nfs4_fs_locations_arg args = { |
| 7429 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7430 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7431 | .page = page, |
| 7432 | .bitmask = bitmask, |
| 7433 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7434 | struct nfs4_fs_locations_res res = { |
| 7435 | .fs_locations = fs_locations, |
| 7436 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7437 | struct rpc_message msg = { |
| 7438 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7439 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7440 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7441 | }; |
| 7442 | int status; |
| 7443 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7444 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7445 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7446 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7447 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7448 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7449 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7450 | * is not supported */ |
| 7451 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7452 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7453 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7454 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7455 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7456 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7457 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7458 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7459 | 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] | 7460 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7461 | return status; |
| 7462 | } |
| 7463 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7464 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7465 | const struct qstr *name, |
| 7466 | struct nfs4_fs_locations *fs_locations, |
| 7467 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7468 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7469 | struct nfs4_exception exception = { |
| 7470 | .interruptible = true, |
| 7471 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7472 | int err; |
| 7473 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7474 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7475 | fs_locations, page); |
| 7476 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7477 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7478 | &exception); |
| 7479 | } while (exception.retry); |
| 7480 | return err; |
| 7481 | } |
| 7482 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7483 | /* |
| 7484 | * This operation also signals the server that this client is |
| 7485 | * performing migration recovery. The server can stop returning |
| 7486 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7487 | * appended to this compound to identify the client ID which is |
| 7488 | * performing recovery. |
| 7489 | */ |
| 7490 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7491 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7492 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7493 | { |
| 7494 | struct nfs_server *server = NFS_SERVER(inode); |
| 7495 | struct rpc_clnt *clnt = server->client; |
| 7496 | u32 bitmask[2] = { |
| 7497 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7498 | }; |
| 7499 | struct nfs4_fs_locations_arg args = { |
| 7500 | .clientid = server->nfs_client->cl_clientid, |
| 7501 | .fh = NFS_FH(inode), |
| 7502 | .page = page, |
| 7503 | .bitmask = bitmask, |
| 7504 | .migration = 1, /* skip LOOKUP */ |
| 7505 | .renew = 1, /* append RENEW */ |
| 7506 | }; |
| 7507 | struct nfs4_fs_locations_res res = { |
| 7508 | .fs_locations = locations, |
| 7509 | .migration = 1, |
| 7510 | .renew = 1, |
| 7511 | }; |
| 7512 | struct rpc_message msg = { |
| 7513 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7514 | .rpc_argp = &args, |
| 7515 | .rpc_resp = &res, |
| 7516 | .rpc_cred = cred, |
| 7517 | }; |
| 7518 | unsigned long now = jiffies; |
| 7519 | int status; |
| 7520 | |
| 7521 | nfs_fattr_init(&locations->fattr); |
| 7522 | locations->server = server; |
| 7523 | locations->nlocations = 0; |
| 7524 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7525 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7526 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7527 | &args.seq_args, &res.seq_res); |
| 7528 | if (status) |
| 7529 | return status; |
| 7530 | |
| 7531 | renew_lease(server, now); |
| 7532 | return 0; |
| 7533 | } |
| 7534 | |
| 7535 | #ifdef CONFIG_NFS_V4_1 |
| 7536 | |
| 7537 | /* |
| 7538 | * This operation also signals the server that this client is |
| 7539 | * performing migration recovery. The server can stop asserting |
| 7540 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7541 | * performing this operation is identified in the SEQUENCE |
| 7542 | * operation in this compound. |
| 7543 | * |
| 7544 | * When the client supports GETATTR(fs_locations_info), it can |
| 7545 | * be plumbed in here. |
| 7546 | */ |
| 7547 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7548 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7549 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7550 | { |
| 7551 | struct nfs_server *server = NFS_SERVER(inode); |
| 7552 | struct rpc_clnt *clnt = server->client; |
| 7553 | u32 bitmask[2] = { |
| 7554 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7555 | }; |
| 7556 | struct nfs4_fs_locations_arg args = { |
| 7557 | .fh = NFS_FH(inode), |
| 7558 | .page = page, |
| 7559 | .bitmask = bitmask, |
| 7560 | .migration = 1, /* skip LOOKUP */ |
| 7561 | }; |
| 7562 | struct nfs4_fs_locations_res res = { |
| 7563 | .fs_locations = locations, |
| 7564 | .migration = 1, |
| 7565 | }; |
| 7566 | struct rpc_message msg = { |
| 7567 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7568 | .rpc_argp = &args, |
| 7569 | .rpc_resp = &res, |
| 7570 | .rpc_cred = cred, |
| 7571 | }; |
| 7572 | int status; |
| 7573 | |
| 7574 | nfs_fattr_init(&locations->fattr); |
| 7575 | locations->server = server; |
| 7576 | locations->nlocations = 0; |
| 7577 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7578 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7579 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7580 | &args.seq_args, &res.seq_res); |
| 7581 | if (status == NFS4_OK && |
| 7582 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7583 | status = -NFS4ERR_LEASE_MOVED; |
| 7584 | return status; |
| 7585 | } |
| 7586 | |
| 7587 | #endif /* CONFIG_NFS_V4_1 */ |
| 7588 | |
| 7589 | /** |
| 7590 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7591 | * @inode: inode on FSID that is migrating |
| 7592 | * @locations: result of query |
| 7593 | * @page: buffer |
| 7594 | * @cred: credential to use for this operation |
| 7595 | * |
| 7596 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7597 | * operation failed, or a negative errno if a local error occurred. |
| 7598 | * |
| 7599 | * On success, "locations" is filled in, but if the server has |
| 7600 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7601 | * asserted. |
| 7602 | * |
| 7603 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7604 | * from this client that require migration recovery. |
| 7605 | */ |
| 7606 | int nfs4_proc_get_locations(struct inode *inode, |
| 7607 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7608 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7609 | { |
| 7610 | struct nfs_server *server = NFS_SERVER(inode); |
| 7611 | struct nfs_client *clp = server->nfs_client; |
| 7612 | const struct nfs4_mig_recovery_ops *ops = |
| 7613 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7614 | struct nfs4_exception exception = { |
| 7615 | .interruptible = true, |
| 7616 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7617 | int status; |
| 7618 | |
| 7619 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7620 | (unsigned long long)server->fsid.major, |
| 7621 | (unsigned long long)server->fsid.minor, |
| 7622 | clp->cl_hostname); |
| 7623 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7624 | |
| 7625 | do { |
| 7626 | status = ops->get_locations(inode, locations, page, cred); |
| 7627 | if (status != -NFS4ERR_DELAY) |
| 7628 | break; |
| 7629 | nfs4_handle_exception(server, status, &exception); |
| 7630 | } while (exception.retry); |
| 7631 | return status; |
| 7632 | } |
| 7633 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7634 | /* |
| 7635 | * This operation also signals the server that this client is |
| 7636 | * performing "lease moved" recovery. The server can stop |
| 7637 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7638 | * is appended to this compound to identify the client ID which is |
| 7639 | * performing recovery. |
| 7640 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7641 | 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] | 7642 | { |
| 7643 | struct nfs_server *server = NFS_SERVER(inode); |
| 7644 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7645 | struct rpc_clnt *clnt = server->client; |
| 7646 | struct nfs4_fsid_present_arg args = { |
| 7647 | .fh = NFS_FH(inode), |
| 7648 | .clientid = clp->cl_clientid, |
| 7649 | .renew = 1, /* append RENEW */ |
| 7650 | }; |
| 7651 | struct nfs4_fsid_present_res res = { |
| 7652 | .renew = 1, |
| 7653 | }; |
| 7654 | struct rpc_message msg = { |
| 7655 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7656 | .rpc_argp = &args, |
| 7657 | .rpc_resp = &res, |
| 7658 | .rpc_cred = cred, |
| 7659 | }; |
| 7660 | unsigned long now = jiffies; |
| 7661 | int status; |
| 7662 | |
| 7663 | res.fh = nfs_alloc_fhandle(); |
| 7664 | if (res.fh == NULL) |
| 7665 | return -ENOMEM; |
| 7666 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7667 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7668 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7669 | &args.seq_args, &res.seq_res); |
| 7670 | nfs_free_fhandle(res.fh); |
| 7671 | if (status) |
| 7672 | return status; |
| 7673 | |
| 7674 | do_renew_lease(clp, now); |
| 7675 | return 0; |
| 7676 | } |
| 7677 | |
| 7678 | #ifdef CONFIG_NFS_V4_1 |
| 7679 | |
| 7680 | /* |
| 7681 | * This operation also signals the server that this client is |
| 7682 | * performing "lease moved" recovery. The server can stop asserting |
| 7683 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7684 | * this operation is identified in the SEQUENCE operation in this |
| 7685 | * compound. |
| 7686 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7687 | 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] | 7688 | { |
| 7689 | struct nfs_server *server = NFS_SERVER(inode); |
| 7690 | struct rpc_clnt *clnt = server->client; |
| 7691 | struct nfs4_fsid_present_arg args = { |
| 7692 | .fh = NFS_FH(inode), |
| 7693 | }; |
| 7694 | struct nfs4_fsid_present_res res = { |
| 7695 | }; |
| 7696 | struct rpc_message msg = { |
| 7697 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7698 | .rpc_argp = &args, |
| 7699 | .rpc_resp = &res, |
| 7700 | .rpc_cred = cred, |
| 7701 | }; |
| 7702 | int status; |
| 7703 | |
| 7704 | res.fh = nfs_alloc_fhandle(); |
| 7705 | if (res.fh == NULL) |
| 7706 | return -ENOMEM; |
| 7707 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7708 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7709 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7710 | &args.seq_args, &res.seq_res); |
| 7711 | nfs_free_fhandle(res.fh); |
| 7712 | if (status == NFS4_OK && |
| 7713 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7714 | status = -NFS4ERR_LEASE_MOVED; |
| 7715 | return status; |
| 7716 | } |
| 7717 | |
| 7718 | #endif /* CONFIG_NFS_V4_1 */ |
| 7719 | |
| 7720 | /** |
| 7721 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7722 | * @inode: inode on FSID to check |
| 7723 | * @cred: credential to use for this operation |
| 7724 | * |
| 7725 | * Server indicates whether the FSID is present, moved, or not |
| 7726 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7727 | * condition for this client ID. |
| 7728 | * |
| 7729 | * Returns NFS4_OK if the FSID is present on this server, |
| 7730 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7731 | * NFS4ERR code if some error occurred on the server, or a |
| 7732 | * negative errno if a local failure occurred. |
| 7733 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7734 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7735 | { |
| 7736 | struct nfs_server *server = NFS_SERVER(inode); |
| 7737 | struct nfs_client *clp = server->nfs_client; |
| 7738 | const struct nfs4_mig_recovery_ops *ops = |
| 7739 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7740 | struct nfs4_exception exception = { |
| 7741 | .interruptible = true, |
| 7742 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7743 | int status; |
| 7744 | |
| 7745 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7746 | (unsigned long long)server->fsid.major, |
| 7747 | (unsigned long long)server->fsid.minor, |
| 7748 | clp->cl_hostname); |
| 7749 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7750 | |
| 7751 | do { |
| 7752 | status = ops->fsid_present(inode, cred); |
| 7753 | if (status != -NFS4ERR_DELAY) |
| 7754 | break; |
| 7755 | nfs4_handle_exception(server, status, &exception); |
| 7756 | } while (exception.retry); |
| 7757 | return status; |
| 7758 | } |
| 7759 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 7760 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7761 | * If 'use_integrity' is true and the state managment nfs_client |
| 7762 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7763 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7764 | * Considerations sections. Otherwise, just use the user cred with the |
| 7765 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7766 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7767 | 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] | 7768 | { |
| 7769 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7770 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 7771 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7772 | struct nfs4_secinfo_arg args = { |
| 7773 | .dir_fh = NFS_FH(dir), |
| 7774 | .name = name, |
| 7775 | }; |
| 7776 | struct nfs4_secinfo_res res = { |
| 7777 | .flavors = flavors, |
| 7778 | }; |
| 7779 | struct rpc_message msg = { |
| 7780 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7781 | .rpc_argp = &args, |
| 7782 | .rpc_resp = &res, |
| 7783 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7784 | struct nfs4_call_sync_data data = { |
| 7785 | .seq_server = NFS_SERVER(dir), |
| 7786 | .seq_args = &args.seq_args, |
| 7787 | .seq_res = &res.seq_res, |
| 7788 | }; |
| 7789 | struct rpc_task_setup task_setup = { |
| 7790 | .rpc_client = clnt, |
| 7791 | .rpc_message = &msg, |
| 7792 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 7793 | .callback_data = &data, |
| 7794 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 7795 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7796 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7797 | |
| 7798 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7799 | clnt = clp->cl_rpcclient; |
| 7800 | task_setup.rpc_client = clnt; |
| 7801 | |
| 7802 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7803 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7804 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7805 | |
| 7806 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7807 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7808 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7809 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 7810 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7811 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7812 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7813 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7814 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7815 | return status; |
| 7816 | } |
| 7817 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7818 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7819 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7820 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7821 | struct nfs4_exception exception = { |
| 7822 | .interruptible = true, |
| 7823 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7824 | int err; |
| 7825 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7826 | err = -NFS4ERR_WRONGSEC; |
| 7827 | |
| 7828 | /* try to use integrity protection with machine cred */ |
| 7829 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7830 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7831 | |
| 7832 | /* |
| 7833 | * if unable to use integrity protection, or SECINFO with |
| 7834 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7835 | * disallowed by spec, but exists in deployed servers) use |
| 7836 | * the current filesystem's rpc_client and the user cred. |
| 7837 | */ |
| 7838 | if (err == -NFS4ERR_WRONGSEC) |
| 7839 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7840 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7841 | trace_nfs4_secinfo(dir, name, err); |
| 7842 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7843 | &exception); |
| 7844 | } while (exception.retry); |
| 7845 | return err; |
| 7846 | } |
| 7847 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7848 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7849 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7850 | * Check the exchange flags returned by the server for invalid flags, having |
| 7851 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7852 | * DS flags set. |
| 7853 | */ |
| 7854 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7855 | { |
| 7856 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7857 | goto out_inval; |
| 7858 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7859 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7860 | goto out_inval; |
| 7861 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7862 | goto out_inval; |
| 7863 | return NFS_OK; |
| 7864 | out_inval: |
| 7865 | return -NFS4ERR_INVAL; |
| 7866 | } |
| 7867 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7868 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7869 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7870 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7871 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7872 | if (a->server_scope_sz != b->server_scope_sz) |
| 7873 | return false; |
| 7874 | 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] | 7875 | } |
| 7876 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7877 | static void |
| 7878 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7879 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 7880 | struct nfs41_bind_conn_to_session_args *args = task->tk_msg.rpc_argp; |
| 7881 | struct nfs_client *clp = args->client; |
| 7882 | |
| 7883 | switch (task->tk_status) { |
| 7884 | case -NFS4ERR_BADSESSION: |
| 7885 | case -NFS4ERR_DEADSESSION: |
| 7886 | nfs4_schedule_session_recovery(clp->cl_session, |
| 7887 | task->tk_status); |
| 7888 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7889 | } |
| 7890 | |
| 7891 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7892 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7893 | }; |
| 7894 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7895 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7896 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7897 | * |
| 7898 | * The 4.1 client currently uses the same TCP connection for the |
| 7899 | * fore and backchannel. |
| 7900 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7901 | static |
| 7902 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7903 | struct rpc_xprt *xprt, |
| 7904 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7905 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7906 | { |
| 7907 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7908 | struct nfs41_bind_conn_to_session_args args = { |
| 7909 | .client = clp, |
| 7910 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7911 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7912 | struct nfs41_bind_conn_to_session_res res; |
| 7913 | struct rpc_message msg = { |
| 7914 | .rpc_proc = |
| 7915 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7916 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7917 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7918 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7919 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7920 | struct rpc_task_setup task_setup_data = { |
| 7921 | .rpc_client = clnt, |
| 7922 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7923 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7924 | .rpc_message = &msg, |
| 7925 | .flags = RPC_TASK_TIMEOUT, |
| 7926 | }; |
| 7927 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7928 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7929 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7930 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7931 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7932 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7933 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7934 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7935 | args.dir = NFS4_CDFC4_FORE; |
| 7936 | |
| 7937 | task = rpc_run_task(&task_setup_data); |
| 7938 | if (!IS_ERR(task)) { |
| 7939 | status = task->tk_status; |
| 7940 | rpc_put_task(task); |
| 7941 | } else |
| 7942 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7943 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7944 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7945 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7946 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7947 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7948 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7949 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7950 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7951 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7952 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7953 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7954 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7955 | 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] | 7956 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7957 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7958 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7959 | } |
| 7960 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7961 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7962 | return status; |
| 7963 | } |
| 7964 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7965 | struct rpc_bind_conn_calldata { |
| 7966 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7967 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7968 | }; |
| 7969 | |
| 7970 | static int |
| 7971 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7972 | struct rpc_xprt *xprt, |
| 7973 | void *calldata) |
| 7974 | { |
| 7975 | struct rpc_bind_conn_calldata *p = calldata; |
| 7976 | |
| 7977 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7978 | } |
| 7979 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7980 | 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] | 7981 | { |
| 7982 | struct rpc_bind_conn_calldata data = { |
| 7983 | .clp = clp, |
| 7984 | .cred = cred, |
| 7985 | }; |
| 7986 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7987 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7988 | } |
| 7989 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7990 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7991 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7992 | * 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] | 7993 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7994 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7995 | .how = SP4_MACH_CRED, |
| 7996 | .enforce.u.words = { |
| 7997 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7998 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7999 | 1 << (OP_CREATE_SESSION - 32) | |
| 8000 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8001 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8002 | }, |
| 8003 | .allow.u.words = { |
| 8004 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8005 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8006 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8007 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8008 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8009 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8010 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8011 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8012 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8013 | 1 << (OP_FREE_STATEID - 32) | |
| 8014 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8015 | } |
| 8016 | }; |
| 8017 | |
| 8018 | /* |
| 8019 | * Select the state protection mode for client `clp' given the server results |
| 8020 | * from exchange_id in `sp'. |
| 8021 | * |
| 8022 | * Returns 0 on success, negative errno otherwise. |
| 8023 | */ |
| 8024 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8025 | struct nfs41_state_protection *sp) |
| 8026 | { |
| 8027 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8028 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8029 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8030 | 1 << (OP_CREATE_SESSION - 32) | |
| 8031 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8032 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8033 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8034 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8035 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8036 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8037 | |
| 8038 | if (sp->how == SP4_MACH_CRED) { |
| 8039 | /* Print state protect result */ |
| 8040 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8041 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8042 | if (test_bit(i, sp->enforce.u.longs)) |
| 8043 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8044 | if (test_bit(i, sp->allow.u.longs)) |
| 8045 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8046 | } |
| 8047 | |
| 8048 | /* make sure nothing is on enforce list that isn't supported */ |
| 8049 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8050 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8051 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8052 | ret = -EINVAL; |
| 8053 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8054 | } |
| 8055 | } |
| 8056 | |
| 8057 | /* |
| 8058 | * Minimal mode - state operations are allowed to use machine |
| 8059 | * credential. Note this already happens by default, so the |
| 8060 | * client doesn't have to do anything more than the negotiation. |
| 8061 | * |
| 8062 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8063 | * we're already using the machine cred for exchange_id |
| 8064 | * and will never use a different cred. |
| 8065 | */ |
| 8066 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8067 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8068 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8069 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8070 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8071 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8072 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8073 | } else { |
| 8074 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8075 | ret = -EINVAL; |
| 8076 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8077 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8078 | |
| 8079 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8080 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8081 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8082 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8083 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8084 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8085 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8086 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8087 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8088 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8089 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8090 | } |
| 8091 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8092 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8093 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8094 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8095 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8096 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8097 | |
| 8098 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8099 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8100 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8101 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8102 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8103 | |
| 8104 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8105 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8106 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8107 | } |
| 8108 | |
| 8109 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8110 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8111 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8112 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8113 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8114 | out: |
| 8115 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8116 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8117 | } |
| 8118 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8119 | struct nfs41_exchange_id_data { |
| 8120 | struct nfs41_exchange_id_res res; |
| 8121 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8122 | }; |
| 8123 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8124 | static void nfs4_exchange_id_release(void *data) |
| 8125 | { |
| 8126 | struct nfs41_exchange_id_data *cdata = |
| 8127 | (struct nfs41_exchange_id_data *)data; |
| 8128 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8129 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8130 | kfree(cdata->res.impl_id); |
| 8131 | kfree(cdata->res.server_scope); |
| 8132 | kfree(cdata->res.server_owner); |
| 8133 | kfree(cdata); |
| 8134 | } |
| 8135 | |
| 8136 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8137 | .rpc_release = nfs4_exchange_id_release, |
| 8138 | }; |
| 8139 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8140 | /* |
| 8141 | * _nfs4_proc_exchange_id() |
| 8142 | * |
| 8143 | * Wrapper for EXCHANGE_ID operation. |
| 8144 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8145 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8146 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8147 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8148 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8149 | struct rpc_message msg = { |
| 8150 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8151 | .rpc_cred = cred, |
| 8152 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8153 | struct rpc_task_setup task_setup_data = { |
| 8154 | .rpc_client = clp->cl_rpcclient, |
| 8155 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8156 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8157 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8158 | }; |
| 8159 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8160 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8161 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8162 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8163 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8164 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8165 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8166 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8167 | if (!calldata) |
| 8168 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8169 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8170 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8171 | |
| 8172 | status = nfs4_init_uniform_client_string(clp); |
| 8173 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8174 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8175 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8176 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8177 | GFP_NOFS); |
| 8178 | status = -ENOMEM; |
| 8179 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8180 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8181 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8182 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8183 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8184 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8185 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8186 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8187 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8188 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8189 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8190 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8191 | switch (sp4_how) { |
| 8192 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8193 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8194 | break; |
| 8195 | |
| 8196 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8197 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8198 | break; |
| 8199 | |
| 8200 | default: |
| 8201 | /* unsupported! */ |
| 8202 | WARN_ON_ONCE(1); |
| 8203 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8204 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8205 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8206 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8207 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8208 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8209 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8210 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8211 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8212 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8213 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8214 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8215 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8216 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8217 | #endif |
| 8218 | msg.rpc_argp = &calldata->args; |
| 8219 | msg.rpc_resp = &calldata->res; |
| 8220 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8221 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8222 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8223 | |
| 8224 | out_impl_id: |
| 8225 | kfree(calldata->res.impl_id); |
| 8226 | out_server_scope: |
| 8227 | kfree(calldata->res.server_scope); |
| 8228 | out_server_owner: |
| 8229 | kfree(calldata->res.server_owner); |
| 8230 | out_calldata: |
| 8231 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8232 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8233 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8234 | return ERR_PTR(status); |
| 8235 | } |
| 8236 | |
| 8237 | /* |
| 8238 | * _nfs4_proc_exchange_id() |
| 8239 | * |
| 8240 | * Wrapper for EXCHANGE_ID operation. |
| 8241 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8242 | 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] | 8243 | u32 sp4_how) |
| 8244 | { |
| 8245 | struct rpc_task *task; |
| 8246 | struct nfs41_exchange_id_args *argp; |
| 8247 | struct nfs41_exchange_id_res *resp; |
| 8248 | int status; |
| 8249 | |
| 8250 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8251 | if (IS_ERR(task)) |
| 8252 | return PTR_ERR(task); |
| 8253 | |
| 8254 | argp = task->tk_msg.rpc_argp; |
| 8255 | resp = task->tk_msg.rpc_resp; |
| 8256 | status = task->tk_status; |
| 8257 | if (status != 0) |
| 8258 | goto out; |
| 8259 | |
| 8260 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 8261 | if (status != 0) |
| 8262 | goto out; |
| 8263 | |
| 8264 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8265 | if (status != 0) |
| 8266 | goto out; |
| 8267 | |
| 8268 | clp->cl_clientid = resp->clientid; |
| 8269 | clp->cl_exchange_flags = resp->flags; |
| 8270 | clp->cl_seqid = resp->seqid; |
| 8271 | /* Client ID is not confirmed */ |
| 8272 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8273 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8274 | &clp->cl_session->session_state); |
| 8275 | |
| 8276 | if (clp->cl_serverscope != NULL && |
| 8277 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8278 | resp->server_scope)) { |
| 8279 | dprintk("%s: server_scope mismatch detected\n", |
| 8280 | __func__); |
| 8281 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8282 | } |
| 8283 | |
| 8284 | swap(clp->cl_serverowner, resp->server_owner); |
| 8285 | swap(clp->cl_serverscope, resp->server_scope); |
| 8286 | swap(clp->cl_implid, resp->impl_id); |
| 8287 | |
| 8288 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8289 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8290 | sizeof(clp->cl_confirm.data)); |
| 8291 | out: |
| 8292 | trace_nfs4_exchange_id(clp, status); |
| 8293 | rpc_put_task(task); |
| 8294 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8295 | } |
| 8296 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8297 | /* |
| 8298 | * nfs4_proc_exchange_id() |
| 8299 | * |
| 8300 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8301 | * |
| 8302 | * Since the clientid has expired, all compounds using sessions |
| 8303 | * associated with the stale clientid will be returning |
| 8304 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8305 | * be in some phase of session reset. |
| 8306 | * |
| 8307 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8308 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8309 | 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] | 8310 | { |
| 8311 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8312 | int status; |
| 8313 | |
| 8314 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8315 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8316 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8317 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8318 | if (!status) |
| 8319 | return 0; |
| 8320 | } |
| 8321 | |
| 8322 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8323 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8324 | } |
| 8325 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8326 | /** |
| 8327 | * nfs4_test_session_trunk |
| 8328 | * |
| 8329 | * This is an add_xprt_test() test function called from |
| 8330 | * rpc_clnt_setup_test_and_add_xprt. |
| 8331 | * |
| 8332 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8333 | * and is dereferrenced in nfs4_exchange_id_release |
| 8334 | * |
| 8335 | * Upon success, add the new transport to the rpc_clnt |
| 8336 | * |
| 8337 | * @clnt: struct rpc_clnt to get new transport |
| 8338 | * @xprt: the rpc_xprt to test |
| 8339 | * @data: call data for _nfs4_proc_exchange_id. |
| 8340 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8341 | 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] | 8342 | void *data) |
| 8343 | { |
| 8344 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8345 | struct rpc_task *task; |
| 8346 | int status; |
| 8347 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8348 | u32 sp4_how; |
| 8349 | |
| 8350 | dprintk("--> %s try %s\n", __func__, |
| 8351 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8352 | |
| 8353 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8354 | |
| 8355 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8356 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8357 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8358 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8359 | |
| 8360 | status = task->tk_status; |
| 8361 | if (status == 0) |
| 8362 | status = nfs4_detect_session_trunking(adata->clp, |
| 8363 | task->tk_msg.rpc_resp, xprt); |
| 8364 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8365 | if (status == 0) |
| 8366 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8367 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8368 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8369 | } |
| 8370 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8371 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8372 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8373 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8374 | { |
| 8375 | struct rpc_message msg = { |
| 8376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8377 | .rpc_argp = clp, |
| 8378 | .rpc_cred = cred, |
| 8379 | }; |
| 8380 | int status; |
| 8381 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8382 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8383 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8384 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8385 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8386 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8387 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8388 | return status; |
| 8389 | } |
| 8390 | |
| 8391 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8392 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8393 | { |
| 8394 | unsigned int loop; |
| 8395 | int ret; |
| 8396 | |
| 8397 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8398 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8399 | switch (ret) { |
| 8400 | case -NFS4ERR_DELAY: |
| 8401 | case -NFS4ERR_CLIENTID_BUSY: |
| 8402 | ssleep(1); |
| 8403 | break; |
| 8404 | default: |
| 8405 | return ret; |
| 8406 | } |
| 8407 | } |
| 8408 | return 0; |
| 8409 | } |
| 8410 | |
| 8411 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8412 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8413 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8414 | int ret = 0; |
| 8415 | |
| 8416 | if (clp->cl_mvops->minor_version < 1) |
| 8417 | goto out; |
| 8418 | if (clp->cl_exchange_flags == 0) |
| 8419 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8420 | if (clp->cl_preserve_clid) |
| 8421 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8422 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8423 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8424 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8425 | switch (ret) { |
| 8426 | case 0: |
| 8427 | case -NFS4ERR_STALE_CLIENTID: |
| 8428 | clp->cl_exchange_flags = 0; |
| 8429 | } |
| 8430 | out: |
| 8431 | return ret; |
| 8432 | } |
| 8433 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8434 | #endif /* CONFIG_NFS_V4_1 */ |
| 8435 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8436 | struct nfs4_get_lease_time_data { |
| 8437 | struct nfs4_get_lease_time_args *args; |
| 8438 | struct nfs4_get_lease_time_res *res; |
| 8439 | struct nfs_client *clp; |
| 8440 | }; |
| 8441 | |
| 8442 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8443 | void *calldata) |
| 8444 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8445 | struct nfs4_get_lease_time_data *data = |
| 8446 | (struct nfs4_get_lease_time_data *)calldata; |
| 8447 | |
| 8448 | dprintk("--> %s\n", __func__); |
| 8449 | /* just setup sequence, do not trigger session recovery |
| 8450 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8451 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8452 | &data->args->la_seq_args, |
| 8453 | &data->res->lr_seq_res, |
| 8454 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8455 | dprintk("<-- %s\n", __func__); |
| 8456 | } |
| 8457 | |
| 8458 | /* |
| 8459 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8460 | * from sequence operation or clientid errors. |
| 8461 | */ |
| 8462 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8463 | { |
| 8464 | struct nfs4_get_lease_time_data *data = |
| 8465 | (struct nfs4_get_lease_time_data *)calldata; |
| 8466 | |
| 8467 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8468 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8469 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8470 | switch (task->tk_status) { |
| 8471 | case -NFS4ERR_DELAY: |
| 8472 | case -NFS4ERR_GRACE: |
| 8473 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8474 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8475 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8476 | /* fall through */ |
| 8477 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8478 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8479 | return; |
| 8480 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8481 | dprintk("<-- %s\n", __func__); |
| 8482 | } |
| 8483 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8484 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8485 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8486 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8487 | }; |
| 8488 | |
| 8489 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8490 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8491 | struct nfs4_get_lease_time_args args; |
| 8492 | struct nfs4_get_lease_time_res res = { |
| 8493 | .lr_fsinfo = fsinfo, |
| 8494 | }; |
| 8495 | struct nfs4_get_lease_time_data data = { |
| 8496 | .args = &args, |
| 8497 | .res = &res, |
| 8498 | .clp = clp, |
| 8499 | }; |
| 8500 | struct rpc_message msg = { |
| 8501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8502 | .rpc_argp = &args, |
| 8503 | .rpc_resp = &res, |
| 8504 | }; |
| 8505 | struct rpc_task_setup task_setup = { |
| 8506 | .rpc_client = clp->cl_rpcclient, |
| 8507 | .rpc_message = &msg, |
| 8508 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8509 | .callback_data = &data, |
| 8510 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8511 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8512 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8513 | 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] | 8514 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8515 | } |
| 8516 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8517 | #ifdef CONFIG_NFS_V4_1 |
| 8518 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8519 | /* |
| 8520 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8521 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8522 | * use them. |
| 8523 | * |
| 8524 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8525 | * always set csa_cachethis to FALSE because the current implementation |
| 8526 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8527 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8528 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8529 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8530 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8531 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8532 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8533 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8534 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8535 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8536 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8537 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8538 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8539 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8540 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8541 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8542 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8543 | |
| 8544 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8545 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8546 | __func__, |
| 8547 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8548 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8549 | |
| 8550 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8551 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8552 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8553 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8554 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8555 | 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] | 8556 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8557 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8558 | |
| 8559 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8560 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8561 | __func__, |
| 8562 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8563 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8564 | args->bc_attrs.max_reqs); |
| 8565 | } |
| 8566 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8567 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8568 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8569 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8570 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8571 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8572 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8573 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8574 | return -EINVAL; |
| 8575 | /* |
| 8576 | * Our requested max_ops is the minimum we need; we're not |
| 8577 | * prepared to break up compounds into smaller pieces than that. |
| 8578 | * So, no point even trying to continue if the server won't |
| 8579 | * cooperate: |
| 8580 | */ |
| 8581 | if (rcvd->max_ops < sent->max_ops) |
| 8582 | return -EINVAL; |
| 8583 | if (rcvd->max_reqs == 0) |
| 8584 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8585 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8586 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8587 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8588 | } |
| 8589 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8590 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8591 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8592 | { |
| 8593 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8594 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8595 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8596 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8597 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8598 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8599 | return -EINVAL; |
| 8600 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8601 | return -EINVAL; |
| 8602 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8603 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8604 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8605 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8606 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8607 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8608 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8609 | return 0; |
| 8610 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8611 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8612 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8613 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8614 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8615 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8616 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8617 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8618 | if (ret) |
| 8619 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8620 | return nfs4_verify_back_channel_attrs(args, res); |
| 8621 | } |
| 8622 | |
| 8623 | static void nfs4_update_session(struct nfs4_session *session, |
| 8624 | struct nfs41_create_session_res *res) |
| 8625 | { |
| 8626 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8627 | /* Mark client id and session as being confirmed */ |
| 8628 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8629 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8630 | session->flags = res->flags; |
| 8631 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8632 | if (res->flags & SESSION4_BACK_CHAN) |
| 8633 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8634 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8635 | } |
| 8636 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8637 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8638 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8639 | { |
| 8640 | struct nfs4_session *session = clp->cl_session; |
| 8641 | struct nfs41_create_session_args args = { |
| 8642 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8643 | .clientid = clp->cl_clientid, |
| 8644 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8645 | .cb_program = NFS4_CALLBACK, |
| 8646 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8647 | struct nfs41_create_session_res res; |
| 8648 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8649 | struct rpc_message msg = { |
| 8650 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8651 | .rpc_argp = &args, |
| 8652 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8653 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8654 | }; |
| 8655 | int status; |
| 8656 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8657 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8658 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8659 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8660 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8661 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8662 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8663 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8664 | switch (status) { |
| 8665 | case -NFS4ERR_STALE_CLIENTID: |
| 8666 | case -NFS4ERR_DELAY: |
| 8667 | case -ETIMEDOUT: |
| 8668 | case -EACCES: |
| 8669 | case -EAGAIN: |
| 8670 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 8671 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8672 | |
| 8673 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8674 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8675 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8676 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8677 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8678 | if (status) |
| 8679 | goto out; |
| 8680 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8681 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8682 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8683 | return status; |
| 8684 | } |
| 8685 | |
| 8686 | /* |
| 8687 | * Issues a CREATE_SESSION operation to the server. |
| 8688 | * It is the responsibility of the caller to verify the session is |
| 8689 | * expired before calling this routine. |
| 8690 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8691 | 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] | 8692 | { |
| 8693 | int status; |
| 8694 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8695 | struct nfs4_session *session = clp->cl_session; |
| 8696 | |
| 8697 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8698 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8699 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8700 | if (status) |
| 8701 | goto out; |
| 8702 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8703 | /* Init or reset the session slot tables */ |
| 8704 | status = nfs4_setup_session_slot_tables(session); |
| 8705 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8706 | if (status) |
| 8707 | goto out; |
| 8708 | |
| 8709 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8710 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8711 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8712 | out: |
| 8713 | dprintk("<-- %s\n", __func__); |
| 8714 | return status; |
| 8715 | } |
| 8716 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8717 | /* |
| 8718 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8719 | * The caller must serialize access to this routine. |
| 8720 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8721 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8722 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8723 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8724 | struct rpc_message msg = { |
| 8725 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8726 | .rpc_argp = session, |
| 8727 | .rpc_cred = cred, |
| 8728 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8729 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8730 | |
| 8731 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8732 | |
| 8733 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8734 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8735 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8736 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8737 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8738 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8739 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8740 | |
| 8741 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8742 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8743 | "Session has been destroyed regardless...\n", status); |
| 8744 | |
| 8745 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8746 | return status; |
| 8747 | } |
| 8748 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8749 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8750 | * Renew the cl_session lease. |
| 8751 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8752 | struct nfs4_sequence_data { |
| 8753 | struct nfs_client *clp; |
| 8754 | struct nfs4_sequence_args args; |
| 8755 | struct nfs4_sequence_res res; |
| 8756 | }; |
| 8757 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8758 | static void nfs41_sequence_release(void *data) |
| 8759 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8760 | struct nfs4_sequence_data *calldata = data; |
| 8761 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8762 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8763 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8764 | nfs4_schedule_state_renewal(clp); |
| 8765 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8766 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8767 | } |
| 8768 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8769 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8770 | { |
| 8771 | switch(task->tk_status) { |
| 8772 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8773 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8774 | return -EAGAIN; |
| 8775 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8776 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8777 | } |
| 8778 | return 0; |
| 8779 | } |
| 8780 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8781 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8782 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8783 | struct nfs4_sequence_data *calldata = data; |
| 8784 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8785 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8786 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8787 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8788 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8789 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8790 | if (task->tk_status < 0) { |
| 8791 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8792 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8793 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8794 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8795 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8796 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8797 | return; |
| 8798 | } |
| 8799 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8800 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8801 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8802 | dprintk("<-- %s\n", __func__); |
| 8803 | } |
| 8804 | |
| 8805 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8806 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8807 | struct nfs4_sequence_data *calldata = data; |
| 8808 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8809 | struct nfs4_sequence_args *args; |
| 8810 | struct nfs4_sequence_res *res; |
| 8811 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8812 | args = task->tk_msg.rpc_argp; |
| 8813 | res = task->tk_msg.rpc_resp; |
| 8814 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8815 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8816 | } |
| 8817 | |
| 8818 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8819 | .rpc_call_done = nfs41_sequence_call_done, |
| 8820 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8821 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8822 | }; |
| 8823 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8824 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8825 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8826 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8827 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8828 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8829 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8830 | struct rpc_message msg = { |
| 8831 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8832 | .rpc_cred = cred, |
| 8833 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8834 | struct rpc_task_setup task_setup_data = { |
| 8835 | .rpc_client = clp->cl_rpcclient, |
| 8836 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8837 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8838 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8839 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8840 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8841 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8842 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8843 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8844 | goto out_err; |
| 8845 | |
| 8846 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8847 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8848 | if (calldata == NULL) |
| 8849 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8850 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8851 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8852 | msg.rpc_argp = &calldata->args; |
| 8853 | msg.rpc_resp = &calldata->res; |
| 8854 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8855 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8856 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8857 | ret = rpc_run_task(&task_setup_data); |
| 8858 | if (IS_ERR(ret)) |
| 8859 | goto out_err; |
| 8860 | return ret; |
| 8861 | out_put_clp: |
| 8862 | nfs_put_client(clp); |
| 8863 | out_err: |
| 8864 | nfs41_release_slot(slot); |
| 8865 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8866 | } |
| 8867 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8868 | 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] | 8869 | { |
| 8870 | struct rpc_task *task; |
| 8871 | int ret = 0; |
| 8872 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8873 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8874 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8875 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8876 | if (IS_ERR(task)) |
| 8877 | ret = PTR_ERR(task); |
| 8878 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8879 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8880 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8881 | return ret; |
| 8882 | } |
| 8883 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8884 | 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] | 8885 | { |
| 8886 | struct rpc_task *task; |
| 8887 | int ret; |
| 8888 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8889 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8890 | if (IS_ERR(task)) { |
| 8891 | ret = PTR_ERR(task); |
| 8892 | goto out; |
| 8893 | } |
| 8894 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8895 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8896 | ret = task->tk_status; |
| 8897 | rpc_put_task(task); |
| 8898 | out: |
| 8899 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8900 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8901 | } |
| 8902 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8903 | struct nfs4_reclaim_complete_data { |
| 8904 | struct nfs_client *clp; |
| 8905 | struct nfs41_reclaim_complete_args arg; |
| 8906 | struct nfs41_reclaim_complete_res res; |
| 8907 | }; |
| 8908 | |
| 8909 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8910 | { |
| 8911 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8912 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8913 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8914 | &calldata->arg.seq_args, |
| 8915 | &calldata->res.seq_res, |
| 8916 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8917 | } |
| 8918 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8919 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8920 | { |
| 8921 | switch(task->tk_status) { |
| 8922 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8923 | wake_up_all(&clp->cl_lock_waitq); |
| 8924 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8925 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8926 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8927 | break; |
| 8928 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8929 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8930 | /* fall through */ |
| 8931 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8932 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8933 | case -NFS4ERR_BADSESSION: |
| 8934 | case -NFS4ERR_DEADSESSION: |
| 8935 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8936 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8937 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8938 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8939 | } |
| 8940 | return 0; |
| 8941 | } |
| 8942 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8943 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8944 | { |
| 8945 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8946 | struct nfs_client *clp = calldata->clp; |
| 8947 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8948 | |
| 8949 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8950 | if (!nfs41_sequence_done(task, res)) |
| 8951 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8952 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8953 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8954 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8955 | rpc_restart_call_prepare(task); |
| 8956 | return; |
| 8957 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8958 | dprintk("<-- %s\n", __func__); |
| 8959 | } |
| 8960 | |
| 8961 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8962 | { |
| 8963 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8964 | |
| 8965 | kfree(calldata); |
| 8966 | } |
| 8967 | |
| 8968 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8969 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8970 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8971 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8972 | }; |
| 8973 | |
| 8974 | /* |
| 8975 | * Issue a global reclaim complete. |
| 8976 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8977 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8978 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8979 | { |
| 8980 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8981 | struct rpc_message msg = { |
| 8982 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8983 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8984 | }; |
| 8985 | struct rpc_task_setup task_setup_data = { |
| 8986 | .rpc_client = clp->cl_rpcclient, |
| 8987 | .rpc_message = &msg, |
| 8988 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 8989 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8990 | }; |
| 8991 | int status = -ENOMEM; |
| 8992 | |
| 8993 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8994 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8995 | if (calldata == NULL) |
| 8996 | goto out; |
| 8997 | calldata->clp = clp; |
| 8998 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8999 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9000 | 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] | 9001 | msg.rpc_argp = &calldata->arg; |
| 9002 | msg.rpc_resp = &calldata->res; |
| 9003 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9004 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9005 | out: |
| 9006 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9007 | return status; |
| 9008 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9009 | |
| 9010 | static void |
| 9011 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9012 | { |
| 9013 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9014 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9015 | |
| 9016 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9017 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9018 | &lgp->res.seq_res, task); |
| 9019 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9020 | } |
| 9021 | |
| 9022 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9023 | { |
| 9024 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9025 | |
| 9026 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9027 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9028 | dprintk("<-- %s\n", __func__); |
| 9029 | } |
| 9030 | |
| 9031 | static int |
| 9032 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9033 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9034 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9035 | struct inode *inode = lgp->args.inode; |
| 9036 | struct nfs_server *server = NFS_SERVER(inode); |
| 9037 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9038 | int nfs4err = task->tk_status; |
| 9039 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9040 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9041 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9042 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9043 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9044 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9045 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9046 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9047 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9048 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9049 | |
| 9050 | /* |
| 9051 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9052 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9053 | * retry go inband. |
| 9054 | */ |
| 9055 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9056 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9057 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9058 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9059 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9060 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9061 | */ |
| 9062 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9063 | status = -EOVERFLOW; |
| 9064 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9065 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9066 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9067 | * (or clients) writing to the same RAID stripe except when |
| 9068 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9069 | * |
| 9070 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9071 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9072 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9073 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9074 | if (lgp->args.minlength == 0) { |
| 9075 | status = -EOVERFLOW; |
| 9076 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9077 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9078 | status = -EBUSY; |
| 9079 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9080 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9081 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9082 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9083 | case -NFS4ERR_DELEG_REVOKED: |
| 9084 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9085 | case -NFS4ERR_EXPIRED: |
| 9086 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9087 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9088 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9089 | lo = NFS_I(inode)->layout; |
| 9090 | /* If the open stateid was bad, then recover it. */ |
| 9091 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9092 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9093 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9094 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9095 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9096 | break; |
| 9097 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9098 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9099 | /* |
| 9100 | * Mark the bad layout state as invalid, then retry |
| 9101 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9102 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9103 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9104 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9105 | pnfs_free_lseg_list(&head); |
| 9106 | status = -EAGAIN; |
| 9107 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9108 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9109 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9110 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9111 | if (!status) { |
| 9112 | if (exception->retry) |
| 9113 | status = -EAGAIN; |
| 9114 | else |
| 9115 | status = err; |
| 9116 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9117 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9118 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9119 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9120 | } |
| 9121 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9122 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9123 | { |
| 9124 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9125 | return nfs_page_array_len(0, max_resp_sz); |
| 9126 | } |
| 9127 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9128 | static void nfs4_layoutget_release(void *calldata) |
| 9129 | { |
| 9130 | struct nfs4_layoutget *lgp = calldata; |
| 9131 | |
| 9132 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9133 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9134 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9135 | dprintk("<-- %s\n", __func__); |
| 9136 | } |
| 9137 | |
| 9138 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9139 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9140 | .rpc_call_done = nfs4_layoutget_done, |
| 9141 | .rpc_release = nfs4_layoutget_release, |
| 9142 | }; |
| 9143 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9144 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9145 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9146 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9147 | struct inode *inode = lgp->args.inode; |
| 9148 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9149 | struct rpc_task *task; |
| 9150 | struct rpc_message msg = { |
| 9151 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9152 | .rpc_argp = &lgp->args, |
| 9153 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9154 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9155 | }; |
| 9156 | struct rpc_task_setup task_setup_data = { |
| 9157 | .rpc_client = server->client, |
| 9158 | .rpc_message = &msg, |
| 9159 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9160 | .callback_data = lgp, |
| 9161 | .flags = RPC_TASK_ASYNC, |
| 9162 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9163 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9164 | struct nfs4_exception exception = { |
| 9165 | .inode = inode, |
| 9166 | .timeout = *timeout, |
| 9167 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9168 | int status = 0; |
| 9169 | |
| 9170 | dprintk("--> %s\n", __func__); |
| 9171 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9172 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9173 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9174 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9175 | 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] | 9176 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9177 | task = rpc_run_task(&task_setup_data); |
| 9178 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9179 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9180 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9181 | if (status != 0) |
| 9182 | goto out; |
| 9183 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9184 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9185 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9186 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9187 | } else if (lgp->res.layoutp->len == 0) { |
| 9188 | status = -EAGAIN; |
| 9189 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9190 | } else |
| 9191 | lseg = pnfs_layout_process(lgp); |
| 9192 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9193 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9194 | &lgp->args.range, |
| 9195 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9196 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9197 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9198 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9199 | rpc_put_task(task); |
| 9200 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9201 | if (status) |
| 9202 | return ERR_PTR(status); |
| 9203 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9204 | } |
| 9205 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9206 | static void |
| 9207 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9208 | { |
| 9209 | struct nfs4_layoutreturn *lrp = calldata; |
| 9210 | |
| 9211 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9212 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9213 | &lrp->args.seq_args, |
| 9214 | &lrp->res.seq_res, |
| 9215 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9216 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9217 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9218 | } |
| 9219 | |
| 9220 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9221 | { |
| 9222 | struct nfs4_layoutreturn *lrp = calldata; |
| 9223 | struct nfs_server *server; |
| 9224 | |
| 9225 | dprintk("--> %s\n", __func__); |
| 9226 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9227 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9228 | return; |
| 9229 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9230 | /* |
| 9231 | * Was there an RPC level error? Assume the call succeeded, |
| 9232 | * and that we need to release the layout |
| 9233 | */ |
| 9234 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9235 | lrp->res.lrs_present = 0; |
| 9236 | return; |
| 9237 | } |
| 9238 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9239 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9240 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9241 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9242 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9243 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9244 | lrp->args.inode)) |
| 9245 | goto out_restart; |
| 9246 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9247 | default: |
| 9248 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9249 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9250 | case 0: |
| 9251 | break; |
| 9252 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9253 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9254 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9255 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9256 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9257 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9258 | return; |
| 9259 | out_restart: |
| 9260 | task->tk_status = 0; |
| 9261 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9262 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9263 | } |
| 9264 | |
| 9265 | static void nfs4_layoutreturn_release(void *calldata) |
| 9266 | { |
| 9267 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9268 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9269 | |
| 9270 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9271 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9272 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9273 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9274 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9275 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9276 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9277 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9278 | kfree(calldata); |
| 9279 | dprintk("<-- %s\n", __func__); |
| 9280 | } |
| 9281 | |
| 9282 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9283 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9284 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9285 | .rpc_release = nfs4_layoutreturn_release, |
| 9286 | }; |
| 9287 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9288 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9289 | { |
| 9290 | struct rpc_task *task; |
| 9291 | struct rpc_message msg = { |
| 9292 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9293 | .rpc_argp = &lrp->args, |
| 9294 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9295 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9296 | }; |
| 9297 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9298 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9299 | .rpc_message = &msg, |
| 9300 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9301 | .callback_data = lrp, |
| 9302 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9303 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9304 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9305 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9306 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9307 | &task_setup_data.rpc_client, &msg); |
| 9308 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9309 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9310 | if (!sync) { |
| 9311 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9312 | if (!lrp->inode) { |
| 9313 | nfs4_layoutreturn_release(lrp); |
| 9314 | return -EAGAIN; |
| 9315 | } |
| 9316 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9317 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9318 | 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] | 9319 | task = rpc_run_task(&task_setup_data); |
| 9320 | if (IS_ERR(task)) |
| 9321 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9322 | if (sync) |
| 9323 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9324 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9325 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9326 | rpc_put_task(task); |
| 9327 | return status; |
| 9328 | } |
| 9329 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9330 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9331 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9332 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9333 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9334 | { |
| 9335 | struct nfs4_getdeviceinfo_args args = { |
| 9336 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9337 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9338 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9339 | }; |
| 9340 | struct nfs4_getdeviceinfo_res res = { |
| 9341 | .pdev = pdev, |
| 9342 | }; |
| 9343 | struct rpc_message msg = { |
| 9344 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9345 | .rpc_argp = &args, |
| 9346 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9347 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9348 | }; |
| 9349 | int status; |
| 9350 | |
| 9351 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9352 | 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] | 9353 | if (res.notification & ~args.notify_types) |
| 9354 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9355 | if (res.notification != args.notify_types) |
| 9356 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9357 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9358 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9359 | |
| 9360 | return status; |
| 9361 | } |
| 9362 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9363 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9364 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9365 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9366 | { |
| 9367 | struct nfs4_exception exception = { }; |
| 9368 | int err; |
| 9369 | |
| 9370 | do { |
| 9371 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9372 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9373 | &exception); |
| 9374 | } while (exception.retry); |
| 9375 | return err; |
| 9376 | } |
| 9377 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9378 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9379 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9380 | { |
| 9381 | struct nfs4_layoutcommit_data *data = calldata; |
| 9382 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9383 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9384 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9385 | &data->args.seq_args, |
| 9386 | &data->res.seq_res, |
| 9387 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9388 | } |
| 9389 | |
| 9390 | static void |
| 9391 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9392 | { |
| 9393 | struct nfs4_layoutcommit_data *data = calldata; |
| 9394 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9395 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9396 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9397 | return; |
| 9398 | |
| 9399 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9400 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9401 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9402 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9403 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9404 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9405 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9406 | break; |
| 9407 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9408 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9409 | rpc_restart_call_prepare(task); |
| 9410 | return; |
| 9411 | } |
| 9412 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9413 | } |
| 9414 | |
| 9415 | static void nfs4_layoutcommit_release(void *calldata) |
| 9416 | { |
| 9417 | struct nfs4_layoutcommit_data *data = calldata; |
| 9418 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9419 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9420 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9421 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9422 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9423 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9424 | kfree(data); |
| 9425 | } |
| 9426 | |
| 9427 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9428 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9429 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9430 | .rpc_release = nfs4_layoutcommit_release, |
| 9431 | }; |
| 9432 | |
| 9433 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9434 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9435 | { |
| 9436 | struct rpc_message msg = { |
| 9437 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9438 | .rpc_argp = &data->args, |
| 9439 | .rpc_resp = &data->res, |
| 9440 | .rpc_cred = data->cred, |
| 9441 | }; |
| 9442 | struct rpc_task_setup task_setup_data = { |
| 9443 | .task = &data->task, |
| 9444 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9445 | .rpc_message = &msg, |
| 9446 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9447 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9448 | }; |
| 9449 | struct rpc_task *task; |
| 9450 | int status = 0; |
| 9451 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9452 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9453 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9454 | data->args.lastbytewritten, |
| 9455 | data->args.inode->i_ino); |
| 9456 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9457 | if (!sync) { |
| 9458 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9459 | if (data->inode == NULL) { |
| 9460 | nfs4_layoutcommit_release(data); |
| 9461 | return -EAGAIN; |
| 9462 | } |
| 9463 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9464 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9465 | 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] | 9466 | task = rpc_run_task(&task_setup_data); |
| 9467 | if (IS_ERR(task)) |
| 9468 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9469 | if (sync) |
| 9470 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9471 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9472 | dprintk("%s: status %d\n", __func__, status); |
| 9473 | rpc_put_task(task); |
| 9474 | return status; |
| 9475 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9476 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9477 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9478 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9479 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9480 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9481 | static int |
| 9482 | _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] | 9483 | struct nfs_fsinfo *info, |
| 9484 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9485 | { |
| 9486 | struct nfs41_secinfo_no_name_args args = { |
| 9487 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9488 | }; |
| 9489 | struct nfs4_secinfo_res res = { |
| 9490 | .flavors = flavors, |
| 9491 | }; |
| 9492 | struct rpc_message msg = { |
| 9493 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9494 | .rpc_argp = &args, |
| 9495 | .rpc_resp = &res, |
| 9496 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9497 | struct rpc_clnt *clnt = server->client; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9498 | struct nfs4_call_sync_data data = { |
| 9499 | .seq_server = server, |
| 9500 | .seq_args = &args.seq_args, |
| 9501 | .seq_res = &res.seq_res, |
| 9502 | }; |
| 9503 | struct rpc_task_setup task_setup = { |
| 9504 | .rpc_client = server->client, |
| 9505 | .rpc_message = &msg, |
| 9506 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9507 | .callback_data = &data, |
| 9508 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9509 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9510 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9511 | int status; |
| 9512 | |
| 9513 | if (use_integrity) { |
| 9514 | clnt = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9515 | task_setup.rpc_client = clnt; |
| 9516 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9517 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9518 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9519 | } |
| 9520 | |
| 9521 | dprintk("--> %s\n", __func__); |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9522 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9523 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9524 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9525 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9526 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9527 | |
| 9528 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9529 | } |
| 9530 | |
| 9531 | static int |
| 9532 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9533 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9534 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9535 | struct nfs4_exception exception = { |
| 9536 | .interruptible = true, |
| 9537 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9538 | int err; |
| 9539 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9540 | /* first try using integrity protection */ |
| 9541 | err = -NFS4ERR_WRONGSEC; |
| 9542 | |
| 9543 | /* try to use integrity protection with machine cred */ |
| 9544 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9545 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9546 | flavors, true); |
| 9547 | |
| 9548 | /* |
| 9549 | * if unable to use integrity protection, or SECINFO with |
| 9550 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9551 | * disallowed by spec, but exists in deployed servers) use |
| 9552 | * the current filesystem's rpc_client and the user cred. |
| 9553 | */ |
| 9554 | if (err == -NFS4ERR_WRONGSEC) |
| 9555 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9556 | flavors, false); |
| 9557 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9558 | switch (err) { |
| 9559 | case 0: |
| 9560 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9561 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9562 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9563 | default: |
| 9564 | err = nfs4_handle_exception(server, err, &exception); |
| 9565 | } |
| 9566 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9567 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9568 | return err; |
| 9569 | } |
| 9570 | |
| 9571 | static int |
| 9572 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9573 | struct nfs_fsinfo *info) |
| 9574 | { |
| 9575 | int err; |
| 9576 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9577 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9578 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9579 | struct nfs4_secinfo4 *secinfo; |
| 9580 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9581 | |
| 9582 | page = alloc_page(GFP_KERNEL); |
| 9583 | if (!page) { |
| 9584 | err = -ENOMEM; |
| 9585 | goto out; |
| 9586 | } |
| 9587 | |
| 9588 | flavors = page_address(page); |
| 9589 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9590 | |
| 9591 | /* |
| 9592 | * Fall back on "guess and check" method if |
| 9593 | * the server doesn't support SECINFO_NO_NAME |
| 9594 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9595 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9596 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9597 | goto out_freepage; |
| 9598 | } |
| 9599 | if (err) |
| 9600 | goto out_freepage; |
| 9601 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9602 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9603 | secinfo = &flavors->flavors[i]; |
| 9604 | |
| 9605 | switch (secinfo->flavor) { |
| 9606 | case RPC_AUTH_NULL: |
| 9607 | case RPC_AUTH_UNIX: |
| 9608 | case RPC_AUTH_GSS: |
| 9609 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9610 | &secinfo->flavor_info); |
| 9611 | break; |
| 9612 | default: |
| 9613 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9614 | break; |
| 9615 | } |
| 9616 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9617 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9618 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9619 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9620 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9621 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9622 | info, flavor); |
| 9623 | if (!err) |
| 9624 | break; |
| 9625 | } |
| 9626 | } |
| 9627 | |
| 9628 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9629 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9630 | |
| 9631 | out_freepage: |
| 9632 | put_page(page); |
| 9633 | if (err == -EACCES) |
| 9634 | return -EPERM; |
| 9635 | out: |
| 9636 | return err; |
| 9637 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9638 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9639 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9640 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9641 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9642 | { |
| 9643 | int status; |
| 9644 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9645 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9646 | }; |
| 9647 | struct nfs41_test_stateid_res res; |
| 9648 | struct rpc_message msg = { |
| 9649 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9650 | .rpc_argp = &args, |
| 9651 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9652 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9653 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9654 | struct rpc_clnt *rpc_client = server->client; |
| 9655 | |
| 9656 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9657 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9658 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9659 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9660 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9661 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9662 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9663 | if (status != NFS_OK) { |
| 9664 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9665 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9666 | } |
| 9667 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9668 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9669 | } |
| 9670 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9671 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9672 | int err, struct nfs4_exception *exception) |
| 9673 | { |
| 9674 | exception->retry = 0; |
| 9675 | switch(err) { |
| 9676 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9677 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9678 | nfs4_handle_exception(server, err, exception); |
| 9679 | break; |
| 9680 | case -NFS4ERR_BADSESSION: |
| 9681 | case -NFS4ERR_BADSLOT: |
| 9682 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9683 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9684 | case -NFS4ERR_DEADSESSION: |
| 9685 | nfs4_do_handle_exception(server, err, exception); |
| 9686 | } |
| 9687 | } |
| 9688 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9689 | /** |
| 9690 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9691 | * |
| 9692 | * @server: server / transport on which to perform the operation |
| 9693 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9694 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9695 | * |
| 9696 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9697 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9698 | * failed or the state ID is not currently valid. |
| 9699 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9700 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9701 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9702 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9703 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9704 | struct nfs4_exception exception = { |
| 9705 | .interruptible = true, |
| 9706 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9707 | int err; |
| 9708 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9709 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9710 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9711 | } while (exception.retry); |
| 9712 | return err; |
| 9713 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9714 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9715 | struct nfs_free_stateid_data { |
| 9716 | struct nfs_server *server; |
| 9717 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9718 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9719 | }; |
| 9720 | |
| 9721 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9722 | { |
| 9723 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9724 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9725 | &data->args.seq_args, |
| 9726 | &data->res.seq_res, |
| 9727 | task); |
| 9728 | } |
| 9729 | |
| 9730 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9731 | { |
| 9732 | struct nfs_free_stateid_data *data = calldata; |
| 9733 | |
| 9734 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9735 | |
| 9736 | switch (task->tk_status) { |
| 9737 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9738 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9739 | rpc_restart_call_prepare(task); |
| 9740 | } |
| 9741 | } |
| 9742 | |
| 9743 | static void nfs41_free_stateid_release(void *calldata) |
| 9744 | { |
| 9745 | kfree(calldata); |
| 9746 | } |
| 9747 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9748 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9749 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9750 | .rpc_call_done = nfs41_free_stateid_done, |
| 9751 | .rpc_release = nfs41_free_stateid_release, |
| 9752 | }; |
| 9753 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9754 | /** |
| 9755 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9756 | * |
| 9757 | * @server: server / transport on which to perform the operation |
| 9758 | * @stateid: state ID to release |
| 9759 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9760 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9761 | * |
| 9762 | * Note: this function is always asynchronous. |
| 9763 | */ |
| 9764 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9765 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9766 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9767 | bool privileged) |
| 9768 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9769 | struct rpc_message msg = { |
| 9770 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9771 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9772 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9773 | struct rpc_task_setup task_setup = { |
| 9774 | .rpc_client = server->client, |
| 9775 | .rpc_message = &msg, |
| 9776 | .callback_ops = &nfs41_free_stateid_ops, |
| 9777 | .flags = RPC_TASK_ASYNC, |
| 9778 | }; |
| 9779 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9780 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9781 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9782 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9783 | &task_setup.rpc_client, &msg); |
| 9784 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9785 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9786 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9787 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9788 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9789 | data->server = server; |
| 9790 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9791 | |
| 9792 | task_setup.callback_data = data; |
| 9793 | |
| 9794 | msg.rpc_argp = &data->args; |
| 9795 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9796 | 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] | 9797 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9798 | if (IS_ERR(task)) |
| 9799 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9800 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9801 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9802 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9803 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9804 | static void |
| 9805 | 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] | 9806 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9807 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9808 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9809 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9810 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9811 | } |
| 9812 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9813 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9814 | const nfs4_stateid *s2) |
| 9815 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9816 | if (s1->type != s2->type) |
| 9817 | return false; |
| 9818 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9819 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9820 | return false; |
| 9821 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9822 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9823 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9824 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9825 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9826 | } |
| 9827 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9828 | #endif /* CONFIG_NFS_V4_1 */ |
| 9829 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9830 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9831 | const nfs4_stateid *s2) |
| 9832 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9833 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9834 | } |
| 9835 | |
| 9836 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9837 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9838 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9839 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9840 | .recover_open = nfs4_open_reclaim, |
| 9841 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9842 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9843 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9844 | }; |
| 9845 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9846 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9847 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9848 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9849 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9850 | .recover_open = nfs4_open_reclaim, |
| 9851 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9852 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9853 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9854 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9855 | }; |
| 9856 | #endif /* CONFIG_NFS_V4_1 */ |
| 9857 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9858 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9859 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9860 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9861 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9862 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9863 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9864 | }; |
| 9865 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9866 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9867 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9868 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9869 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9870 | .recover_open = nfs41_open_expired, |
| 9871 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9872 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9873 | }; |
| 9874 | #endif /* CONFIG_NFS_V4_1 */ |
| 9875 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9876 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9877 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9878 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9879 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9880 | }; |
| 9881 | |
| 9882 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9883 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9884 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9885 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9886 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9887 | }; |
| 9888 | #endif |
| 9889 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9890 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9891 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9892 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9893 | }; |
| 9894 | |
| 9895 | #if defined(CONFIG_NFS_V4_1) |
| 9896 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9897 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9898 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9899 | }; |
| 9900 | #endif /* CONFIG_NFS_V4_1 */ |
| 9901 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9902 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9903 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9904 | .init_caps = NFS_CAP_READDIRPLUS |
| 9905 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9906 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9907 | .init_client = nfs40_init_client, |
| 9908 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9909 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9910 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9911 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9912 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9913 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9914 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9915 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9916 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9917 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9918 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9919 | }; |
| 9920 | |
| 9921 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9922 | static struct nfs_seqid * |
| 9923 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9924 | { |
| 9925 | return NULL; |
| 9926 | } |
| 9927 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9928 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9929 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9930 | .init_caps = NFS_CAP_READDIRPLUS |
| 9931 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9932 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9933 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9934 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9935 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9936 | .init_client = nfs41_init_client, |
| 9937 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9938 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9939 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9940 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9941 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9942 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9943 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9944 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9945 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9946 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9947 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9948 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9949 | }; |
| 9950 | #endif |
| 9951 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9952 | #if defined(CONFIG_NFS_V4_2) |
| 9953 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9954 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9955 | .init_caps = NFS_CAP_READDIRPLUS |
| 9956 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9957 | | NFS_CAP_POSIX_LOCK |
| 9958 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9959 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9960 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9961 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9962 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 9963 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 9964 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9965 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9966 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9967 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 9968 | | NFS_CAP_CLONE |
| 9969 | | NFS_CAP_LAYOUTERROR, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9970 | .init_client = nfs41_init_client, |
| 9971 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9972 | .match_stateid = nfs41_match_stateid, |
| 9973 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9974 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9975 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9976 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9977 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9978 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9979 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9980 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9981 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9982 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9983 | }; |
| 9984 | #endif |
| 9985 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9986 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9987 | [0] = &nfs_v4_0_minor_ops, |
| 9988 | #if defined(CONFIG_NFS_V4_1) |
| 9989 | [1] = &nfs_v4_1_minor_ops, |
| 9990 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9991 | #if defined(CONFIG_NFS_V4_2) |
| 9992 | [2] = &nfs_v4_2_minor_ops, |
| 9993 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9994 | }; |
| 9995 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9996 | 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] | 9997 | { |
| 9998 | ssize_t error, error2; |
| 9999 | |
| 10000 | error = generic_listxattr(dentry, list, size); |
| 10001 | if (error < 0) |
| 10002 | return error; |
| 10003 | if (list) { |
| 10004 | list += error; |
| 10005 | size -= error; |
| 10006 | } |
| 10007 | |
| 10008 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10009 | if (error2 < 0) |
| 10010 | return error2; |
| 10011 | return error + error2; |
| 10012 | } |
| 10013 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10014 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10015 | .create = nfs_create, |
| 10016 | .lookup = nfs_lookup, |
| 10017 | .atomic_open = nfs_atomic_open, |
| 10018 | .link = nfs_link, |
| 10019 | .unlink = nfs_unlink, |
| 10020 | .symlink = nfs_symlink, |
| 10021 | .mkdir = nfs_mkdir, |
| 10022 | .rmdir = nfs_rmdir, |
| 10023 | .mknod = nfs_mknod, |
| 10024 | .rename = nfs_rename, |
| 10025 | .permission = nfs_permission, |
| 10026 | .getattr = nfs_getattr, |
| 10027 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10028 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10029 | }; |
| 10030 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10031 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10032 | .permission = nfs_permission, |
| 10033 | .getattr = nfs_getattr, |
| 10034 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10035 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10036 | }; |
| 10037 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10038 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10039 | .version = 4, /* protocol version */ |
| 10040 | .dentry_ops = &nfs4_dentry_operations, |
| 10041 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10042 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10043 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10044 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10045 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10046 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10047 | .getattr = nfs4_proc_getattr, |
| 10048 | .setattr = nfs4_proc_setattr, |
| 10049 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10050 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10051 | .access = nfs4_proc_access, |
| 10052 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10053 | .create = nfs4_proc_create, |
| 10054 | .remove = nfs4_proc_remove, |
| 10055 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10056 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10057 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10058 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10059 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10060 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10061 | .link = nfs4_proc_link, |
| 10062 | .symlink = nfs4_proc_symlink, |
| 10063 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10064 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10065 | .readdir = nfs4_proc_readdir, |
| 10066 | .mknod = nfs4_proc_mknod, |
| 10067 | .statfs = nfs4_proc_statfs, |
| 10068 | .fsinfo = nfs4_proc_fsinfo, |
| 10069 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10070 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10071 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10072 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10073 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10074 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10075 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10076 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10077 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10078 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10079 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10080 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10081 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10082 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10083 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10084 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10085 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10086 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10087 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10088 | .create_server = nfs4_create_server, |
| 10089 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10090 | }; |
| 10091 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10092 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10093 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10094 | .list = nfs4_xattr_list_nfs4_acl, |
| 10095 | .get = nfs4_xattr_get_nfs4_acl, |
| 10096 | .set = nfs4_xattr_set_nfs4_acl, |
| 10097 | }; |
| 10098 | |
| 10099 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10100 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10101 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10102 | &nfs4_xattr_nfs4_label_handler, |
| 10103 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10104 | NULL |
| 10105 | }; |
| 10106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10107 | /* |
| 10108 | * Local variables: |
| 10109 | * c-basic-offset: 8 |
| 10110 | * End: |
| 10111 | */ |