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 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3202 | if (status == -EAGAIN) { |
| 3203 | /* We must have found a delegation */ |
| 3204 | exception.retry = 1; |
| 3205 | continue; |
| 3206 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3207 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3208 | continue; |
| 3209 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | status, &exception)); |
| 3211 | } while (exception.retry); |
| 3212 | return res; |
| 3213 | } |
| 3214 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3215 | static int _nfs4_do_setattr(struct inode *inode, |
| 3216 | struct nfs_setattrargs *arg, |
| 3217 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3218 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3219 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3220 | { |
| 3221 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3222 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3223 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3224 | .rpc_argp = arg, |
| 3225 | .rpc_resp = res, |
| 3226 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3227 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3228 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3229 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3230 | bool truncate; |
| 3231 | int status; |
| 3232 | |
| 3233 | nfs_fattr_init(res->fattr); |
| 3234 | |
| 3235 | /* Servers should only apply open mode checks for file size changes */ |
| 3236 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3237 | if (!truncate) |
| 3238 | goto zero_stateid; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3239 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3240 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3241 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3242 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3243 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3244 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3245 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3246 | l_ctx = nfs_get_lock_context(ctx); |
| 3247 | if (IS_ERR(l_ctx)) |
| 3248 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3249 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3250 | &arg->stateid, &delegation_cred); |
| 3251 | nfs_put_lock_context(l_ctx); |
| 3252 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3253 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3254 | else if (status == -EAGAIN) |
| 3255 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3256 | } else { |
| 3257 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3258 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3259 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3260 | if (delegation_cred) |
| 3261 | msg.rpc_cred = delegation_cred; |
| 3262 | |
| 3263 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3264 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3265 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3266 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3267 | renew_lease(server, timestamp); |
| 3268 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3269 | return status; |
| 3270 | } |
| 3271 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3272 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3273 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3274 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3275 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3277 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3278 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3279 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3280 | struct nfs_setattrargs arg = { |
| 3281 | .fh = NFS_FH(inode), |
| 3282 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3284 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3285 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3286 | }; |
| 3287 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3289 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3291 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3292 | struct nfs4_exception exception = { |
| 3293 | .state = state, |
| 3294 | .inode = inode, |
| 3295 | .stateid = &arg.stateid, |
| 3296 | }; |
| 3297 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3300 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3301 | nfs4_bitmask(server, olabel), |
| 3302 | inode); |
| 3303 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3304 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3305 | switch (err) { |
| 3306 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3307 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3308 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3309 | "applying open mode checks to " |
| 3310 | "a SETATTR that is not " |
| 3311 | "changing file size.\n", |
| 3312 | server->nfs_client->cl_hostname); |
| 3313 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3314 | if (state && !(state->state & FMODE_WRITE)) { |
| 3315 | err = -EBADF; |
| 3316 | if (sattr->ia_valid & ATTR_OPEN) |
| 3317 | err = -EACCES; |
| 3318 | goto out; |
| 3319 | } |
| 3320 | } |
| 3321 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3323 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | return err; |
| 3325 | } |
| 3326 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3327 | static bool |
| 3328 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3329 | { |
| 3330 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3331 | return false; |
| 3332 | |
| 3333 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3334 | } |
| 3335 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3336 | /* |
| 3337 | * Update the seqid of an open stateid |
| 3338 | */ |
| 3339 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3340 | struct nfs4_state *state) |
| 3341 | { |
| 3342 | __be32 seqid_open; |
| 3343 | u32 dst_seqid; |
| 3344 | int seq; |
| 3345 | |
| 3346 | for (;;) { |
| 3347 | if (!nfs4_valid_open_stateid(state)) |
| 3348 | break; |
| 3349 | seq = read_seqbegin(&state->seqlock); |
| 3350 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3351 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3352 | if (read_seqretry(&state->seqlock, seq)) |
| 3353 | continue; |
| 3354 | break; |
| 3355 | } |
| 3356 | seqid_open = state->open_stateid.seqid; |
| 3357 | if (read_seqretry(&state->seqlock, seq)) |
| 3358 | continue; |
| 3359 | |
| 3360 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3361 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3362 | dst->seqid = seqid_open; |
| 3363 | break; |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | /* |
| 3368 | * Update the seqid of an open stateid after receiving |
| 3369 | * NFS4ERR_OLD_STATEID |
| 3370 | */ |
| 3371 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3372 | struct nfs4_state *state) |
| 3373 | { |
| 3374 | __be32 seqid_open; |
| 3375 | u32 dst_seqid; |
| 3376 | bool ret; |
| 3377 | int seq; |
| 3378 | |
| 3379 | for (;;) { |
| 3380 | ret = false; |
| 3381 | if (!nfs4_valid_open_stateid(state)) |
| 3382 | break; |
| 3383 | seq = read_seqbegin(&state->seqlock); |
| 3384 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3385 | if (read_seqretry(&state->seqlock, seq)) |
| 3386 | continue; |
| 3387 | break; |
| 3388 | } |
| 3389 | seqid_open = state->open_stateid.seqid; |
| 3390 | if (read_seqretry(&state->seqlock, seq)) |
| 3391 | continue; |
| 3392 | |
| 3393 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3394 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) >= 0) |
| 3395 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
| 3396 | else |
| 3397 | dst->seqid = seqid_open; |
| 3398 | ret = true; |
| 3399 | break; |
| 3400 | } |
| 3401 | |
| 3402 | return ret; |
| 3403 | } |
| 3404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | struct nfs4_closedata { |
| 3406 | struct inode *inode; |
| 3407 | struct nfs4_state *state; |
| 3408 | struct nfs_closeargs arg; |
| 3409 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3410 | struct { |
| 3411 | struct nfs4_layoutreturn_args arg; |
| 3412 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3413 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3414 | u32 roc_barrier; |
| 3415 | bool roc; |
| 3416 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3417 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3418 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | }; |
| 3420 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3421 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3422 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3423 | struct nfs4_closedata *calldata = data; |
| 3424 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3425 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3426 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3427 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3428 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3429 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3430 | nfs4_put_open_state(calldata->state); |
| 3431 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3432 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3433 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3434 | kfree(calldata); |
| 3435 | } |
| 3436 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3437 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3439 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3442 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3443 | struct nfs4_exception exception = { |
| 3444 | .state = state, |
| 3445 | .inode = calldata->inode, |
| 3446 | .stateid = &calldata->arg.stateid, |
| 3447 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3449 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3450 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3451 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3452 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3453 | |
| 3454 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3455 | if (pnfs_roc_done(task, calldata->inode, |
| 3456 | &calldata->arg.lr_args, |
| 3457 | &calldata->res.lr_res, |
| 3458 | &calldata->res.lr_ret) == -EAGAIN) |
| 3459 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3460 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3461 | /* 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] | 3462 | * the state_owner. we keep this around to process errors |
| 3463 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | switch (task->tk_status) { |
| 3465 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3466 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3467 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3468 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3469 | case -NFS4ERR_ACCESS: |
| 3470 | if (calldata->arg.bitmask != NULL) { |
| 3471 | calldata->arg.bitmask = NULL; |
| 3472 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3473 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3474 | |
| 3475 | } |
| 3476 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3477 | case -NFS4ERR_OLD_STATEID: |
| 3478 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3479 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3480 | state)) |
| 3481 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3482 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3483 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3485 | case -NFS4ERR_EXPIRED: |
| 3486 | nfs4_free_revoked_stateid(server, |
| 3487 | &calldata->arg.stateid, |
| 3488 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3489 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3490 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3491 | if (calldata->arg.fmode == 0) |
| 3492 | break; |
| 3493 | /* Fallthrough */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3495 | task->tk_status = nfs4_async_handle_exception(task, |
| 3496 | server, task->tk_status, &exception); |
| 3497 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3498 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3500 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3501 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3502 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3503 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3504 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3505 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3506 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3507 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3508 | out_restart: |
| 3509 | task->tk_status = 0; |
| 3510 | rpc_restart_call_prepare(task); |
| 3511 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3514 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3516 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3517 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3518 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3519 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3520 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3521 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3522 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3523 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3524 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3525 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3526 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3527 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3528 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3529 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3530 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3531 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3532 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3533 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3534 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3535 | if (state->n_rdonly == 0) |
| 3536 | call_close |= is_rdonly; |
| 3537 | else if (is_rdonly) |
| 3538 | calldata->arg.fmode |= FMODE_READ; |
| 3539 | if (state->n_wronly == 0) |
| 3540 | call_close |= is_wronly; |
| 3541 | else if (is_wronly) |
| 3542 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3543 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3544 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3545 | } else if (is_rdwr) |
| 3546 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3547 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3548 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3549 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3550 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3551 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3552 | |
| 3553 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3554 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3555 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3556 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3557 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3558 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3559 | nfs_release_seqid(calldata->arg.seqid); |
| 3560 | goto out_wait; |
| 3561 | } |
| 3562 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3563 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3564 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3565 | calldata->arg.lr_args = NULL; |
| 3566 | calldata->res.lr_res = NULL; |
| 3567 | } |
| 3568 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3569 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3570 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3571 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3572 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3573 | /* Close-to-open cache consistency revalidation */ |
| 3574 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3575 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3576 | else |
| 3577 | calldata->arg.bitmask = NULL; |
| 3578 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3579 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3580 | calldata->arg.share_access = |
| 3581 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3582 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3583 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3584 | if (calldata->res.fattr == NULL) |
| 3585 | calldata->arg.bitmask = NULL; |
| 3586 | else if (calldata->arg.bitmask == NULL) |
| 3587 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3588 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3589 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3590 | &calldata->arg.seq_args, |
| 3591 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3592 | task) != 0) |
| 3593 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3594 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3595 | return; |
| 3596 | out_no_action: |
| 3597 | task->tk_action = NULL; |
| 3598 | out_wait: |
| 3599 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3602 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3603 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3604 | .rpc_call_done = nfs4_close_done, |
| 3605 | .rpc_release = nfs4_free_closedata, |
| 3606 | }; |
| 3607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | /* |
| 3609 | * It is possible for data to be read/written from a mem-mapped file |
| 3610 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3611 | * This means that we can't safely call nfsv4 close on a file until |
| 3612 | * the inode is cleared. This in turn means that we are not good |
| 3613 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3614 | * share state even when we are done with one of the three share |
| 3615 | * stateid's in the inode. |
| 3616 | * |
| 3617 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3618 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3619 | 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] | 3620 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3621 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3622 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3624 | struct nfs4_state_owner *sp = state->owner; |
| 3625 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3626 | struct rpc_message msg = { |
| 3627 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3628 | .rpc_cred = state->owner->so_cred, |
| 3629 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3630 | struct rpc_task_setup task_setup_data = { |
| 3631 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3632 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3633 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3634 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3635 | .flags = RPC_TASK_ASYNC, |
| 3636 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3637 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3639 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3640 | &task_setup_data.rpc_client, &msg); |
| 3641 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3642 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3644 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3645 | 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] | 3646 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3648 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3649 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3650 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3652 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3653 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3654 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3655 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3656 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3657 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3658 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3659 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3660 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3661 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3662 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3663 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3664 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3665 | if (calldata->lr.roc) { |
| 3666 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3667 | calldata->res.lr_res = &calldata->lr.res; |
| 3668 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3669 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3670 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3671 | msg.rpc_argp = &calldata->arg; |
| 3672 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3673 | task_setup_data.callback_data = calldata; |
| 3674 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3675 | if (IS_ERR(task)) |
| 3676 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3677 | status = 0; |
| 3678 | if (wait) |
| 3679 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3680 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3681 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3682 | out_free_calldata: |
| 3683 | kfree(calldata); |
| 3684 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3685 | nfs4_put_open_state(state); |
| 3686 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3687 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3690 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3691 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3692 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3695 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3696 | |
| 3697 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3699 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3700 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3701 | |
| 3702 | nfs4_label_release_security(label); |
| 3703 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3704 | if (IS_ERR(state)) |
| 3705 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3706 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3709 | 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] | 3710 | { |
| 3711 | if (ctx->state == NULL) |
| 3712 | return; |
| 3713 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3714 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3715 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3716 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3717 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3719 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3720 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3721 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3724 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3725 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3726 | struct nfs4_server_caps_arg args = { |
| 3727 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3728 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3729 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | struct nfs4_server_caps_res res = {}; |
| 3731 | struct rpc_message msg = { |
| 3732 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3733 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | .rpc_resp = &res, |
| 3735 | }; |
| 3736 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3737 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3739 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3740 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3741 | FATTR4_WORD0_LINK_SUPPORT | |
| 3742 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3743 | FATTR4_WORD0_ACLSUPPORT; |
| 3744 | if (minorversion) |
| 3745 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3746 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3747 | 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] | 3748 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3749 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3750 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3751 | case 0: |
| 3752 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3753 | res.attr_bitmask[2] = 0; |
| 3754 | break; |
| 3755 | case 1: |
| 3756 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3757 | break; |
| 3758 | case 2: |
| 3759 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3762 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3763 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3764 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3765 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3766 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3767 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3768 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3769 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | server->caps |= NFS_CAP_ACLS; |
| 3771 | if (res.has_links != 0) |
| 3772 | server->caps |= NFS_CAP_HARDLINKS; |
| 3773 | if (res.has_symlinks != 0) |
| 3774 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3775 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3776 | server->caps |= NFS_CAP_FILEID; |
| 3777 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3778 | server->caps |= NFS_CAP_MODE; |
| 3779 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3780 | server->caps |= NFS_CAP_NLINK; |
| 3781 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3782 | server->caps |= NFS_CAP_OWNER; |
| 3783 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3784 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3785 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3786 | server->caps |= NFS_CAP_ATIME; |
| 3787 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3788 | server->caps |= NFS_CAP_CTIME; |
| 3789 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3790 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3791 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3792 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3793 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3794 | #endif |
| 3795 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3796 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3797 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3798 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3799 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3800 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3801 | 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] | 3802 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3803 | |
| 3804 | /* Avoid a regression due to buggy server */ |
| 3805 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3806 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3807 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3808 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3811 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | return status; |
| 3815 | } |
| 3816 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3817 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3819 | struct nfs4_exception exception = { |
| 3820 | .interruptible = true, |
| 3821 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | int err; |
| 3823 | do { |
| 3824 | err = nfs4_handle_exception(server, |
| 3825 | _nfs4_server_capabilities(server, fhandle), |
| 3826 | &exception); |
| 3827 | } while (exception.retry); |
| 3828 | return err; |
| 3829 | } |
| 3830 | |
| 3831 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3832 | struct nfs_fsinfo *info) |
| 3833 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3834 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3836 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | }; |
| 3838 | struct nfs4_lookup_res res = { |
| 3839 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3840 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | .fh = fhandle, |
| 3842 | }; |
| 3843 | struct rpc_message msg = { |
| 3844 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3845 | .rpc_argp = &args, |
| 3846 | .rpc_resp = &res, |
| 3847 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3848 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3849 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3850 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3851 | /* |
| 3852 | * Process the label in the upcoming getfattr |
| 3853 | */ |
| 3854 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3855 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3856 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3857 | 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] | 3858 | } |
| 3859 | |
| 3860 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3861 | struct nfs_fsinfo *info) |
| 3862 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3863 | struct nfs4_exception exception = { |
| 3864 | .interruptible = true, |
| 3865 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | int err; |
| 3867 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3868 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3869 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3870 | switch (err) { |
| 3871 | case 0: |
| 3872 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3873 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3874 | default: |
| 3875 | err = nfs4_handle_exception(server, err, &exception); |
| 3876 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3878 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | return err; |
| 3880 | } |
| 3881 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3882 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3883 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3884 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3885 | struct rpc_auth_create_args auth_args = { |
| 3886 | .pseudoflavor = flavor, |
| 3887 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3888 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3889 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3890 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3891 | if (IS_ERR(auth)) |
| 3892 | return -EACCES; |
| 3893 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3896 | /* |
| 3897 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3898 | * |
| 3899 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3900 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3901 | * |
| 3902 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3903 | * negative errno value. |
| 3904 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3905 | 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] | 3906 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3908 | /* Per 3530bis 15.33.5 */ |
| 3909 | static const rpc_authflavor_t flav_array[] = { |
| 3910 | RPC_AUTH_GSS_KRB5P, |
| 3911 | RPC_AUTH_GSS_KRB5I, |
| 3912 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3913 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3914 | RPC_AUTH_NULL, |
| 3915 | }; |
| 3916 | int status = -EPERM; |
| 3917 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3919 | if (server->auth_info.flavor_len > 0) { |
| 3920 | /* try each flavor specified by user */ |
| 3921 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3922 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3923 | server->auth_info.flavors[i]); |
| 3924 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3925 | continue; |
| 3926 | break; |
| 3927 | } |
| 3928 | } else { |
| 3929 | /* no flavors specified by user, try default list */ |
| 3930 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3931 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3932 | flav_array[i]); |
| 3933 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3934 | continue; |
| 3935 | break; |
| 3936 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3937 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3938 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3939 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 3940 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3941 | * to access the mount. It could also mean that we tried to mount |
| 3942 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3943 | * existing mount programs don't handle -EACCES very well so it should |
| 3944 | * be mapped to -EPERM instead. |
| 3945 | */ |
| 3946 | if (status == -EACCES) |
| 3947 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3948 | return status; |
| 3949 | } |
| 3950 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3951 | /** |
| 3952 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3953 | * @server: initialized nfs_server handle |
| 3954 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3955 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3956 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3957 | * |
| 3958 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3959 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3960 | 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] | 3961 | struct nfs_fsinfo *info, |
| 3962 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3963 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3964 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3965 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3966 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3967 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3968 | |
| 3969 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3970 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3971 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | if (status == 0) |
| 3974 | status = nfs4_server_capabilities(server, fhandle); |
| 3975 | if (status == 0) |
| 3976 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3977 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3978 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3981 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3982 | struct nfs_fsinfo *info) |
| 3983 | { |
| 3984 | int error; |
| 3985 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3986 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3987 | |
| 3988 | error = nfs4_server_capabilities(server, mntfh); |
| 3989 | if (error < 0) { |
| 3990 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3991 | return error; |
| 3992 | } |
| 3993 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3994 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3995 | if (IS_ERR(label)) |
| 3996 | return PTR_ERR(label); |
| 3997 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3998 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3999 | if (error < 0) { |
| 4000 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4001 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4005 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4006 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4007 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4008 | err_free_label: |
| 4009 | nfs4_label_free(label); |
| 4010 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4011 | return error; |
| 4012 | } |
| 4013 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4014 | /* |
| 4015 | * Get locations and (maybe) other attributes of a referral. |
| 4016 | * Note that we'll actually follow the referral later when |
| 4017 | * we detect fsid mismatch in inode revalidation |
| 4018 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4019 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4020 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4021 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4022 | { |
| 4023 | int status = -ENOMEM; |
| 4024 | struct page *page = NULL; |
| 4025 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4026 | |
| 4027 | page = alloc_page(GFP_KERNEL); |
| 4028 | if (page == NULL) |
| 4029 | goto out; |
| 4030 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4031 | if (locations == NULL) |
| 4032 | goto out; |
| 4033 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4034 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4035 | if (status != 0) |
| 4036 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4037 | |
| 4038 | /* |
| 4039 | * If the fsid didn't change, this is a migration event, not a |
| 4040 | * referral. Cause us to drop into the exception handler, which |
| 4041 | * will kick off migration recovery. |
| 4042 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4043 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4044 | dprintk("%s: server did not return a different fsid for" |
| 4045 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4046 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4047 | goto out; |
| 4048 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4049 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4050 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4051 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4052 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4053 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4054 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4055 | out: |
| 4056 | if (page) |
| 4057 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4058 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4059 | return status; |
| 4060 | } |
| 4061 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4062 | 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] | 4063 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4064 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4066 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | struct nfs4_getattr_arg args = { |
| 4068 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4069 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | }; |
| 4071 | struct nfs4_getattr_res res = { |
| 4072 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4073 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | .server = server, |
| 4075 | }; |
| 4076 | struct rpc_message msg = { |
| 4077 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4078 | .rpc_argp = &args, |
| 4079 | .rpc_resp = &res, |
| 4080 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4081 | unsigned short task_flags = 0; |
| 4082 | |
| 4083 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4084 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4085 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4086 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4087 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4088 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4089 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4090 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4091 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4092 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4095 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4096 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4097 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4099 | struct nfs4_exception exception = { |
| 4100 | .interruptible = true, |
| 4101 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | int err; |
| 4103 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4104 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4105 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4106 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | &exception); |
| 4108 | } while (exception.retry); |
| 4109 | return err; |
| 4110 | } |
| 4111 | |
| 4112 | /* |
| 4113 | * The file is not closed if it is opened due to the a request to change |
| 4114 | * the size of the file. The open call will not be needed once the |
| 4115 | * VFS layer lookup-intents are implemented. |
| 4116 | * |
| 4117 | * Close is called when the inode is destroyed. |
| 4118 | * If we haven't opened the file for O_WRONLY, we |
| 4119 | * need to in the size_change case to obtain a stateid. |
| 4120 | * |
| 4121 | * Got race? |
| 4122 | * Because OPEN is always done by name in nfsv4, it is |
| 4123 | * possible that we opened a different file by the same |
| 4124 | * name. We can recognize this race condition, but we |
| 4125 | * can't do anything about it besides returning an error. |
| 4126 | * |
| 4127 | * This will be fixed with VFS changes (lookup-intent). |
| 4128 | */ |
| 4129 | static int |
| 4130 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4131 | struct iattr *sattr) |
| 4132 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4133 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4134 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4135 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4136 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | int status; |
| 4138 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4139 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4140 | sattr->ia_valid & ATTR_SIZE && |
| 4141 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4142 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4143 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4144 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4146 | /* Deal with open(O_TRUNC) */ |
| 4147 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4148 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4149 | |
| 4150 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4151 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4152 | return 0; |
| 4153 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4154 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4155 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4156 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4157 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4158 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4159 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4160 | } |
| 4161 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4162 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4163 | if (IS_ERR(label)) |
| 4164 | return PTR_ERR(label); |
| 4165 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4166 | /* Return any delegations if we're going to change ACLs */ |
| 4167 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4168 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4169 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4170 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4171 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4172 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4173 | nfs_setsecurity(inode, fattr, label); |
| 4174 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4175 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | return status; |
| 4177 | } |
| 4178 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4179 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4180 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4181 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4182 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4183 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4184 | int status; |
| 4185 | struct nfs4_lookup_arg args = { |
| 4186 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4187 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4188 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4189 | }; |
| 4190 | struct nfs4_lookup_res res = { |
| 4191 | .server = server, |
| 4192 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4193 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4194 | .fh = fhandle, |
| 4195 | }; |
| 4196 | struct rpc_message msg = { |
| 4197 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4198 | .rpc_argp = &args, |
| 4199 | .rpc_resp = &res, |
| 4200 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4201 | unsigned short task_flags = 0; |
| 4202 | |
| 4203 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4204 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4205 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4206 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4207 | args.bitmask = nfs4_bitmask(server, label); |
| 4208 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4209 | nfs_fattr_init(fattr); |
| 4210 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4211 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4212 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4213 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4214 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | dprintk("NFS reply lookup: %d\n", status); |
| 4216 | return status; |
| 4217 | } |
| 4218 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4219 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4220 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4221 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4222 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4223 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4224 | fattr->nlink = 2; |
| 4225 | } |
| 4226 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4227 | 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^] | 4228 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4229 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4230 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4231 | struct nfs4_exception exception = { |
| 4232 | .interruptible = true, |
| 4233 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4234 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4235 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4236 | int err; |
| 4237 | do { |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4238 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4239 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4240 | switch (err) { |
| 4241 | case -NFS4ERR_BADNAME: |
| 4242 | err = -ENOENT; |
| 4243 | goto out; |
| 4244 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4245 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4246 | if (err == -NFS4ERR_MOVED) |
| 4247 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4248 | goto out; |
| 4249 | case -NFS4ERR_WRONGSEC: |
| 4250 | err = -EPERM; |
| 4251 | if (client != *clnt) |
| 4252 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4253 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4254 | if (IS_ERR(client)) |
| 4255 | return PTR_ERR(client); |
| 4256 | |
| 4257 | exception.retry = 1; |
| 4258 | break; |
| 4259 | default: |
| 4260 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4261 | } |
| 4262 | } while (exception.retry); |
| 4263 | |
| 4264 | out: |
| 4265 | if (err == 0) |
| 4266 | *clnt = client; |
| 4267 | else if (client != *clnt) |
| 4268 | rpc_shutdown_client(client); |
| 4269 | |
| 4270 | return err; |
| 4271 | } |
| 4272 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4273 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4274 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4275 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4277 | int status; |
| 4278 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4279 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4280 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4281 | if (client != NFS_CLIENT(dir)) { |
| 4282 | rpc_shutdown_client(client); |
| 4283 | nfs_fixup_secinfo_attributes(fattr); |
| 4284 | } |
| 4285 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | } |
| 4287 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4288 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4289 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4290 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4291 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4292 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4293 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4294 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame^] | 4295 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4296 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4297 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4298 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4299 | } |
| 4300 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4301 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4302 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4303 | struct nfs4_label *label) |
| 4304 | { |
| 4305 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4306 | struct nfs_server *server = NFS_SERVER(inode); |
| 4307 | int status; |
| 4308 | struct nfs4_lookupp_arg args = { |
| 4309 | .bitmask = server->attr_bitmask, |
| 4310 | .fh = NFS_FH(inode), |
| 4311 | }; |
| 4312 | struct nfs4_lookupp_res res = { |
| 4313 | .server = server, |
| 4314 | .fattr = fattr, |
| 4315 | .label = label, |
| 4316 | .fh = fhandle, |
| 4317 | }; |
| 4318 | struct rpc_message msg = { |
| 4319 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4320 | .rpc_argp = &args, |
| 4321 | .rpc_resp = &res, |
| 4322 | }; |
| 4323 | |
| 4324 | args.bitmask = nfs4_bitmask(server, label); |
| 4325 | |
| 4326 | nfs_fattr_init(fattr); |
| 4327 | |
| 4328 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4329 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4330 | &res.seq_res, 0); |
| 4331 | dprintk("NFS reply lookupp: %d\n", status); |
| 4332 | return status; |
| 4333 | } |
| 4334 | |
| 4335 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4336 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4337 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4338 | struct nfs4_exception exception = { |
| 4339 | .interruptible = true, |
| 4340 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4341 | int err; |
| 4342 | do { |
| 4343 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4344 | trace_nfs4_lookupp(inode, err); |
| 4345 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4346 | &exception); |
| 4347 | } while (exception.retry); |
| 4348 | return err; |
| 4349 | } |
| 4350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4352 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4353 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | struct nfs4_accessargs args = { |
| 4355 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4356 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4358 | struct nfs4_accessres res = { |
| 4359 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4360 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | struct rpc_message msg = { |
| 4362 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4363 | .rpc_argp = &args, |
| 4364 | .rpc_resp = &res, |
| 4365 | .rpc_cred = entry->cred, |
| 4366 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4367 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4369 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4370 | res.fattr = nfs_alloc_fattr(); |
| 4371 | if (res.fattr == NULL) |
| 4372 | return -ENOMEM; |
| 4373 | args.bitmask = server->cache_consistency_bitmask; |
| 4374 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4375 | 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] | 4376 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4377 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4378 | if (res.fattr) |
| 4379 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4381 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | return status; |
| 4383 | } |
| 4384 | |
| 4385 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4386 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4387 | struct nfs4_exception exception = { |
| 4388 | .interruptible = true, |
| 4389 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | int err; |
| 4391 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4392 | err = _nfs4_proc_access(inode, entry); |
| 4393 | trace_nfs4_access(inode, err); |
| 4394 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | &exception); |
| 4396 | } while (exception.retry); |
| 4397 | return err; |
| 4398 | } |
| 4399 | |
| 4400 | /* |
| 4401 | * TODO: For the time being, we don't try to get any attributes |
| 4402 | * along with any of the zero-copy operations READ, READDIR, |
| 4403 | * READLINK, WRITE. |
| 4404 | * |
| 4405 | * In the case of the first three, we want to put the GETATTR |
| 4406 | * after the read-type operation -- this is because it is hard |
| 4407 | * to predict the length of a GETATTR response in v4, and thus |
| 4408 | * align the READ data correctly. This means that the GETATTR |
| 4409 | * may end up partially falling into the page cache, and we should |
| 4410 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4411 | * To do this efficiently, we need to know the total length |
| 4412 | * of data received, which doesn't seem to be available outside |
| 4413 | * of the RPC layer. |
| 4414 | * |
| 4415 | * In the case of WRITE, we also want to put the GETATTR after |
| 4416 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4417 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | * |
| 4419 | * Both of these changes to the XDR layer would in fact be quite |
| 4420 | * minor, but I decided to leave them for a subsequent patch. |
| 4421 | */ |
| 4422 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4423 | unsigned int pgbase, unsigned int pglen) |
| 4424 | { |
| 4425 | struct nfs4_readlink args = { |
| 4426 | .fh = NFS_FH(inode), |
| 4427 | .pgbase = pgbase, |
| 4428 | .pglen = pglen, |
| 4429 | .pages = &page, |
| 4430 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4431 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | struct rpc_message msg = { |
| 4433 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4434 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4435 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | }; |
| 4437 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4438 | 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] | 4439 | } |
| 4440 | |
| 4441 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4442 | unsigned int pgbase, unsigned int pglen) |
| 4443 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4444 | struct nfs4_exception exception = { |
| 4445 | .interruptible = true, |
| 4446 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | int err; |
| 4448 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4449 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4450 | trace_nfs4_readlink(inode, err); |
| 4451 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | &exception); |
| 4453 | } while (exception.retry); |
| 4454 | return err; |
| 4455 | } |
| 4456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4458 | * 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] | 4459 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | static int |
| 4461 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4462 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4464 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4465 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4466 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | int status = 0; |
| 4469 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4470 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4471 | if (IS_ERR(ctx)) |
| 4472 | return PTR_ERR(ctx); |
| 4473 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4474 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4475 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4476 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4477 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4478 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | if (IS_ERR(state)) { |
| 4480 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4481 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4484 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4485 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | return status; |
| 4487 | } |
| 4488 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4489 | static int |
| 4490 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4492 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4493 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4495 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4497 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4498 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4499 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4502 | .rpc_argp = &args, |
| 4503 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4505 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4506 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4507 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4508 | 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] | 4509 | if (status == 0) { |
| 4510 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4511 | update_changeattr_locked(dir, &res.cinfo, timestamp, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4512 | /* Removing a directory decrements nlink in the parent */ |
| 4513 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4514 | nfs4_dec_nlink_locked(dir); |
| 4515 | spin_unlock(&dir->i_lock); |
| 4516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | return status; |
| 4518 | } |
| 4519 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4520 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4521 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4522 | struct nfs4_exception exception = { |
| 4523 | .interruptible = true, |
| 4524 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4525 | struct inode *inode = d_inode(dentry); |
| 4526 | int err; |
| 4527 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4528 | if (inode) { |
| 4529 | if (inode->i_nlink == 1) |
| 4530 | nfs4_inode_return_delegation(inode); |
| 4531 | else |
| 4532 | nfs4_inode_make_writeable(inode); |
| 4533 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4534 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4535 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4536 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4537 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4538 | &exception); |
| 4539 | } while (exception.retry); |
| 4540 | return err; |
| 4541 | } |
| 4542 | |
| 4543 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4545 | struct nfs4_exception exception = { |
| 4546 | .interruptible = true, |
| 4547 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4550 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4551 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4552 | trace_nfs4_remove(dir, name, err); |
| 4553 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | &exception); |
| 4555 | } while (exception.retry); |
| 4556 | return err; |
| 4557 | } |
| 4558 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4559 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4560 | struct dentry *dentry, |
| 4561 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4563 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4564 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4566 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4568 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4569 | |
| 4570 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4571 | |
| 4572 | if (inode) |
| 4573 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | } |
| 4575 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4576 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4577 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4578 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4579 | &data->args.seq_args, |
| 4580 | &data->res.seq_res, |
| 4581 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | } |
| 4583 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4584 | 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] | 4585 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4586 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4587 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4588 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4589 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4590 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4591 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4592 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4593 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4594 | if (task->tk_status == 0) |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4595 | update_changeattr(dir, &res->cinfo, |
| 4596 | res->dir_attr->time_start, 0); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4597 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4600 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4601 | struct dentry *old_dentry, |
| 4602 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4603 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4604 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4605 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4606 | struct inode *old_inode = d_inode(old_dentry); |
| 4607 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4608 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4609 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4610 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4611 | if (new_inode) |
| 4612 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4613 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4614 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4615 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4616 | } |
| 4617 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4618 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4619 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4620 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4621 | &data->args.seq_args, |
| 4622 | &data->res.seq_res, |
| 4623 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4627 | struct inode *new_dir) |
| 4628 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4629 | struct nfs_renamedata *data = task->tk_calldata; |
| 4630 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4631 | |
| 4632 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4633 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4634 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4635 | return 0; |
| 4636 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4637 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4638 | if (new_dir != old_dir) { |
| 4639 | /* Note: If we moved a directory, nlink will change */ |
| 4640 | update_changeattr(old_dir, &res->old_cinfo, |
| 4641 | res->old_fattr->time_start, |
| 4642 | NFS_INO_INVALID_OTHER); |
| 4643 | update_changeattr(new_dir, &res->new_cinfo, |
| 4644 | res->new_fattr->time_start, |
| 4645 | NFS_INO_INVALID_OTHER); |
| 4646 | } else |
| 4647 | update_changeattr(old_dir, &res->old_cinfo, |
| 4648 | res->old_fattr->time_start, |
| 4649 | 0); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4650 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4651 | return 1; |
| 4652 | } |
| 4653 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4654 | 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] | 4655 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4656 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4657 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | struct nfs4_link_arg arg = { |
| 4659 | .fh = NFS_FH(inode), |
| 4660 | .dir_fh = NFS_FH(dir), |
| 4661 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4662 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4664 | struct nfs4_link_res res = { |
| 4665 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4666 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4667 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | struct rpc_message msg = { |
| 4669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4670 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4671 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4673 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4675 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4676 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4677 | goto out; |
| 4678 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4679 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4680 | if (IS_ERR(res.label)) { |
| 4681 | status = PTR_ERR(res.label); |
| 4682 | goto out; |
| 4683 | } |
| 4684 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4685 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4686 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4687 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4688 | 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] | 4689 | if (!status) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4690 | update_changeattr(dir, &res.cinfo, res.fattr->time_start, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4691 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4692 | if (!status) |
| 4693 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4694 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4695 | |
| 4696 | |
| 4697 | nfs4_label_free(res.label); |
| 4698 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4699 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4700 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | return status; |
| 4702 | } |
| 4703 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4704 | 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] | 4705 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4706 | struct nfs4_exception exception = { |
| 4707 | .interruptible = true, |
| 4708 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | int err; |
| 4710 | do { |
| 4711 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4712 | _nfs4_proc_link(inode, dir, name), |
| 4713 | &exception); |
| 4714 | } while (exception.retry); |
| 4715 | return err; |
| 4716 | } |
| 4717 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4718 | struct nfs4_createdata { |
| 4719 | struct rpc_message msg; |
| 4720 | struct nfs4_create_arg arg; |
| 4721 | struct nfs4_create_res res; |
| 4722 | struct nfs_fh fh; |
| 4723 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4724 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4725 | }; |
| 4726 | |
| 4727 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4728 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4729 | { |
| 4730 | struct nfs4_createdata *data; |
| 4731 | |
| 4732 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4733 | if (data != NULL) { |
| 4734 | struct nfs_server *server = NFS_SERVER(dir); |
| 4735 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4736 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4737 | if (IS_ERR(data->label)) |
| 4738 | goto out_free; |
| 4739 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4740 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4741 | data->msg.rpc_argp = &data->arg; |
| 4742 | data->msg.rpc_resp = &data->res; |
| 4743 | data->arg.dir_fh = NFS_FH(dir); |
| 4744 | data->arg.server = server; |
| 4745 | data->arg.name = name; |
| 4746 | data->arg.attrs = sattr; |
| 4747 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4748 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4749 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4750 | data->res.server = server; |
| 4751 | data->res.fh = &data->fh; |
| 4752 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4753 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4754 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4755 | } |
| 4756 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4757 | out_free: |
| 4758 | kfree(data); |
| 4759 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4763 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4764 | 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] | 4765 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4766 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4767 | spin_lock(&dir->i_lock); |
| 4768 | update_changeattr_locked(dir, &data->res.dir_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4769 | data->res.fattr->time_start, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4770 | /* Creating a directory bumps nlink in the parent */ |
| 4771 | if (data->arg.ftype == NF4DIR) |
| 4772 | nfs4_inc_nlink_locked(dir); |
| 4773 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4774 | 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] | 4775 | } |
| 4776 | return status; |
| 4777 | } |
| 4778 | |
| 4779 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4780 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4781 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4782 | kfree(data); |
| 4783 | } |
| 4784 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4785 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4786 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4787 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4788 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4789 | struct nfs4_createdata *data; |
| 4790 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4792 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4793 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4794 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4795 | status = -ENOMEM; |
| 4796 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4797 | if (data == NULL) |
| 4798 | goto out; |
| 4799 | |
| 4800 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4801 | data->arg.u.symlink.pages = &page; |
| 4802 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4803 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4805 | status = nfs4_do_create(dir, dentry, data); |
| 4806 | |
| 4807 | nfs4_free_createdata(data); |
| 4808 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | return status; |
| 4810 | } |
| 4811 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4812 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4813 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4815 | struct nfs4_exception exception = { |
| 4816 | .interruptible = true, |
| 4817 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4818 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4820 | |
| 4821 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4824 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4825 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4826 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | &exception); |
| 4828 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4829 | |
| 4830 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | return err; |
| 4832 | } |
| 4833 | |
| 4834 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4835 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4837 | struct nfs4_createdata *data; |
| 4838 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4840 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4841 | if (data == NULL) |
| 4842 | goto out; |
| 4843 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4844 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4845 | status = nfs4_do_create(dir, dentry, data); |
| 4846 | |
| 4847 | nfs4_free_createdata(data); |
| 4848 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | return status; |
| 4850 | } |
| 4851 | |
| 4852 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4853 | struct iattr *sattr) |
| 4854 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4855 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4856 | struct nfs4_exception exception = { |
| 4857 | .interruptible = true, |
| 4858 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4859 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4861 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4862 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4863 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4864 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4865 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4867 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4868 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4869 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4870 | &exception); |
| 4871 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4872 | nfs4_label_release_security(label); |
| 4873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | return err; |
| 4875 | } |
| 4876 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4877 | static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4878 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4880 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | struct nfs4_readdir_arg args = { |
| 4882 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4883 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | .pgbase = 0, |
| 4885 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4886 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4887 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | }; |
| 4889 | struct nfs4_readdir_res res; |
| 4890 | struct rpc_message msg = { |
| 4891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4892 | .rpc_argp = &args, |
| 4893 | .rpc_resp = &res, |
| 4894 | .rpc_cred = cred, |
| 4895 | }; |
| 4896 | int status; |
| 4897 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4898 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4899 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4900 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4901 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4903 | 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] | 4904 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4905 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4906 | status += args.pgbase; |
| 4907 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4908 | |
| 4909 | nfs_invalidate_atime(dir); |
| 4910 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4911 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | return status; |
| 4913 | } |
| 4914 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4915 | static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4916 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4918 | struct nfs4_exception exception = { |
| 4919 | .interruptible = true, |
| 4920 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | int err; |
| 4922 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4923 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4924 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4925 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4926 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | &exception); |
| 4928 | } while (exception.retry); |
| 4929 | return err; |
| 4930 | } |
| 4931 | |
| 4932 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4933 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4935 | struct nfs4_createdata *data; |
| 4936 | int mode = sattr->ia_mode; |
| 4937 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4939 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4940 | if (data == NULL) |
| 4941 | goto out; |
| 4942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4944 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4946 | data->arg.ftype = NF4BLK; |
| 4947 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4948 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | } |
| 4950 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4951 | data->arg.ftype = NF4CHR; |
| 4952 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4953 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4954 | } else if (!S_ISSOCK(mode)) { |
| 4955 | status = -EINVAL; |
| 4956 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4958 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4959 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4960 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4961 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4962 | nfs4_free_createdata(data); |
| 4963 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | return status; |
| 4965 | } |
| 4966 | |
| 4967 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4968 | struct iattr *sattr, dev_t rdev) |
| 4969 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4970 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4971 | struct nfs4_exception exception = { |
| 4972 | .interruptible = true, |
| 4973 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4974 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4976 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4977 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4978 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4979 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4980 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4982 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4983 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4984 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | &exception); |
| 4986 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4987 | |
| 4988 | nfs4_label_release_security(label); |
| 4989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | return err; |
| 4991 | } |
| 4992 | |
| 4993 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4994 | struct nfs_fsstat *fsstat) |
| 4995 | { |
| 4996 | struct nfs4_statfs_arg args = { |
| 4997 | .fh = fhandle, |
| 4998 | .bitmask = server->attr_bitmask, |
| 4999 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5000 | struct nfs4_statfs_res res = { |
| 5001 | .fsstat = fsstat, |
| 5002 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | struct rpc_message msg = { |
| 5004 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5005 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5006 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | }; |
| 5008 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5009 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5010 | 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] | 5011 | } |
| 5012 | |
| 5013 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5014 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5015 | struct nfs4_exception exception = { |
| 5016 | .interruptible = true, |
| 5017 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5018 | int err; |
| 5019 | do { |
| 5020 | err = nfs4_handle_exception(server, |
| 5021 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5022 | &exception); |
| 5023 | } while (exception.retry); |
| 5024 | return err; |
| 5025 | } |
| 5026 | |
| 5027 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5028 | struct nfs_fsinfo *fsinfo) |
| 5029 | { |
| 5030 | struct nfs4_fsinfo_arg args = { |
| 5031 | .fh = fhandle, |
| 5032 | .bitmask = server->attr_bitmask, |
| 5033 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5034 | struct nfs4_fsinfo_res res = { |
| 5035 | .fsinfo = fsinfo, |
| 5036 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | struct rpc_message msg = { |
| 5038 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5039 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5040 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | }; |
| 5042 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5043 | 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] | 5044 | } |
| 5045 | |
| 5046 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5047 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5048 | struct nfs4_exception exception = { |
| 5049 | .interruptible = true, |
| 5050 | }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5051 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | int err; |
| 5053 | |
| 5054 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5055 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5056 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5057 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 5058 | nfs4_set_lease_period(server->nfs_client, |
| 5059 | fsinfo->lease_time * HZ, |
| 5060 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5061 | break; |
| 5062 | } |
| 5063 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | } while (exception.retry); |
| 5065 | return err; |
| 5066 | } |
| 5067 | |
| 5068 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5069 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5070 | int error; |
| 5071 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5072 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5073 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5074 | if (error == 0) { |
| 5075 | /* block layout checks this! */ |
| 5076 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5077 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5078 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5079 | |
| 5080 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
| 5083 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5084 | struct nfs_pathconf *pathconf) |
| 5085 | { |
| 5086 | struct nfs4_pathconf_arg args = { |
| 5087 | .fh = fhandle, |
| 5088 | .bitmask = server->attr_bitmask, |
| 5089 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5090 | struct nfs4_pathconf_res res = { |
| 5091 | .pathconf = pathconf, |
| 5092 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | struct rpc_message msg = { |
| 5094 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5095 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5096 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | }; |
| 5098 | |
| 5099 | /* None of the pathconf attributes are mandatory to implement */ |
| 5100 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5101 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5102 | return 0; |
| 5103 | } |
| 5104 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5105 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5106 | 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] | 5107 | } |
| 5108 | |
| 5109 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5110 | struct nfs_pathconf *pathconf) |
| 5111 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5112 | struct nfs4_exception exception = { |
| 5113 | .interruptible = true, |
| 5114 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | int err; |
| 5116 | |
| 5117 | do { |
| 5118 | err = nfs4_handle_exception(server, |
| 5119 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5120 | &exception); |
| 5121 | } while (exception.retry); |
| 5122 | return err; |
| 5123 | } |
| 5124 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5125 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5126 | const struct nfs_open_context *ctx, |
| 5127 | const struct nfs_lock_context *l_ctx, |
| 5128 | fmode_t fmode) |
| 5129 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5130 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5131 | } |
| 5132 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5133 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5134 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5135 | const struct nfs_open_context *ctx, |
| 5136 | const struct nfs_lock_context *l_ctx, |
| 5137 | fmode_t fmode) |
| 5138 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5139 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5140 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5141 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5142 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5143 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5144 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5145 | } |
| 5146 | |
| 5147 | static bool nfs4_error_stateid_expired(int err) |
| 5148 | { |
| 5149 | switch (err) { |
| 5150 | case -NFS4ERR_DELEG_REVOKED: |
| 5151 | case -NFS4ERR_ADMIN_REVOKED: |
| 5152 | case -NFS4ERR_BAD_STATEID: |
| 5153 | case -NFS4ERR_STALE_STATEID: |
| 5154 | case -NFS4ERR_OLD_STATEID: |
| 5155 | case -NFS4ERR_OPENMODE: |
| 5156 | case -NFS4ERR_EXPIRED: |
| 5157 | return true; |
| 5158 | } |
| 5159 | return false; |
| 5160 | } |
| 5161 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5162 | 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] | 5163 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5164 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5166 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5167 | if (task->tk_status < 0) { |
| 5168 | struct nfs4_exception exception = { |
| 5169 | .inode = hdr->inode, |
| 5170 | .state = hdr->args.context->state, |
| 5171 | .stateid = &hdr->args.stateid, |
| 5172 | }; |
| 5173 | task->tk_status = nfs4_async_handle_exception(task, |
| 5174 | server, task->tk_status, &exception); |
| 5175 | if (exception.retry) { |
| 5176 | rpc_restart_call_prepare(task); |
| 5177 | return -EAGAIN; |
| 5178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5182 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5183 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5186 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5187 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5188 | { |
| 5189 | |
| 5190 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5191 | nfs4_stateid_is_current(&args->stateid, |
| 5192 | args->context, |
| 5193 | args->lock_context, |
| 5194 | FMODE_READ)) |
| 5195 | return false; |
| 5196 | rpc_restart_call_prepare(task); |
| 5197 | return true; |
| 5198 | } |
| 5199 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5200 | 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] | 5201 | { |
| 5202 | |
| 5203 | dprintk("--> %s\n", __func__); |
| 5204 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5205 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5206 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5207 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5208 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5209 | if (task->tk_status > 0) |
| 5210 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5211 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5212 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5215 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5216 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5218 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5219 | if (!hdr->pgio_done_cb) |
| 5220 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5221 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5222 | 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] | 5223 | } |
| 5224 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5225 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5226 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5227 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5228 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5229 | &hdr->args.seq_args, |
| 5230 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5231 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5232 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5233 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5234 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5235 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5236 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5237 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5238 | return -EIO; |
| 5239 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | } |
| 5241 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5242 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5243 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5244 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5245 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5246 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5247 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5248 | if (task->tk_status < 0) { |
| 5249 | struct nfs4_exception exception = { |
| 5250 | .inode = hdr->inode, |
| 5251 | .state = hdr->args.context->state, |
| 5252 | .stateid = &hdr->args.stateid, |
| 5253 | }; |
| 5254 | task->tk_status = nfs4_async_handle_exception(task, |
| 5255 | NFS_SERVER(inode), task->tk_status, |
| 5256 | &exception); |
| 5257 | if (exception.retry) { |
| 5258 | rpc_restart_call_prepare(task); |
| 5259 | return -EAGAIN; |
| 5260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5262 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5263 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5264 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5265 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5266 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5267 | } |
| 5268 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5269 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5270 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5271 | { |
| 5272 | |
| 5273 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5274 | nfs4_stateid_is_current(&args->stateid, |
| 5275 | args->context, |
| 5276 | args->lock_context, |
| 5277 | FMODE_WRITE)) |
| 5278 | return false; |
| 5279 | rpc_restart_call_prepare(task); |
| 5280 | return true; |
| 5281 | } |
| 5282 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5283 | 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] | 5284 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5285 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5286 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5287 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5288 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5289 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5290 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5293 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5294 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5295 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5296 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5297 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5298 | return false; |
| 5299 | /* Otherwise, request attributes if and only if we don't hold |
| 5300 | * a delegation |
| 5301 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5302 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5303 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5304 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5305 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5306 | struct rpc_message *msg, |
| 5307 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5308 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5309 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5310 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5311 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5312 | hdr->args.bitmask = NULL; |
| 5313 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5314 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5315 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5316 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5317 | if (!hdr->pgio_done_cb) |
| 5318 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5319 | hdr->res.server = server; |
| 5320 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5322 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5323 | 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] | 5324 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | } |
| 5326 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5327 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5328 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5329 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5330 | &data->args.seq_args, |
| 5331 | &data->res.seq_res, |
| 5332 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5335 | 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] | 5336 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5337 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5338 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5339 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5340 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5341 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5342 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5343 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5345 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5348 | 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] | 5349 | { |
| 5350 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5351 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5352 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5355 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5356 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5358 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5359 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5360 | if (data->commit_done_cb == NULL) |
| 5361 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5362 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5363 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5364 | 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] | 5365 | 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] | 5366 | } |
| 5367 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5368 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5369 | struct nfs_commitres *res) |
| 5370 | { |
| 5371 | struct inode *dst_inode = file_inode(dst); |
| 5372 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5373 | struct rpc_message msg = { |
| 5374 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5375 | .rpc_argp = args, |
| 5376 | .rpc_resp = res, |
| 5377 | }; |
| 5378 | |
| 5379 | args->fh = NFS_FH(dst_inode); |
| 5380 | return nfs4_call_sync(server->client, server, &msg, |
| 5381 | &args->seq_args, &res->seq_res, 1); |
| 5382 | } |
| 5383 | |
| 5384 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5385 | { |
| 5386 | struct nfs_commitargs args = { |
| 5387 | .offset = offset, |
| 5388 | .count = count, |
| 5389 | }; |
| 5390 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5391 | struct nfs4_exception exception = { }; |
| 5392 | int status; |
| 5393 | |
| 5394 | do { |
| 5395 | status = _nfs4_proc_commit(dst, &args, res); |
| 5396 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5397 | } while (exception.retry); |
| 5398 | |
| 5399 | return status; |
| 5400 | } |
| 5401 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5402 | struct nfs4_renewdata { |
| 5403 | struct nfs_client *client; |
| 5404 | unsigned long timestamp; |
| 5405 | }; |
| 5406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | /* |
| 5408 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5409 | * standalone procedure for queueing an asynchronous RENEW. |
| 5410 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5411 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5412 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5413 | struct nfs4_renewdata *data = calldata; |
| 5414 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5415 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5416 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5417 | nfs4_schedule_state_renewal(clp); |
| 5418 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5419 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5420 | } |
| 5421 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5422 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5424 | struct nfs4_renewdata *data = calldata; |
| 5425 | struct nfs_client *clp = data->client; |
| 5426 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5428 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5429 | switch (task->tk_status) { |
| 5430 | case 0: |
| 5431 | break; |
| 5432 | case -NFS4ERR_LEASE_MOVED: |
| 5433 | nfs4_schedule_lease_moved_recovery(clp); |
| 5434 | break; |
| 5435 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5436 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5437 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5438 | return; |
| 5439 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5440 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5441 | return; |
| 5442 | } |
| 5443 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5445 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5446 | } |
| 5447 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5448 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5449 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5450 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5451 | }; |
| 5452 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5453 | 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] | 5454 | { |
| 5455 | struct rpc_message msg = { |
| 5456 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5457 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5458 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5459 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5460 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5462 | if (renew_flags == 0) |
| 5463 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5464 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5465 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5466 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5467 | if (data == NULL) { |
| 5468 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5469 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5470 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5471 | data->client = clp; |
| 5472 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5473 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5474 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5477 | 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] | 5478 | { |
| 5479 | struct rpc_message msg = { |
| 5480 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5481 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5482 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | }; |
| 5484 | unsigned long now = jiffies; |
| 5485 | int status; |
| 5486 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5487 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | if (status < 0) |
| 5489 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5490 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | return 0; |
| 5492 | } |
| 5493 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5494 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5495 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5496 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5497 | } |
| 5498 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5499 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5500 | * 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] | 5501 | * the stack. |
| 5502 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5503 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5504 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5505 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5506 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5507 | { |
| 5508 | struct page *newpage, **spages; |
| 5509 | int rc = 0; |
| 5510 | size_t len; |
| 5511 | spages = pages; |
| 5512 | |
| 5513 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5514 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5515 | newpage = alloc_page(GFP_KERNEL); |
| 5516 | |
| 5517 | if (newpage == NULL) |
| 5518 | goto unwind; |
| 5519 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5520 | buf += len; |
| 5521 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5522 | *pages++ = newpage; |
| 5523 | rc++; |
| 5524 | } while (buflen != 0); |
| 5525 | |
| 5526 | return rc; |
| 5527 | |
| 5528 | unwind: |
| 5529 | for(; rc > 0; rc--) |
| 5530 | __free_page(spages[rc-1]); |
| 5531 | return -ENOMEM; |
| 5532 | } |
| 5533 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5534 | struct nfs4_cached_acl { |
| 5535 | int cached; |
| 5536 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5537 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5538 | }; |
| 5539 | |
| 5540 | 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] | 5541 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5542 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5543 | |
| 5544 | spin_lock(&inode->i_lock); |
| 5545 | kfree(nfsi->nfs4_acl); |
| 5546 | nfsi->nfs4_acl = acl; |
| 5547 | spin_unlock(&inode->i_lock); |
| 5548 | } |
| 5549 | |
| 5550 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5551 | { |
| 5552 | nfs4_set_cached_acl(inode, NULL); |
| 5553 | } |
| 5554 | |
| 5555 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5556 | { |
| 5557 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5558 | struct nfs4_cached_acl *acl; |
| 5559 | int ret = -ENOENT; |
| 5560 | |
| 5561 | spin_lock(&inode->i_lock); |
| 5562 | acl = nfsi->nfs4_acl; |
| 5563 | if (acl == NULL) |
| 5564 | goto out; |
| 5565 | if (buf == NULL) /* user is just asking for length */ |
| 5566 | goto out_len; |
| 5567 | if (acl->cached == 0) |
| 5568 | goto out; |
| 5569 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5570 | if (acl->len > buflen) |
| 5571 | goto out; |
| 5572 | memcpy(buf, acl->data, acl->len); |
| 5573 | out_len: |
| 5574 | ret = acl->len; |
| 5575 | out: |
| 5576 | spin_unlock(&inode->i_lock); |
| 5577 | return ret; |
| 5578 | } |
| 5579 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5580 | 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] | 5581 | { |
| 5582 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5583 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5584 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5585 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5586 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5587 | if (acl == NULL) |
| 5588 | goto out; |
| 5589 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5590 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5591 | } else { |
| 5592 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5593 | if (acl == NULL) |
| 5594 | goto out; |
| 5595 | acl->cached = 0; |
| 5596 | } |
| 5597 | acl->len = acl_len; |
| 5598 | out: |
| 5599 | nfs4_set_cached_acl(inode, acl); |
| 5600 | } |
| 5601 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5602 | /* |
| 5603 | * The getxattr API returns the required buffer length when called with a |
| 5604 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5605 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5606 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5607 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5608 | * the cache. If not so, we throw away the page, and cache the required |
| 5609 | * length. The next getxattr call will then produce another round trip to |
| 5610 | * the server, this time with the input buf of the required size. |
| 5611 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5612 | 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] | 5613 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5614 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5615 | struct nfs_getaclargs args = { |
| 5616 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5617 | .acl_len = buflen, |
| 5618 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5619 | struct nfs_getaclres res = { |
| 5620 | .acl_len = buflen, |
| 5621 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5622 | struct rpc_message msg = { |
| 5623 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5624 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5625 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5626 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5627 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5628 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5629 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5630 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5631 | if (buflen == 0) |
| 5632 | buflen = server->rsize; |
| 5633 | |
| 5634 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5635 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5636 | if (!pages) |
| 5637 | return -ENOMEM; |
| 5638 | |
| 5639 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5640 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5641 | for (i = 0; i < npages; i++) { |
| 5642 | pages[i] = alloc_page(GFP_KERNEL); |
| 5643 | if (!pages[i]) |
| 5644 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5645 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5646 | |
| 5647 | /* for decoding across pages */ |
| 5648 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5649 | if (!res.acl_scratch) |
| 5650 | goto out_free; |
| 5651 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5652 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5653 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5654 | 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] | 5655 | __func__, buf, buflen, npages, args.acl_len); |
| 5656 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5657 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5658 | if (ret) |
| 5659 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5660 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5661 | /* Handle the case where the passed-in buffer is too short */ |
| 5662 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5663 | /* Did the user only issue a request for the acl length? */ |
| 5664 | if (buf == NULL) |
| 5665 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5666 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5667 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5668 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5669 | 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] | 5670 | if (buf) { |
| 5671 | if (res.acl_len > buflen) { |
| 5672 | ret = -ERANGE; |
| 5673 | goto out_free; |
| 5674 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5675 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5676 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5677 | out_ok: |
| 5678 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5679 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5680 | for (i = 0; i < npages; i++) |
| 5681 | if (pages[i]) |
| 5682 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5683 | if (res.acl_scratch) |
| 5684 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5685 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5686 | return ret; |
| 5687 | } |
| 5688 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5689 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5690 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5691 | struct nfs4_exception exception = { |
| 5692 | .interruptible = true, |
| 5693 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5694 | ssize_t ret; |
| 5695 | do { |
| 5696 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5697 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5698 | if (ret >= 0) |
| 5699 | break; |
| 5700 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5701 | } while (exception.retry); |
| 5702 | return ret; |
| 5703 | } |
| 5704 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5705 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5706 | { |
| 5707 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5708 | int ret; |
| 5709 | |
| 5710 | if (!nfs4_server_supports_acls(server)) |
| 5711 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5712 | ret = nfs_revalidate_inode(server, inode); |
| 5713 | if (ret < 0) |
| 5714 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5715 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5716 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5717 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5718 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5719 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5720 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5721 | return ret; |
| 5722 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5723 | } |
| 5724 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5725 | 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] | 5726 | { |
| 5727 | struct nfs_server *server = NFS_SERVER(inode); |
| 5728 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5729 | struct nfs_setaclargs arg = { |
| 5730 | .fh = NFS_FH(inode), |
| 5731 | .acl_pages = pages, |
| 5732 | .acl_len = buflen, |
| 5733 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5734 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5735 | struct rpc_message msg = { |
| 5736 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5737 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5738 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5739 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5740 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5741 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5742 | |
| 5743 | if (!nfs4_server_supports_acls(server)) |
| 5744 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5745 | if (npages > ARRAY_SIZE(pages)) |
| 5746 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5747 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5748 | if (i < 0) |
| 5749 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5750 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5751 | 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] | 5752 | |
| 5753 | /* |
| 5754 | * Free each page after tx, so the only ref left is |
| 5755 | * held by the network stack |
| 5756 | */ |
| 5757 | for (; i > 0; i--) |
| 5758 | put_page(pages[i-1]); |
| 5759 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5760 | /* |
| 5761 | * Acl update can result in inode attribute update. |
| 5762 | * so mark the attribute cache invalid. |
| 5763 | */ |
| 5764 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5765 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5766 | | NFS_INO_INVALID_CTIME |
| 5767 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5768 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5769 | nfs_access_zap_cache(inode); |
| 5770 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5771 | return ret; |
| 5772 | } |
| 5773 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5774 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5775 | { |
| 5776 | struct nfs4_exception exception = { }; |
| 5777 | int err; |
| 5778 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5779 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5780 | trace_nfs4_set_acl(inode, err); |
| 5781 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5782 | &exception); |
| 5783 | } while (exception.retry); |
| 5784 | return err; |
| 5785 | } |
| 5786 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5787 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5788 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5789 | size_t buflen) |
| 5790 | { |
| 5791 | struct nfs_server *server = NFS_SERVER(inode); |
| 5792 | struct nfs_fattr fattr; |
| 5793 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5794 | |
| 5795 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5796 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5797 | .fh = NFS_FH(inode), |
| 5798 | .bitmask = bitmask, |
| 5799 | }; |
| 5800 | struct nfs4_getattr_res res = { |
| 5801 | .fattr = &fattr, |
| 5802 | .label = &label, |
| 5803 | .server = server, |
| 5804 | }; |
| 5805 | struct rpc_message msg = { |
| 5806 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5807 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5808 | .rpc_resp = &res, |
| 5809 | }; |
| 5810 | int ret; |
| 5811 | |
| 5812 | nfs_fattr_init(&fattr); |
| 5813 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5814 | 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] | 5815 | if (ret) |
| 5816 | return ret; |
| 5817 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5818 | return -ENOENT; |
| 5819 | if (buflen < label.len) |
| 5820 | return -ERANGE; |
| 5821 | return 0; |
| 5822 | } |
| 5823 | |
| 5824 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5825 | size_t buflen) |
| 5826 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5827 | struct nfs4_exception exception = { |
| 5828 | .interruptible = true, |
| 5829 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5830 | int err; |
| 5831 | |
| 5832 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5833 | return -EOPNOTSUPP; |
| 5834 | |
| 5835 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5836 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5837 | trace_nfs4_get_security_label(inode, err); |
| 5838 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5839 | &exception); |
| 5840 | } while (exception.retry); |
| 5841 | return err; |
| 5842 | } |
| 5843 | |
| 5844 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5845 | struct nfs4_label *ilabel, |
| 5846 | struct nfs_fattr *fattr, |
| 5847 | struct nfs4_label *olabel) |
| 5848 | { |
| 5849 | |
| 5850 | struct iattr sattr = {0}; |
| 5851 | struct nfs_server *server = NFS_SERVER(inode); |
| 5852 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5853 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5854 | .fh = NFS_FH(inode), |
| 5855 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5856 | .server = server, |
| 5857 | .bitmask = bitmask, |
| 5858 | .label = ilabel, |
| 5859 | }; |
| 5860 | struct nfs_setattrres res = { |
| 5861 | .fattr = fattr, |
| 5862 | .label = olabel, |
| 5863 | .server = server, |
| 5864 | }; |
| 5865 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5866 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5867 | .rpc_argp = &arg, |
| 5868 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5869 | }; |
| 5870 | int status; |
| 5871 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5872 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5873 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5874 | 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] | 5875 | if (status) |
| 5876 | dprintk("%s failed: %d\n", __func__, status); |
| 5877 | |
| 5878 | return status; |
| 5879 | } |
| 5880 | |
| 5881 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5882 | struct nfs4_label *ilabel, |
| 5883 | struct nfs_fattr *fattr, |
| 5884 | struct nfs4_label *olabel) |
| 5885 | { |
| 5886 | struct nfs4_exception exception = { }; |
| 5887 | int err; |
| 5888 | |
| 5889 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5890 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5891 | fattr, olabel); |
| 5892 | trace_nfs4_set_security_label(inode, err); |
| 5893 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5894 | &exception); |
| 5895 | } while (exception.retry); |
| 5896 | return err; |
| 5897 | } |
| 5898 | |
| 5899 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5900 | 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] | 5901 | { |
| 5902 | struct nfs4_label ilabel, *olabel = NULL; |
| 5903 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5904 | int status; |
| 5905 | |
| 5906 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5907 | return -EOPNOTSUPP; |
| 5908 | |
| 5909 | nfs_fattr_init(&fattr); |
| 5910 | |
| 5911 | ilabel.pi = 0; |
| 5912 | ilabel.lfs = 0; |
| 5913 | ilabel.label = (char *)buf; |
| 5914 | ilabel.len = buflen; |
| 5915 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5916 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5917 | if (IS_ERR(olabel)) { |
| 5918 | status = -PTR_ERR(olabel); |
| 5919 | goto out; |
| 5920 | } |
| 5921 | |
| 5922 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5923 | if (status == 0) |
| 5924 | nfs_setsecurity(inode, &fattr, olabel); |
| 5925 | |
| 5926 | nfs4_label_free(olabel); |
| 5927 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5928 | return status; |
| 5929 | } |
| 5930 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5931 | |
| 5932 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5933 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5934 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5935 | { |
| 5936 | __be32 verf[2]; |
| 5937 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5938 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5939 | /* An impossible timestamp guarantees this value |
| 5940 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5941 | verf[0] = cpu_to_be32(U32_MAX); |
| 5942 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5943 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5944 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5945 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5946 | |
| 5947 | verf[0] = cpu_to_be32(ns >> 32); |
| 5948 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5949 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5950 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5951 | } |
| 5952 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5953 | static int |
| 5954 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5955 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5956 | size_t len; |
| 5957 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5958 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5959 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5960 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5961 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5962 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5963 | len = 14 + |
| 5964 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5965 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5966 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5967 | 1; |
| 5968 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5969 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5970 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5971 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5972 | return -EINVAL; |
| 5973 | |
| 5974 | /* |
| 5975 | * Since this string is allocated at mount time, and held until the |
| 5976 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5977 | * about a memory-reclaim deadlock. |
| 5978 | */ |
| 5979 | str = kmalloc(len, GFP_KERNEL); |
| 5980 | if (!str) |
| 5981 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5982 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5983 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5984 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5985 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5986 | clp->cl_rpcclient->cl_nodename, |
| 5987 | nfs4_client_id_uniquifier, |
| 5988 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5989 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5990 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5991 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5992 | clp->cl_rpcclient->cl_nodename, |
| 5993 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5994 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5995 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5996 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5997 | clp->cl_owner_id = str; |
| 5998 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5999 | } |
| 6000 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6001 | static int |
| 6002 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6003 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6004 | size_t len; |
| 6005 | char *str; |
| 6006 | |
| 6007 | len = 10 + 10 + 1 + 10 + 1 + |
| 6008 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 6009 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6010 | |
| 6011 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6012 | return -EINVAL; |
| 6013 | |
| 6014 | /* |
| 6015 | * Since this string is allocated at mount time, and held until the |
| 6016 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6017 | * about a memory-reclaim deadlock. |
| 6018 | */ |
| 6019 | str = kmalloc(len, GFP_KERNEL); |
| 6020 | if (!str) |
| 6021 | return -ENOMEM; |
| 6022 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 6023 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6024 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6025 | nfs4_client_id_uniquifier, |
| 6026 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6027 | clp->cl_owner_id = str; |
| 6028 | return 0; |
| 6029 | } |
| 6030 | |
| 6031 | static int |
| 6032 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6033 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6034 | size_t len; |
| 6035 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6036 | |
| 6037 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6038 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6039 | |
| 6040 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6041 | return nfs4_init_uniquifier_client_string(clp); |
| 6042 | |
| 6043 | len = 10 + 10 + 1 + 10 + 1 + |
| 6044 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6045 | |
| 6046 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6047 | return -EINVAL; |
| 6048 | |
| 6049 | /* |
| 6050 | * Since this string is allocated at mount time, and held until the |
| 6051 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6052 | * about a memory-reclaim deadlock. |
| 6053 | */ |
| 6054 | str = kmalloc(len, GFP_KERNEL); |
| 6055 | if (!str) |
| 6056 | return -ENOMEM; |
| 6057 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 6058 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6059 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6060 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6061 | clp->cl_owner_id = str; |
| 6062 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6063 | } |
| 6064 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6065 | /* |
| 6066 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6067 | * services. Advertise one based on the address family of the |
| 6068 | * clientaddr. |
| 6069 | */ |
| 6070 | static unsigned int |
| 6071 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6072 | { |
| 6073 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6074 | return scnprintf(buf, len, "tcp6"); |
| 6075 | else |
| 6076 | return scnprintf(buf, len, "tcp"); |
| 6077 | } |
| 6078 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6079 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6080 | { |
| 6081 | struct nfs4_setclientid *sc = calldata; |
| 6082 | |
| 6083 | if (task->tk_status == 0) |
| 6084 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6085 | } |
| 6086 | |
| 6087 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6088 | .rpc_call_done = nfs4_setclientid_done, |
| 6089 | }; |
| 6090 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6091 | /** |
| 6092 | * nfs4_proc_setclientid - Negotiate client ID |
| 6093 | * @clp: state data structure |
| 6094 | * @program: RPC program for NFSv4 callback service |
| 6095 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6096 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6097 | * @res: where to place the result |
| 6098 | * |
| 6099 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6100 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6101 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6102 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6103 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6104 | { |
| 6105 | nfs4_verifier sc_verifier; |
| 6106 | struct nfs4_setclientid setclientid = { |
| 6107 | .sc_verifier = &sc_verifier, |
| 6108 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6109 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6110 | }; |
| 6111 | struct rpc_message msg = { |
| 6112 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6113 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6114 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6115 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6117 | struct rpc_task_setup task_setup_data = { |
| 6118 | .rpc_client = clp->cl_rpcclient, |
| 6119 | .rpc_message = &msg, |
| 6120 | .callback_ops = &nfs4_setclientid_ops, |
| 6121 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6122 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6123 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6124 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6126 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6127 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6128 | |
| 6129 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6130 | status = nfs4_init_uniform_client_string(clp); |
| 6131 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6132 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6133 | |
| 6134 | if (status) |
| 6135 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6136 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6137 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6138 | setclientid.sc_netid_len = |
| 6139 | nfs4_init_callback_netid(clp, |
| 6140 | setclientid.sc_netid, |
| 6141 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6142 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6143 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6145 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6146 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6147 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6148 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6149 | |
| 6150 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6151 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6152 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6153 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6154 | put_rpccred(setclientid.sc_cred); |
| 6155 | } |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6156 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6157 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6158 | dprintk("NFS reply setclientid: %d\n", status); |
| 6159 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6160 | } |
| 6161 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6162 | /** |
| 6163 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6164 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6165 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6166 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6167 | * |
| 6168 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6169 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6170 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6171 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6172 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | struct rpc_message msg = { |
| 6175 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6176 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6177 | .rpc_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 | int status; |
| 6180 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6181 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6182 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6183 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6184 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6185 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6186 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6187 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | return status; |
| 6189 | } |
| 6190 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6191 | struct nfs4_delegreturndata { |
| 6192 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6193 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6194 | struct nfs_fh fh; |
| 6195 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6196 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6197 | struct { |
| 6198 | struct nfs4_layoutreturn_args arg; |
| 6199 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6200 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6201 | u32 roc_barrier; |
| 6202 | bool roc; |
| 6203 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6204 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6205 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6206 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6207 | }; |
| 6208 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6209 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6210 | { |
| 6211 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6212 | struct nfs4_exception exception = { |
| 6213 | .inode = data->inode, |
| 6214 | .stateid = &data->stateid, |
| 6215 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6216 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6217 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6218 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6219 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6220 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6221 | |
| 6222 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6223 | if (pnfs_roc_done(task, data->inode, |
| 6224 | &data->args.lr_args, |
| 6225 | &data->res.lr_res, |
| 6226 | &data->res.lr_ret) == -EAGAIN) |
| 6227 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6228 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6229 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6230 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6231 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6232 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6233 | case -NFS4ERR_ADMIN_REVOKED: |
| 6234 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6235 | case -NFS4ERR_EXPIRED: |
| 6236 | nfs4_free_revoked_stateid(data->res.server, |
| 6237 | data->args.stateid, |
| 6238 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6239 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6240 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6241 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6242 | task->tk_status = 0; |
| 6243 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6244 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6245 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6246 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6247 | if (data->args.bitmask) { |
| 6248 | data->args.bitmask = NULL; |
| 6249 | data->res.fattr = NULL; |
| 6250 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6251 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6252 | case -NFS4ERR_ACCESS: |
| 6253 | if (data->args.bitmask) { |
| 6254 | data->args.bitmask = NULL; |
| 6255 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6256 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6257 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6258 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6259 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6260 | task->tk_status = nfs4_async_handle_exception(task, |
| 6261 | data->res.server, task->tk_status, |
| 6262 | &exception); |
| 6263 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6264 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6265 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6266 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6267 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6268 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6269 | out_restart: |
| 6270 | task->tk_status = 0; |
| 6271 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6272 | } |
| 6273 | |
| 6274 | static void nfs4_delegreturn_release(void *calldata) |
| 6275 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6276 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6277 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6278 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6279 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6280 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6281 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6282 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6283 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6284 | nfs_iput_and_deactive(inode); |
| 6285 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6286 | kfree(calldata); |
| 6287 | } |
| 6288 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6289 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6290 | { |
| 6291 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6292 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6293 | |
| 6294 | d_data = (struct nfs4_delegreturndata *)data; |
| 6295 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6296 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6297 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6298 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6299 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6300 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6301 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6302 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6303 | d_data->args.lr_args = NULL; |
| 6304 | d_data->res.lr_res = NULL; |
| 6305 | } |
| 6306 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6307 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6308 | &d_data->args.seq_args, |
| 6309 | &d_data->res.seq_res, |
| 6310 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6311 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6312 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6313 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6314 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6315 | .rpc_call_done = nfs4_delegreturn_done, |
| 6316 | .rpc_release = nfs4_delegreturn_release, |
| 6317 | }; |
| 6318 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6319 | 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] | 6320 | { |
| 6321 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6322 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6323 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6324 | struct rpc_message msg = { |
| 6325 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6326 | .rpc_cred = cred, |
| 6327 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6328 | struct rpc_task_setup task_setup_data = { |
| 6329 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6330 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6331 | .callback_ops = &nfs4_delegreturn_ops, |
| 6332 | .flags = RPC_TASK_ASYNC, |
| 6333 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6334 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6335 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6336 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6337 | if (data == NULL) |
| 6338 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6339 | 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] | 6340 | |
| 6341 | nfs4_state_protect(server->nfs_client, |
| 6342 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6343 | &task_setup_data.rpc_client, &msg); |
| 6344 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6345 | data->args.fhandle = &data->fh; |
| 6346 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6347 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6348 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6349 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6350 | data->res.fattr = &data->fattr; |
| 6351 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6352 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6353 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6354 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6355 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6356 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6357 | 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] | 6358 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6359 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6360 | if (data->lr.roc) { |
| 6361 | data->args.lr_args = &data->lr.arg; |
| 6362 | data->res.lr_res = &data->lr.res; |
| 6363 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6364 | } else if (data->lr.roc) { |
| 6365 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6366 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6367 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6368 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6369 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6370 | msg.rpc_argp = &data->args; |
| 6371 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6372 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6373 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6374 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6375 | if (!issync) |
| 6376 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6377 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6378 | if (status != 0) |
| 6379 | goto out; |
| 6380 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6381 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6382 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6383 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6384 | } |
| 6385 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6386 | 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] | 6387 | { |
| 6388 | struct nfs_server *server = NFS_SERVER(inode); |
| 6389 | struct nfs4_exception exception = { }; |
| 6390 | int err; |
| 6391 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6392 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6393 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6394 | switch (err) { |
| 6395 | case -NFS4ERR_STALE_STATEID: |
| 6396 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | case 0: |
| 6398 | return 0; |
| 6399 | } |
| 6400 | err = nfs4_handle_exception(server, err, &exception); |
| 6401 | } while (exception.retry); |
| 6402 | return err; |
| 6403 | } |
| 6404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6405 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6406 | { |
| 6407 | struct inode *inode = state->inode; |
| 6408 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6409 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6410 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6411 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6412 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6414 | struct nfs_lockt_res res = { |
| 6415 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6416 | }; |
| 6417 | struct rpc_message msg = { |
| 6418 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6419 | .rpc_argp = &arg, |
| 6420 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | .rpc_cred = state->owner->so_cred, |
| 6422 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6423 | struct nfs4_lock_state *lsp; |
| 6424 | int status; |
| 6425 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6426 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6427 | status = nfs4_set_lock_state(state, request); |
| 6428 | if (status != 0) |
| 6429 | goto out; |
| 6430 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6431 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6432 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6433 | 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] | 6434 | switch (status) { |
| 6435 | case 0: |
| 6436 | request->fl_type = F_UNLCK; |
| 6437 | break; |
| 6438 | case -NFS4ERR_DENIED: |
| 6439 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6440 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6441 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6442 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6443 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6444 | return status; |
| 6445 | } |
| 6446 | |
| 6447 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6448 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6449 | struct nfs4_exception exception = { |
| 6450 | .interruptible = true, |
| 6451 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6452 | int err; |
| 6453 | |
| 6454 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6455 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6456 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6457 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6458 | &exception); |
| 6459 | } while (exception.retry); |
| 6460 | return err; |
| 6461 | } |
| 6462 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6463 | /* |
| 6464 | * Update the seqid of a lock stateid after receiving |
| 6465 | * NFS4ERR_OLD_STATEID |
| 6466 | */ |
| 6467 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6468 | struct nfs4_lock_state *lsp) |
| 6469 | { |
| 6470 | struct nfs4_state *state = lsp->ls_state; |
| 6471 | bool ret = false; |
| 6472 | |
| 6473 | spin_lock(&state->state_lock); |
| 6474 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6475 | goto out; |
| 6476 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6477 | nfs4_stateid_seqid_inc(dst); |
| 6478 | else |
| 6479 | dst->seqid = lsp->ls_stateid.seqid; |
| 6480 | ret = true; |
| 6481 | out: |
| 6482 | spin_unlock(&state->state_lock); |
| 6483 | return ret; |
| 6484 | } |
| 6485 | |
| 6486 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6487 | struct nfs4_lock_state *lsp) |
| 6488 | { |
| 6489 | struct nfs4_state *state = lsp->ls_state; |
| 6490 | bool ret; |
| 6491 | |
| 6492 | spin_lock(&state->state_lock); |
| 6493 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6494 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6495 | spin_unlock(&state->state_lock); |
| 6496 | return ret; |
| 6497 | } |
| 6498 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6499 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6500 | struct nfs_locku_args arg; |
| 6501 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6502 | struct nfs4_lock_state *lsp; |
| 6503 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6504 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6505 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6506 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6507 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6508 | }; |
| 6509 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6510 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6511 | struct nfs_open_context *ctx, |
| 6512 | struct nfs4_lock_state *lsp, |
| 6513 | struct nfs_seqid *seqid) |
| 6514 | { |
| 6515 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6516 | struct nfs4_state *state = lsp->ls_state; |
| 6517 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6518 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6519 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6520 | if (p == NULL) |
| 6521 | return NULL; |
| 6522 | p->arg.fh = NFS_FH(inode); |
| 6523 | p->arg.fl = &p->fl; |
| 6524 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6525 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6526 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6527 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6528 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6529 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6530 | locks_init_lock(&p->fl); |
| 6531 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6532 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6533 | spin_lock(&state->state_lock); |
| 6534 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6535 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6536 | return p; |
| 6537 | } |
| 6538 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6539 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6540 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6541 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6542 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6543 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6544 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6545 | put_nfs_open_context(calldata->ctx); |
| 6546 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6547 | } |
| 6548 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6549 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6550 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6551 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6552 | struct nfs4_exception exception = { |
| 6553 | .inode = calldata->lsp->ls_state->inode, |
| 6554 | .stateid = &calldata->arg.stateid, |
| 6555 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6556 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6557 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6558 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6559 | switch (task->tk_status) { |
| 6560 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6561 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6562 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6563 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6564 | &calldata->res.stateid)) |
| 6565 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6566 | /* Fall through */ |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6567 | case -NFS4ERR_ADMIN_REVOKED: |
| 6568 | case -NFS4ERR_EXPIRED: |
| 6569 | nfs4_free_revoked_stateid(calldata->server, |
| 6570 | &calldata->arg.stateid, |
| 6571 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6572 | /* Fall through */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6573 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6574 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6575 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6576 | calldata->lsp)) |
| 6577 | rpc_restart_call_prepare(task); |
| 6578 | break; |
| 6579 | case -NFS4ERR_OLD_STATEID: |
| 6580 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6581 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6582 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6583 | break; |
| 6584 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6585 | task->tk_status = nfs4_async_handle_exception(task, |
| 6586 | calldata->server, task->tk_status, |
| 6587 | &exception); |
| 6588 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6589 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6590 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6591 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6592 | } |
| 6593 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6594 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6595 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6596 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6597 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6598 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6599 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6600 | return; |
| 6601 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6602 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6603 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6604 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6605 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6606 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6607 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6608 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6609 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6610 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6611 | &calldata->res.seq_res, |
| 6612 | task) != 0) |
| 6613 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6614 | return; |
| 6615 | out_no_action: |
| 6616 | task->tk_action = NULL; |
| 6617 | out_wait: |
| 6618 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6619 | } |
| 6620 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6621 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6622 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6623 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6624 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6625 | }; |
| 6626 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6627 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6628 | struct nfs_open_context *ctx, |
| 6629 | struct nfs4_lock_state *lsp, |
| 6630 | struct nfs_seqid *seqid) |
| 6631 | { |
| 6632 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6633 | struct rpc_message msg = { |
| 6634 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6635 | .rpc_cred = ctx->cred, |
| 6636 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6637 | struct rpc_task_setup task_setup_data = { |
| 6638 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6639 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6640 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6641 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6642 | .flags = RPC_TASK_ASYNC, |
| 6643 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6644 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6645 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6646 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6647 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6648 | /* Ensure this is an unlock - when canceling a lock, the |
| 6649 | * canceled lock is passed in, and it won't be an unlock. |
| 6650 | */ |
| 6651 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6652 | if (fl->fl_flags & FL_CLOSE) |
| 6653 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6654 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6655 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6656 | if (data == NULL) { |
| 6657 | nfs_free_seqid(seqid); |
| 6658 | return ERR_PTR(-ENOMEM); |
| 6659 | } |
| 6660 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6661 | 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] | 6662 | msg.rpc_argp = &data->arg; |
| 6663 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6664 | task_setup_data.callback_data = data; |
| 6665 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6666 | } |
| 6667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6668 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6669 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6670 | struct inode *inode = state->inode; |
| 6671 | struct nfs4_state_owner *sp = state->owner; |
| 6672 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6673 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6674 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6675 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6676 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6677 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6678 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6679 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6680 | status = nfs4_set_lock_state(state, request); |
| 6681 | /* Unlock _before_ we do the RPC call */ |
| 6682 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6683 | /* Exclude nfs_delegation_claim_locks() */ |
| 6684 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6685 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6686 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6687 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6688 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6689 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6690 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6691 | } |
| 6692 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6693 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6694 | if (status != 0) |
| 6695 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6696 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6697 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6698 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6699 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6700 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6701 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6702 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6703 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6704 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6705 | 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] | 6706 | status = PTR_ERR(task); |
| 6707 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6708 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6709 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6710 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6711 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6712 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6713 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6714 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6715 | } |
| 6716 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6717 | struct nfs4_lockdata { |
| 6718 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6719 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6720 | struct nfs4_lock_state *lsp; |
| 6721 | struct nfs_open_context *ctx; |
| 6722 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6723 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6724 | int rpc_status; |
| 6725 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6726 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6727 | }; |
| 6728 | |
| 6729 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6730 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6731 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6732 | { |
| 6733 | struct nfs4_lockdata *p; |
| 6734 | struct inode *inode = lsp->ls_state->inode; |
| 6735 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6736 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6737 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6738 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6739 | if (p == NULL) |
| 6740 | return NULL; |
| 6741 | |
| 6742 | p->arg.fh = NFS_FH(inode); |
| 6743 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6744 | 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] | 6745 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6746 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6747 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6748 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6749 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6750 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6751 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6752 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6753 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6754 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6755 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6756 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6757 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6758 | locks_init_lock(&p->fl); |
| 6759 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6760 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6761 | out_free_seqid: |
| 6762 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6763 | out_free: |
| 6764 | kfree(p); |
| 6765 | return NULL; |
| 6766 | } |
| 6767 | |
| 6768 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6769 | { |
| 6770 | struct nfs4_lockdata *data = calldata; |
| 6771 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6772 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6773 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6774 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6775 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6776 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6777 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6778 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6779 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6780 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6781 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6782 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6783 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6784 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6785 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6786 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6787 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6788 | &data->lsp->ls_stateid); |
| 6789 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6790 | if (!nfs4_valid_open_stateid(state)) { |
| 6791 | data->rpc_status = -EBADF; |
| 6792 | task->tk_action = NULL; |
| 6793 | goto out_release_open_seqid; |
| 6794 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6795 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6796 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6797 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6798 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6799 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6800 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6801 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6802 | nfs_release_seqid(data->arg.open_seqid); |
| 6803 | out_release_lock_seqid: |
| 6804 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6805 | out_wait: |
| 6806 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6807 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6808 | } |
| 6809 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6810 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6811 | { |
| 6812 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6813 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6814 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6815 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6816 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6817 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6818 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6819 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6820 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6821 | switch (task->tk_status) { |
| 6822 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6823 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6824 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6825 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6826 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6827 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6828 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6829 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6830 | if (data->arg.new_lock_owner != 0) { |
| 6831 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6832 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6833 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6834 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6835 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6836 | break; |
| 6837 | case -NFS4ERR_BAD_STATEID: |
| 6838 | case -NFS4ERR_OLD_STATEID: |
| 6839 | case -NFS4ERR_STALE_STATEID: |
| 6840 | case -NFS4ERR_EXPIRED: |
| 6841 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6842 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6843 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6844 | goto out_restart; |
| 6845 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6846 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6847 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6848 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6849 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6850 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6851 | return; |
| 6852 | out_restart: |
| 6853 | if (!data->cancelled) |
| 6854 | rpc_restart_call_prepare(task); |
| 6855 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | static void nfs4_lock_release(void *calldata) |
| 6859 | { |
| 6860 | struct nfs4_lockdata *data = calldata; |
| 6861 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6862 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6863 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6864 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6865 | struct rpc_task *task; |
| 6866 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6867 | data->arg.lock_seqid); |
| 6868 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6869 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6870 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6871 | } else |
| 6872 | nfs_free_seqid(data->arg.lock_seqid); |
| 6873 | nfs4_put_lock_state(data->lsp); |
| 6874 | put_nfs_open_context(data->ctx); |
| 6875 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6876 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6877 | } |
| 6878 | |
| 6879 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6880 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6881 | .rpc_call_done = nfs4_lock_done, |
| 6882 | .rpc_release = nfs4_lock_release, |
| 6883 | }; |
| 6884 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6885 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6886 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6887 | switch (error) { |
| 6888 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6889 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6890 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6891 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6892 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6893 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6894 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6895 | break; |
| 6896 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6897 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6898 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 6899 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6900 | } |
| 6901 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6902 | 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] | 6903 | { |
| 6904 | struct nfs4_lockdata *data; |
| 6905 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6906 | struct rpc_message msg = { |
| 6907 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6908 | .rpc_cred = state->owner->so_cred, |
| 6909 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6910 | struct rpc_task_setup task_setup_data = { |
| 6911 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6912 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6913 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6914 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6915 | .flags = RPC_TASK_ASYNC, |
| 6916 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6917 | int ret; |
| 6918 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6919 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6920 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6921 | fl->fl_u.nfs4_fl.owner, |
| 6922 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6923 | if (data == NULL) |
| 6924 | return -ENOMEM; |
| 6925 | if (IS_SETLKW(cmd)) |
| 6926 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6927 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6928 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6929 | msg.rpc_argp = &data->arg; |
| 6930 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6931 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6932 | if (recovery_type > NFS_LOCK_NEW) { |
| 6933 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6934 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6935 | } else |
| 6936 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6937 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6938 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6939 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6940 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6941 | if (ret == 0) { |
| 6942 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6943 | if (ret) |
| 6944 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6945 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6946 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6947 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6948 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6949 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6950 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6951 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
| 6954 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6955 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6956 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6957 | struct nfs4_exception exception = { |
| 6958 | .inode = state->inode, |
| 6959 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6960 | int err; |
| 6961 | |
| 6962 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6963 | /* Cache the lock if possible... */ |
| 6964 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6965 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6966 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6967 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6968 | break; |
| 6969 | nfs4_handle_exception(server, err, &exception); |
| 6970 | } while (exception.retry); |
| 6971 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6975 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6976 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6977 | struct nfs4_exception exception = { |
| 6978 | .inode = state->inode, |
| 6979 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6980 | int err; |
| 6981 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6982 | err = nfs4_set_lock_state(state, request); |
| 6983 | if (err != 0) |
| 6984 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6985 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6986 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6987 | return 0; |
| 6988 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6989 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6990 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6991 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6992 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6993 | switch (err) { |
| 6994 | default: |
| 6995 | goto out; |
| 6996 | case -NFS4ERR_GRACE: |
| 6997 | case -NFS4ERR_DELAY: |
| 6998 | nfs4_handle_exception(server, err, &exception); |
| 6999 | err = 0; |
| 7000 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7001 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7002 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7003 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7004 | } |
| 7005 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7006 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7007 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7008 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7009 | struct nfs4_lock_state *lsp; |
| 7010 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7011 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7012 | status = nfs4_set_lock_state(state, request); |
| 7013 | if (status != 0) |
| 7014 | return status; |
| 7015 | lsp = request->fl_u.nfs4_fl.owner; |
| 7016 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7017 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7018 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7019 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7020 | } |
| 7021 | #endif |
| 7022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7023 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7024 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7025 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7026 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7027 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7028 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7029 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7030 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7031 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7032 | if (status < 0) |
| 7033 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7034 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7035 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7036 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7037 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7038 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7039 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7040 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7041 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7042 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7043 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7044 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7045 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7046 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7047 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7048 | out: |
| 7049 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7050 | return status; |
| 7051 | } |
| 7052 | |
| 7053 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7054 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7055 | struct nfs4_exception exception = { |
| 7056 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7057 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7058 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7059 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7060 | int err; |
| 7061 | |
| 7062 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7063 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7064 | if (err == -NFS4ERR_DENIED) |
| 7065 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7066 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7067 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7068 | } while (exception.retry); |
| 7069 | return err; |
| 7070 | } |
| 7071 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7072 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7073 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7074 | |
| 7075 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7076 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7077 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7078 | { |
| 7079 | int status = -ERESTARTSYS; |
| 7080 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7081 | |
| 7082 | while(!signalled()) { |
| 7083 | status = nfs4_proc_setlk(state, cmd, request); |
| 7084 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7085 | break; |
| 7086 | freezable_schedule_timeout_interruptible(timeout); |
| 7087 | timeout *= 2; |
| 7088 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7089 | status = -ERESTARTSYS; |
| 7090 | } |
| 7091 | return status; |
| 7092 | } |
| 7093 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7094 | #ifdef CONFIG_NFS_V4_1 |
| 7095 | struct nfs4_lock_waiter { |
| 7096 | struct task_struct *task; |
| 7097 | struct inode *inode; |
| 7098 | struct nfs_lowner *owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7099 | }; |
| 7100 | |
| 7101 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7102 | 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] | 7103 | { |
| 7104 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7105 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7106 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7107 | /* NULL key means to wake up everyone */ |
| 7108 | if (key) { |
| 7109 | struct cb_notify_lock_args *cbnl = key; |
| 7110 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 7111 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7112 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7113 | /* Only wake if the callback was for the same owner. */ |
| 7114 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7115 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7116 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7117 | /* Make sure it's for the right inode */ |
| 7118 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7119 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7120 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7121 | |
| 7122 | /* override "private" so we can use default_wake_function */ |
| 7123 | wait->private = waiter->task; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7124 | ret = woken_wake_function(wait, mode, flags, key); |
| 7125 | if (ret) |
| 7126 | list_del_init(&wait->entry); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7127 | wait->private = waiter; |
| 7128 | return ret; |
| 7129 | } |
| 7130 | |
| 7131 | static int |
| 7132 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7133 | { |
| 7134 | int status = -ERESTARTSYS; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7135 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7136 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7137 | struct nfs_client *clp = server->nfs_client; |
| 7138 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 7139 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 7140 | .id = lsp->ls_seqid.owner_id, |
| 7141 | .s_dev = server->s_dev }; |
| 7142 | struct nfs4_lock_waiter waiter = { .task = current, |
| 7143 | .inode = state->inode, |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7144 | .owner = &owner}; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7145 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7146 | |
| 7147 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7148 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7149 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7150 | |
| 7151 | init_wait(&wait); |
| 7152 | wait.private = &waiter; |
| 7153 | wait.func = nfs4_wake_lock_waiter; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7154 | |
| 7155 | while(!signalled()) { |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7156 | add_wait_queue(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7157 | status = nfs4_proc_setlk(state, cmd, request); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7158 | if ((status != -EAGAIN) || IS_SETLK(cmd)) { |
| 7159 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7160 | break; |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7161 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7162 | |
| 7163 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7164 | freezer_do_not_count(); |
| 7165 | wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); |
| 7166 | freezer_count(); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7167 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7168 | } |
| 7169 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7170 | return status; |
| 7171 | } |
| 7172 | #else /* !CONFIG_NFS_V4_1 */ |
| 7173 | static inline int |
| 7174 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7175 | { |
| 7176 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7177 | } |
| 7178 | #endif |
| 7179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7180 | static int |
| 7181 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7182 | { |
| 7183 | struct nfs_open_context *ctx; |
| 7184 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7185 | int status; |
| 7186 | |
| 7187 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7188 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7189 | state = ctx->state; |
| 7190 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7191 | if (IS_GETLK(cmd)) { |
| 7192 | if (state != NULL) |
| 7193 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7194 | return 0; |
| 7195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7196 | |
| 7197 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7198 | return -EINVAL; |
| 7199 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7200 | if (request->fl_type == F_UNLCK) { |
| 7201 | if (state != NULL) |
| 7202 | return nfs4_proc_unlck(state, cmd, request); |
| 7203 | return 0; |
| 7204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7205 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7206 | if (state == NULL) |
| 7207 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7208 | |
| 7209 | if ((request->fl_flags & FL_POSIX) && |
| 7210 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7211 | return -ENOLCK; |
| 7212 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7213 | /* |
| 7214 | * Don't rely on the VFS having checked the file open mode, |
| 7215 | * since it won't do this for flock() locks. |
| 7216 | */ |
| 7217 | switch (request->fl_type) { |
| 7218 | case F_RDLCK: |
| 7219 | if (!(filp->f_mode & FMODE_READ)) |
| 7220 | return -EBADF; |
| 7221 | break; |
| 7222 | case F_WRLCK: |
| 7223 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7224 | return -EBADF; |
| 7225 | } |
| 7226 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7227 | status = nfs4_set_lock_state(state, request); |
| 7228 | if (status != 0) |
| 7229 | return status; |
| 7230 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7231 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7232 | } |
| 7233 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7234 | 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] | 7235 | { |
| 7236 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7237 | int err; |
| 7238 | |
| 7239 | err = nfs4_set_lock_state(state, fl); |
| 7240 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7241 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 7242 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7243 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7244 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7245 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7246 | struct nfs_release_lockowner_data { |
| 7247 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7248 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7249 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7250 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7251 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7252 | }; |
| 7253 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7254 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7255 | { |
| 7256 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7257 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7258 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7259 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7260 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7261 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7265 | { |
| 7266 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7267 | struct nfs_server *server = data->server; |
| 7268 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7269 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7270 | |
| 7271 | switch (task->tk_status) { |
| 7272 | case 0: |
| 7273 | renew_lease(server, data->timestamp); |
| 7274 | break; |
| 7275 | case -NFS4ERR_STALE_CLIENTID: |
| 7276 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7277 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7278 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7279 | case -NFS4ERR_LEASE_MOVED: |
| 7280 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7281 | if (nfs4_async_handle_error(task, server, |
| 7282 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7283 | rpc_restart_call_prepare(task); |
| 7284 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7285 | } |
| 7286 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7287 | static void nfs4_release_lockowner_release(void *calldata) |
| 7288 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7289 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7290 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7291 | kfree(calldata); |
| 7292 | } |
| 7293 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7294 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7295 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7296 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7297 | .rpc_release = nfs4_release_lockowner_release, |
| 7298 | }; |
| 7299 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7300 | static void |
| 7301 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7302 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7303 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7304 | struct rpc_message msg = { |
| 7305 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7306 | }; |
| 7307 | |
| 7308 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7309 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7310 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7311 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7312 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7313 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7314 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7315 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7316 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7317 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7318 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7319 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7320 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7321 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7322 | 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] | 7323 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7324 | } |
| 7325 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7326 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7327 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7328 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7329 | struct dentry *unused, struct inode *inode, |
| 7330 | const char *key, const void *buf, |
| 7331 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7332 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7333 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7334 | } |
| 7335 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7336 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7337 | struct dentry *unused, struct inode *inode, |
| 7338 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7339 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7340 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7343 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7344 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7345 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7348 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7349 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7350 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7351 | struct dentry *unused, struct inode *inode, |
| 7352 | const char *key, const void *buf, |
| 7353 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7354 | { |
| 7355 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7356 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7357 | |
| 7358 | return -EOPNOTSUPP; |
| 7359 | } |
| 7360 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7361 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7362 | struct dentry *unused, struct inode *inode, |
| 7363 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7364 | { |
| 7365 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7366 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7367 | return -EOPNOTSUPP; |
| 7368 | } |
| 7369 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7370 | static ssize_t |
| 7371 | 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] | 7372 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7373 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7374 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7375 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7376 | len = security_inode_listsecurity(inode, list, list_len); |
| 7377 | if (list_len && len > list_len) |
| 7378 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7379 | } |
| 7380 | return len; |
| 7381 | } |
| 7382 | |
| 7383 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7384 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7385 | .get = nfs4_xattr_get_nfs4_label, |
| 7386 | .set = nfs4_xattr_set_nfs4_label, |
| 7387 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7388 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7389 | #else |
| 7390 | |
| 7391 | static ssize_t |
| 7392 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7393 | { |
| 7394 | return 0; |
| 7395 | } |
| 7396 | |
| 7397 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7398 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7399 | /* |
| 7400 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7401 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7402 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7403 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7404 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7405 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7406 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7407 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7408 | return; |
| 7409 | |
| 7410 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7411 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7412 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7413 | fattr->nlink = 2; |
| 7414 | } |
| 7415 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7416 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7417 | const struct qstr *name, |
| 7418 | struct nfs4_fs_locations *fs_locations, |
| 7419 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7420 | { |
| 7421 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7422 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7423 | struct nfs4_fs_locations_arg args = { |
| 7424 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7425 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7426 | .page = page, |
| 7427 | .bitmask = bitmask, |
| 7428 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7429 | struct nfs4_fs_locations_res res = { |
| 7430 | .fs_locations = fs_locations, |
| 7431 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7432 | struct rpc_message msg = { |
| 7433 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7434 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7435 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7436 | }; |
| 7437 | int status; |
| 7438 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7439 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7440 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7441 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7442 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7443 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7444 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7445 | * is not supported */ |
| 7446 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7447 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7448 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7449 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7450 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7451 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7452 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7453 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7454 | 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] | 7455 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7456 | return status; |
| 7457 | } |
| 7458 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7459 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7460 | const struct qstr *name, |
| 7461 | struct nfs4_fs_locations *fs_locations, |
| 7462 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7463 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7464 | struct nfs4_exception exception = { |
| 7465 | .interruptible = true, |
| 7466 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7467 | int err; |
| 7468 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7469 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7470 | fs_locations, page); |
| 7471 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7472 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7473 | &exception); |
| 7474 | } while (exception.retry); |
| 7475 | return err; |
| 7476 | } |
| 7477 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7478 | /* |
| 7479 | * This operation also signals the server that this client is |
| 7480 | * performing migration recovery. The server can stop returning |
| 7481 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7482 | * appended to this compound to identify the client ID which is |
| 7483 | * performing recovery. |
| 7484 | */ |
| 7485 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7486 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7487 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7488 | { |
| 7489 | struct nfs_server *server = NFS_SERVER(inode); |
| 7490 | struct rpc_clnt *clnt = server->client; |
| 7491 | u32 bitmask[2] = { |
| 7492 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7493 | }; |
| 7494 | struct nfs4_fs_locations_arg args = { |
| 7495 | .clientid = server->nfs_client->cl_clientid, |
| 7496 | .fh = NFS_FH(inode), |
| 7497 | .page = page, |
| 7498 | .bitmask = bitmask, |
| 7499 | .migration = 1, /* skip LOOKUP */ |
| 7500 | .renew = 1, /* append RENEW */ |
| 7501 | }; |
| 7502 | struct nfs4_fs_locations_res res = { |
| 7503 | .fs_locations = locations, |
| 7504 | .migration = 1, |
| 7505 | .renew = 1, |
| 7506 | }; |
| 7507 | struct rpc_message msg = { |
| 7508 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7509 | .rpc_argp = &args, |
| 7510 | .rpc_resp = &res, |
| 7511 | .rpc_cred = cred, |
| 7512 | }; |
| 7513 | unsigned long now = jiffies; |
| 7514 | int status; |
| 7515 | |
| 7516 | nfs_fattr_init(&locations->fattr); |
| 7517 | locations->server = server; |
| 7518 | locations->nlocations = 0; |
| 7519 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7520 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7521 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7522 | &args.seq_args, &res.seq_res); |
| 7523 | if (status) |
| 7524 | return status; |
| 7525 | |
| 7526 | renew_lease(server, now); |
| 7527 | return 0; |
| 7528 | } |
| 7529 | |
| 7530 | #ifdef CONFIG_NFS_V4_1 |
| 7531 | |
| 7532 | /* |
| 7533 | * This operation also signals the server that this client is |
| 7534 | * performing migration recovery. The server can stop asserting |
| 7535 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7536 | * performing this operation is identified in the SEQUENCE |
| 7537 | * operation in this compound. |
| 7538 | * |
| 7539 | * When the client supports GETATTR(fs_locations_info), it can |
| 7540 | * be plumbed in here. |
| 7541 | */ |
| 7542 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7543 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7544 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7545 | { |
| 7546 | struct nfs_server *server = NFS_SERVER(inode); |
| 7547 | struct rpc_clnt *clnt = server->client; |
| 7548 | u32 bitmask[2] = { |
| 7549 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7550 | }; |
| 7551 | struct nfs4_fs_locations_arg args = { |
| 7552 | .fh = NFS_FH(inode), |
| 7553 | .page = page, |
| 7554 | .bitmask = bitmask, |
| 7555 | .migration = 1, /* skip LOOKUP */ |
| 7556 | }; |
| 7557 | struct nfs4_fs_locations_res res = { |
| 7558 | .fs_locations = locations, |
| 7559 | .migration = 1, |
| 7560 | }; |
| 7561 | struct rpc_message msg = { |
| 7562 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7563 | .rpc_argp = &args, |
| 7564 | .rpc_resp = &res, |
| 7565 | .rpc_cred = cred, |
| 7566 | }; |
| 7567 | int status; |
| 7568 | |
| 7569 | nfs_fattr_init(&locations->fattr); |
| 7570 | locations->server = server; |
| 7571 | locations->nlocations = 0; |
| 7572 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7573 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7574 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7575 | &args.seq_args, &res.seq_res); |
| 7576 | if (status == NFS4_OK && |
| 7577 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7578 | status = -NFS4ERR_LEASE_MOVED; |
| 7579 | return status; |
| 7580 | } |
| 7581 | |
| 7582 | #endif /* CONFIG_NFS_V4_1 */ |
| 7583 | |
| 7584 | /** |
| 7585 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7586 | * @inode: inode on FSID that is migrating |
| 7587 | * @locations: result of query |
| 7588 | * @page: buffer |
| 7589 | * @cred: credential to use for this operation |
| 7590 | * |
| 7591 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7592 | * operation failed, or a negative errno if a local error occurred. |
| 7593 | * |
| 7594 | * On success, "locations" is filled in, but if the server has |
| 7595 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7596 | * asserted. |
| 7597 | * |
| 7598 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7599 | * from this client that require migration recovery. |
| 7600 | */ |
| 7601 | int nfs4_proc_get_locations(struct inode *inode, |
| 7602 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7603 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7604 | { |
| 7605 | struct nfs_server *server = NFS_SERVER(inode); |
| 7606 | struct nfs_client *clp = server->nfs_client; |
| 7607 | const struct nfs4_mig_recovery_ops *ops = |
| 7608 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7609 | struct nfs4_exception exception = { |
| 7610 | .interruptible = true, |
| 7611 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7612 | int status; |
| 7613 | |
| 7614 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7615 | (unsigned long long)server->fsid.major, |
| 7616 | (unsigned long long)server->fsid.minor, |
| 7617 | clp->cl_hostname); |
| 7618 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7619 | |
| 7620 | do { |
| 7621 | status = ops->get_locations(inode, locations, page, cred); |
| 7622 | if (status != -NFS4ERR_DELAY) |
| 7623 | break; |
| 7624 | nfs4_handle_exception(server, status, &exception); |
| 7625 | } while (exception.retry); |
| 7626 | return status; |
| 7627 | } |
| 7628 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7629 | /* |
| 7630 | * This operation also signals the server that this client is |
| 7631 | * performing "lease moved" recovery. The server can stop |
| 7632 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7633 | * is appended to this compound to identify the client ID which is |
| 7634 | * performing recovery. |
| 7635 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7636 | 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] | 7637 | { |
| 7638 | struct nfs_server *server = NFS_SERVER(inode); |
| 7639 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7640 | struct rpc_clnt *clnt = server->client; |
| 7641 | struct nfs4_fsid_present_arg args = { |
| 7642 | .fh = NFS_FH(inode), |
| 7643 | .clientid = clp->cl_clientid, |
| 7644 | .renew = 1, /* append RENEW */ |
| 7645 | }; |
| 7646 | struct nfs4_fsid_present_res res = { |
| 7647 | .renew = 1, |
| 7648 | }; |
| 7649 | struct rpc_message msg = { |
| 7650 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7651 | .rpc_argp = &args, |
| 7652 | .rpc_resp = &res, |
| 7653 | .rpc_cred = cred, |
| 7654 | }; |
| 7655 | unsigned long now = jiffies; |
| 7656 | int status; |
| 7657 | |
| 7658 | res.fh = nfs_alloc_fhandle(); |
| 7659 | if (res.fh == NULL) |
| 7660 | return -ENOMEM; |
| 7661 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7662 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7663 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7664 | &args.seq_args, &res.seq_res); |
| 7665 | nfs_free_fhandle(res.fh); |
| 7666 | if (status) |
| 7667 | return status; |
| 7668 | |
| 7669 | do_renew_lease(clp, now); |
| 7670 | return 0; |
| 7671 | } |
| 7672 | |
| 7673 | #ifdef CONFIG_NFS_V4_1 |
| 7674 | |
| 7675 | /* |
| 7676 | * This operation also signals the server that this client is |
| 7677 | * performing "lease moved" recovery. The server can stop asserting |
| 7678 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7679 | * this operation is identified in the SEQUENCE operation in this |
| 7680 | * compound. |
| 7681 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7682 | 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] | 7683 | { |
| 7684 | struct nfs_server *server = NFS_SERVER(inode); |
| 7685 | struct rpc_clnt *clnt = server->client; |
| 7686 | struct nfs4_fsid_present_arg args = { |
| 7687 | .fh = NFS_FH(inode), |
| 7688 | }; |
| 7689 | struct nfs4_fsid_present_res res = { |
| 7690 | }; |
| 7691 | struct rpc_message msg = { |
| 7692 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7693 | .rpc_argp = &args, |
| 7694 | .rpc_resp = &res, |
| 7695 | .rpc_cred = cred, |
| 7696 | }; |
| 7697 | int status; |
| 7698 | |
| 7699 | res.fh = nfs_alloc_fhandle(); |
| 7700 | if (res.fh == NULL) |
| 7701 | return -ENOMEM; |
| 7702 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7703 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7704 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7705 | &args.seq_args, &res.seq_res); |
| 7706 | nfs_free_fhandle(res.fh); |
| 7707 | if (status == NFS4_OK && |
| 7708 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7709 | status = -NFS4ERR_LEASE_MOVED; |
| 7710 | return status; |
| 7711 | } |
| 7712 | |
| 7713 | #endif /* CONFIG_NFS_V4_1 */ |
| 7714 | |
| 7715 | /** |
| 7716 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7717 | * @inode: inode on FSID to check |
| 7718 | * @cred: credential to use for this operation |
| 7719 | * |
| 7720 | * Server indicates whether the FSID is present, moved, or not |
| 7721 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7722 | * condition for this client ID. |
| 7723 | * |
| 7724 | * Returns NFS4_OK if the FSID is present on this server, |
| 7725 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7726 | * NFS4ERR code if some error occurred on the server, or a |
| 7727 | * negative errno if a local failure occurred. |
| 7728 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7729 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7730 | { |
| 7731 | struct nfs_server *server = NFS_SERVER(inode); |
| 7732 | struct nfs_client *clp = server->nfs_client; |
| 7733 | const struct nfs4_mig_recovery_ops *ops = |
| 7734 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7735 | struct nfs4_exception exception = { |
| 7736 | .interruptible = true, |
| 7737 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7738 | int status; |
| 7739 | |
| 7740 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7741 | (unsigned long long)server->fsid.major, |
| 7742 | (unsigned long long)server->fsid.minor, |
| 7743 | clp->cl_hostname); |
| 7744 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7745 | |
| 7746 | do { |
| 7747 | status = ops->fsid_present(inode, cred); |
| 7748 | if (status != -NFS4ERR_DELAY) |
| 7749 | break; |
| 7750 | nfs4_handle_exception(server, status, &exception); |
| 7751 | } while (exception.retry); |
| 7752 | return status; |
| 7753 | } |
| 7754 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 7755 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7756 | * If 'use_integrity' is true and the state managment nfs_client |
| 7757 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7758 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7759 | * Considerations sections. Otherwise, just use the user cred with the |
| 7760 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7761 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7762 | 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] | 7763 | { |
| 7764 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7765 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 7766 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7767 | struct nfs4_secinfo_arg args = { |
| 7768 | .dir_fh = NFS_FH(dir), |
| 7769 | .name = name, |
| 7770 | }; |
| 7771 | struct nfs4_secinfo_res res = { |
| 7772 | .flavors = flavors, |
| 7773 | }; |
| 7774 | struct rpc_message msg = { |
| 7775 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7776 | .rpc_argp = &args, |
| 7777 | .rpc_resp = &res, |
| 7778 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7779 | struct nfs4_call_sync_data data = { |
| 7780 | .seq_server = NFS_SERVER(dir), |
| 7781 | .seq_args = &args.seq_args, |
| 7782 | .seq_res = &res.seq_res, |
| 7783 | }; |
| 7784 | struct rpc_task_setup task_setup = { |
| 7785 | .rpc_client = clnt, |
| 7786 | .rpc_message = &msg, |
| 7787 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 7788 | .callback_data = &data, |
| 7789 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 7790 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7791 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7792 | |
| 7793 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7794 | clnt = clp->cl_rpcclient; |
| 7795 | task_setup.rpc_client = clnt; |
| 7796 | |
| 7797 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7798 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7799 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7800 | |
| 7801 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7802 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7803 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7804 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 7805 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7806 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7807 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7808 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7809 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7810 | return status; |
| 7811 | } |
| 7812 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7813 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7814 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7815 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7816 | struct nfs4_exception exception = { |
| 7817 | .interruptible = true, |
| 7818 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7819 | int err; |
| 7820 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7821 | err = -NFS4ERR_WRONGSEC; |
| 7822 | |
| 7823 | /* try to use integrity protection with machine cred */ |
| 7824 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7825 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7826 | |
| 7827 | /* |
| 7828 | * if unable to use integrity protection, or SECINFO with |
| 7829 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7830 | * disallowed by spec, but exists in deployed servers) use |
| 7831 | * the current filesystem's rpc_client and the user cred. |
| 7832 | */ |
| 7833 | if (err == -NFS4ERR_WRONGSEC) |
| 7834 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7835 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7836 | trace_nfs4_secinfo(dir, name, err); |
| 7837 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7838 | &exception); |
| 7839 | } while (exception.retry); |
| 7840 | return err; |
| 7841 | } |
| 7842 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7843 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7844 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7845 | * Check the exchange flags returned by the server for invalid flags, having |
| 7846 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7847 | * DS flags set. |
| 7848 | */ |
| 7849 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7850 | { |
| 7851 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7852 | goto out_inval; |
| 7853 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7854 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7855 | goto out_inval; |
| 7856 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7857 | goto out_inval; |
| 7858 | return NFS_OK; |
| 7859 | out_inval: |
| 7860 | return -NFS4ERR_INVAL; |
| 7861 | } |
| 7862 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7863 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7864 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7865 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7866 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7867 | if (a->server_scope_sz != b->server_scope_sz) |
| 7868 | return false; |
| 7869 | 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] | 7870 | } |
| 7871 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7872 | static void |
| 7873 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7874 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 7875 | struct nfs41_bind_conn_to_session_args *args = task->tk_msg.rpc_argp; |
| 7876 | struct nfs_client *clp = args->client; |
| 7877 | |
| 7878 | switch (task->tk_status) { |
| 7879 | case -NFS4ERR_BADSESSION: |
| 7880 | case -NFS4ERR_DEADSESSION: |
| 7881 | nfs4_schedule_session_recovery(clp->cl_session, |
| 7882 | task->tk_status); |
| 7883 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7884 | } |
| 7885 | |
| 7886 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7887 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7888 | }; |
| 7889 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7890 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7891 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7892 | * |
| 7893 | * The 4.1 client currently uses the same TCP connection for the |
| 7894 | * fore and backchannel. |
| 7895 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7896 | static |
| 7897 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7898 | struct rpc_xprt *xprt, |
| 7899 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7900 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7901 | { |
| 7902 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7903 | struct nfs41_bind_conn_to_session_args args = { |
| 7904 | .client = clp, |
| 7905 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7906 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7907 | struct nfs41_bind_conn_to_session_res res; |
| 7908 | struct rpc_message msg = { |
| 7909 | .rpc_proc = |
| 7910 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7911 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7912 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7913 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7914 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7915 | struct rpc_task_setup task_setup_data = { |
| 7916 | .rpc_client = clnt, |
| 7917 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7918 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7919 | .rpc_message = &msg, |
| 7920 | .flags = RPC_TASK_TIMEOUT, |
| 7921 | }; |
| 7922 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7923 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7924 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7925 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7926 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7927 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7928 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7929 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7930 | args.dir = NFS4_CDFC4_FORE; |
| 7931 | |
| 7932 | task = rpc_run_task(&task_setup_data); |
| 7933 | if (!IS_ERR(task)) { |
| 7934 | status = task->tk_status; |
| 7935 | rpc_put_task(task); |
| 7936 | } else |
| 7937 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7938 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7939 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7940 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7941 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7942 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7943 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7944 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7945 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7946 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7947 | __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.use_conn_in_rdma_mode != args.use_conn_in_rdma_mode) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7951 | dprintk("NFS: %s: Server returned RDMA mode = true\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 | } |
| 7955 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7956 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7957 | return status; |
| 7958 | } |
| 7959 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7960 | struct rpc_bind_conn_calldata { |
| 7961 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7962 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7963 | }; |
| 7964 | |
| 7965 | static int |
| 7966 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7967 | struct rpc_xprt *xprt, |
| 7968 | void *calldata) |
| 7969 | { |
| 7970 | struct rpc_bind_conn_calldata *p = calldata; |
| 7971 | |
| 7972 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7973 | } |
| 7974 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7975 | 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] | 7976 | { |
| 7977 | struct rpc_bind_conn_calldata data = { |
| 7978 | .clp = clp, |
| 7979 | .cred = cred, |
| 7980 | }; |
| 7981 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7982 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7983 | } |
| 7984 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7985 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7986 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7987 | * 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] | 7988 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7989 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7990 | .how = SP4_MACH_CRED, |
| 7991 | .enforce.u.words = { |
| 7992 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7993 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7994 | 1 << (OP_CREATE_SESSION - 32) | |
| 7995 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7996 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7997 | }, |
| 7998 | .allow.u.words = { |
| 7999 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8000 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8001 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8002 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8003 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8004 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8005 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8006 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8007 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8008 | 1 << (OP_FREE_STATEID - 32) | |
| 8009 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8010 | } |
| 8011 | }; |
| 8012 | |
| 8013 | /* |
| 8014 | * Select the state protection mode for client `clp' given the server results |
| 8015 | * from exchange_id in `sp'. |
| 8016 | * |
| 8017 | * Returns 0 on success, negative errno otherwise. |
| 8018 | */ |
| 8019 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8020 | struct nfs41_state_protection *sp) |
| 8021 | { |
| 8022 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8023 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8024 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8025 | 1 << (OP_CREATE_SESSION - 32) | |
| 8026 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8027 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8028 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8029 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8030 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8031 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8032 | |
| 8033 | if (sp->how == SP4_MACH_CRED) { |
| 8034 | /* Print state protect result */ |
| 8035 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8036 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8037 | if (test_bit(i, sp->enforce.u.longs)) |
| 8038 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8039 | if (test_bit(i, sp->allow.u.longs)) |
| 8040 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8041 | } |
| 8042 | |
| 8043 | /* make sure nothing is on enforce list that isn't supported */ |
| 8044 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8045 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8046 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8047 | ret = -EINVAL; |
| 8048 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8049 | } |
| 8050 | } |
| 8051 | |
| 8052 | /* |
| 8053 | * Minimal mode - state operations are allowed to use machine |
| 8054 | * credential. Note this already happens by default, so the |
| 8055 | * client doesn't have to do anything more than the negotiation. |
| 8056 | * |
| 8057 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8058 | * we're already using the machine cred for exchange_id |
| 8059 | * and will never use a different cred. |
| 8060 | */ |
| 8061 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8062 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8063 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8064 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8065 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8066 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8067 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8068 | } else { |
| 8069 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8070 | ret = -EINVAL; |
| 8071 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8072 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8073 | |
| 8074 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8075 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8076 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8077 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8078 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8079 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8080 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8081 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8082 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8083 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8084 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8085 | } |
| 8086 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8087 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8088 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8089 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8090 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8091 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8092 | |
| 8093 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8094 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8095 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8096 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8097 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8098 | |
| 8099 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8100 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8101 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8102 | } |
| 8103 | |
| 8104 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8105 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8106 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8107 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8108 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8109 | out: |
| 8110 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8111 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8112 | } |
| 8113 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8114 | struct nfs41_exchange_id_data { |
| 8115 | struct nfs41_exchange_id_res res; |
| 8116 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8117 | }; |
| 8118 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8119 | static void nfs4_exchange_id_release(void *data) |
| 8120 | { |
| 8121 | struct nfs41_exchange_id_data *cdata = |
| 8122 | (struct nfs41_exchange_id_data *)data; |
| 8123 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8124 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8125 | kfree(cdata->res.impl_id); |
| 8126 | kfree(cdata->res.server_scope); |
| 8127 | kfree(cdata->res.server_owner); |
| 8128 | kfree(cdata); |
| 8129 | } |
| 8130 | |
| 8131 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8132 | .rpc_release = nfs4_exchange_id_release, |
| 8133 | }; |
| 8134 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8135 | /* |
| 8136 | * _nfs4_proc_exchange_id() |
| 8137 | * |
| 8138 | * Wrapper for EXCHANGE_ID operation. |
| 8139 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8140 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8141 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8142 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8143 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8144 | struct rpc_message msg = { |
| 8145 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8146 | .rpc_cred = cred, |
| 8147 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8148 | struct rpc_task_setup task_setup_data = { |
| 8149 | .rpc_client = clp->cl_rpcclient, |
| 8150 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8151 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8152 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8153 | }; |
| 8154 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8155 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8156 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8157 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8158 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8159 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8160 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8161 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8162 | if (!calldata) |
| 8163 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8164 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8165 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8166 | |
| 8167 | status = nfs4_init_uniform_client_string(clp); |
| 8168 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8169 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8170 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8171 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8172 | GFP_NOFS); |
| 8173 | status = -ENOMEM; |
| 8174 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8175 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8176 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8177 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8178 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8179 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8180 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8181 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8182 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8183 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8184 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8185 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8186 | switch (sp4_how) { |
| 8187 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8188 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8189 | break; |
| 8190 | |
| 8191 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8192 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8193 | break; |
| 8194 | |
| 8195 | default: |
| 8196 | /* unsupported! */ |
| 8197 | WARN_ON_ONCE(1); |
| 8198 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8199 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8200 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8201 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8202 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8203 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8204 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8205 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8206 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8207 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8208 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8209 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8210 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8211 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8212 | #endif |
| 8213 | msg.rpc_argp = &calldata->args; |
| 8214 | msg.rpc_resp = &calldata->res; |
| 8215 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8216 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8217 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8218 | |
| 8219 | out_impl_id: |
| 8220 | kfree(calldata->res.impl_id); |
| 8221 | out_server_scope: |
| 8222 | kfree(calldata->res.server_scope); |
| 8223 | out_server_owner: |
| 8224 | kfree(calldata->res.server_owner); |
| 8225 | out_calldata: |
| 8226 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8227 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8228 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8229 | return ERR_PTR(status); |
| 8230 | } |
| 8231 | |
| 8232 | /* |
| 8233 | * _nfs4_proc_exchange_id() |
| 8234 | * |
| 8235 | * Wrapper for EXCHANGE_ID operation. |
| 8236 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8237 | 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] | 8238 | u32 sp4_how) |
| 8239 | { |
| 8240 | struct rpc_task *task; |
| 8241 | struct nfs41_exchange_id_args *argp; |
| 8242 | struct nfs41_exchange_id_res *resp; |
| 8243 | int status; |
| 8244 | |
| 8245 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8246 | if (IS_ERR(task)) |
| 8247 | return PTR_ERR(task); |
| 8248 | |
| 8249 | argp = task->tk_msg.rpc_argp; |
| 8250 | resp = task->tk_msg.rpc_resp; |
| 8251 | status = task->tk_status; |
| 8252 | if (status != 0) |
| 8253 | goto out; |
| 8254 | |
| 8255 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 8256 | if (status != 0) |
| 8257 | goto out; |
| 8258 | |
| 8259 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8260 | if (status != 0) |
| 8261 | goto out; |
| 8262 | |
| 8263 | clp->cl_clientid = resp->clientid; |
| 8264 | clp->cl_exchange_flags = resp->flags; |
| 8265 | clp->cl_seqid = resp->seqid; |
| 8266 | /* Client ID is not confirmed */ |
| 8267 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8268 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8269 | &clp->cl_session->session_state); |
| 8270 | |
| 8271 | if (clp->cl_serverscope != NULL && |
| 8272 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8273 | resp->server_scope)) { |
| 8274 | dprintk("%s: server_scope mismatch detected\n", |
| 8275 | __func__); |
| 8276 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8277 | } |
| 8278 | |
| 8279 | swap(clp->cl_serverowner, resp->server_owner); |
| 8280 | swap(clp->cl_serverscope, resp->server_scope); |
| 8281 | swap(clp->cl_implid, resp->impl_id); |
| 8282 | |
| 8283 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8284 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8285 | sizeof(clp->cl_confirm.data)); |
| 8286 | out: |
| 8287 | trace_nfs4_exchange_id(clp, status); |
| 8288 | rpc_put_task(task); |
| 8289 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8290 | } |
| 8291 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8292 | /* |
| 8293 | * nfs4_proc_exchange_id() |
| 8294 | * |
| 8295 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8296 | * |
| 8297 | * Since the clientid has expired, all compounds using sessions |
| 8298 | * associated with the stale clientid will be returning |
| 8299 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8300 | * be in some phase of session reset. |
| 8301 | * |
| 8302 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8303 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8304 | 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] | 8305 | { |
| 8306 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8307 | int status; |
| 8308 | |
| 8309 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8310 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8311 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8312 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8313 | if (!status) |
| 8314 | return 0; |
| 8315 | } |
| 8316 | |
| 8317 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8318 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8319 | } |
| 8320 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8321 | /** |
| 8322 | * nfs4_test_session_trunk |
| 8323 | * |
| 8324 | * This is an add_xprt_test() test function called from |
| 8325 | * rpc_clnt_setup_test_and_add_xprt. |
| 8326 | * |
| 8327 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8328 | * and is dereferrenced in nfs4_exchange_id_release |
| 8329 | * |
| 8330 | * Upon success, add the new transport to the rpc_clnt |
| 8331 | * |
| 8332 | * @clnt: struct rpc_clnt to get new transport |
| 8333 | * @xprt: the rpc_xprt to test |
| 8334 | * @data: call data for _nfs4_proc_exchange_id. |
| 8335 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8336 | 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] | 8337 | void *data) |
| 8338 | { |
| 8339 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8340 | struct rpc_task *task; |
| 8341 | int status; |
| 8342 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8343 | u32 sp4_how; |
| 8344 | |
| 8345 | dprintk("--> %s try %s\n", __func__, |
| 8346 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8347 | |
| 8348 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8349 | |
| 8350 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8351 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8352 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8353 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8354 | |
| 8355 | status = task->tk_status; |
| 8356 | if (status == 0) |
| 8357 | status = nfs4_detect_session_trunking(adata->clp, |
| 8358 | task->tk_msg.rpc_resp, xprt); |
| 8359 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8360 | if (status == 0) |
| 8361 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8362 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8363 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8364 | } |
| 8365 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8366 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8367 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8368 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8369 | { |
| 8370 | struct rpc_message msg = { |
| 8371 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8372 | .rpc_argp = clp, |
| 8373 | .rpc_cred = cred, |
| 8374 | }; |
| 8375 | int status; |
| 8376 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8377 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8378 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8379 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8380 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8381 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8382 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8383 | return status; |
| 8384 | } |
| 8385 | |
| 8386 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8387 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8388 | { |
| 8389 | unsigned int loop; |
| 8390 | int ret; |
| 8391 | |
| 8392 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8393 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8394 | switch (ret) { |
| 8395 | case -NFS4ERR_DELAY: |
| 8396 | case -NFS4ERR_CLIENTID_BUSY: |
| 8397 | ssleep(1); |
| 8398 | break; |
| 8399 | default: |
| 8400 | return ret; |
| 8401 | } |
| 8402 | } |
| 8403 | return 0; |
| 8404 | } |
| 8405 | |
| 8406 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8407 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8408 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8409 | int ret = 0; |
| 8410 | |
| 8411 | if (clp->cl_mvops->minor_version < 1) |
| 8412 | goto out; |
| 8413 | if (clp->cl_exchange_flags == 0) |
| 8414 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8415 | if (clp->cl_preserve_clid) |
| 8416 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8417 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8418 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8419 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8420 | switch (ret) { |
| 8421 | case 0: |
| 8422 | case -NFS4ERR_STALE_CLIENTID: |
| 8423 | clp->cl_exchange_flags = 0; |
| 8424 | } |
| 8425 | out: |
| 8426 | return ret; |
| 8427 | } |
| 8428 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8429 | #endif /* CONFIG_NFS_V4_1 */ |
| 8430 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8431 | struct nfs4_get_lease_time_data { |
| 8432 | struct nfs4_get_lease_time_args *args; |
| 8433 | struct nfs4_get_lease_time_res *res; |
| 8434 | struct nfs_client *clp; |
| 8435 | }; |
| 8436 | |
| 8437 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8438 | void *calldata) |
| 8439 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8440 | struct nfs4_get_lease_time_data *data = |
| 8441 | (struct nfs4_get_lease_time_data *)calldata; |
| 8442 | |
| 8443 | dprintk("--> %s\n", __func__); |
| 8444 | /* just setup sequence, do not trigger session recovery |
| 8445 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8446 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8447 | &data->args->la_seq_args, |
| 8448 | &data->res->lr_seq_res, |
| 8449 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8450 | dprintk("<-- %s\n", __func__); |
| 8451 | } |
| 8452 | |
| 8453 | /* |
| 8454 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8455 | * from sequence operation or clientid errors. |
| 8456 | */ |
| 8457 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8458 | { |
| 8459 | struct nfs4_get_lease_time_data *data = |
| 8460 | (struct nfs4_get_lease_time_data *)calldata; |
| 8461 | |
| 8462 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8463 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8464 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8465 | switch (task->tk_status) { |
| 8466 | case -NFS4ERR_DELAY: |
| 8467 | case -NFS4ERR_GRACE: |
| 8468 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8469 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8470 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8471 | /* fall through */ |
| 8472 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8473 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8474 | return; |
| 8475 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8476 | dprintk("<-- %s\n", __func__); |
| 8477 | } |
| 8478 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8479 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8480 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8481 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8482 | }; |
| 8483 | |
| 8484 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8485 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8486 | struct nfs4_get_lease_time_args args; |
| 8487 | struct nfs4_get_lease_time_res res = { |
| 8488 | .lr_fsinfo = fsinfo, |
| 8489 | }; |
| 8490 | struct nfs4_get_lease_time_data data = { |
| 8491 | .args = &args, |
| 8492 | .res = &res, |
| 8493 | .clp = clp, |
| 8494 | }; |
| 8495 | struct rpc_message msg = { |
| 8496 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8497 | .rpc_argp = &args, |
| 8498 | .rpc_resp = &res, |
| 8499 | }; |
| 8500 | struct rpc_task_setup task_setup = { |
| 8501 | .rpc_client = clp->cl_rpcclient, |
| 8502 | .rpc_message = &msg, |
| 8503 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8504 | .callback_data = &data, |
| 8505 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8506 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8507 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8508 | 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] | 8509 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8510 | } |
| 8511 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8512 | #ifdef CONFIG_NFS_V4_1 |
| 8513 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8514 | /* |
| 8515 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8516 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8517 | * use them. |
| 8518 | * |
| 8519 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8520 | * always set csa_cachethis to FALSE because the current implementation |
| 8521 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8522 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8523 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8524 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8525 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8526 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8527 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8528 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8529 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8530 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8531 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8532 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8533 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8534 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8535 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8536 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8537 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8538 | |
| 8539 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8540 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8541 | __func__, |
| 8542 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8543 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8544 | |
| 8545 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8546 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8547 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8548 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8549 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8550 | 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] | 8551 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8552 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8553 | |
| 8554 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8555 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8556 | __func__, |
| 8557 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8558 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8559 | args->bc_attrs.max_reqs); |
| 8560 | } |
| 8561 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8562 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8563 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8564 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8565 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8566 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8567 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8568 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8569 | return -EINVAL; |
| 8570 | /* |
| 8571 | * Our requested max_ops is the minimum we need; we're not |
| 8572 | * prepared to break up compounds into smaller pieces than that. |
| 8573 | * So, no point even trying to continue if the server won't |
| 8574 | * cooperate: |
| 8575 | */ |
| 8576 | if (rcvd->max_ops < sent->max_ops) |
| 8577 | return -EINVAL; |
| 8578 | if (rcvd->max_reqs == 0) |
| 8579 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8580 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8581 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8582 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8583 | } |
| 8584 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8585 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8586 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8587 | { |
| 8588 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8589 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8590 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8591 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8592 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8593 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8594 | return -EINVAL; |
| 8595 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8596 | return -EINVAL; |
| 8597 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8598 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8599 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8600 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8601 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8602 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8603 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8604 | return 0; |
| 8605 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8606 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8607 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8608 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8609 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8610 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8611 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8612 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8613 | if (ret) |
| 8614 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8615 | return nfs4_verify_back_channel_attrs(args, res); |
| 8616 | } |
| 8617 | |
| 8618 | static void nfs4_update_session(struct nfs4_session *session, |
| 8619 | struct nfs41_create_session_res *res) |
| 8620 | { |
| 8621 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8622 | /* Mark client id and session as being confirmed */ |
| 8623 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8624 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8625 | session->flags = res->flags; |
| 8626 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8627 | if (res->flags & SESSION4_BACK_CHAN) |
| 8628 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8629 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8630 | } |
| 8631 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8632 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8633 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8634 | { |
| 8635 | struct nfs4_session *session = clp->cl_session; |
| 8636 | struct nfs41_create_session_args args = { |
| 8637 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8638 | .clientid = clp->cl_clientid, |
| 8639 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8640 | .cb_program = NFS4_CALLBACK, |
| 8641 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8642 | struct nfs41_create_session_res res; |
| 8643 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8644 | struct rpc_message msg = { |
| 8645 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8646 | .rpc_argp = &args, |
| 8647 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8648 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8649 | }; |
| 8650 | int status; |
| 8651 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8652 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8653 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8654 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8655 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8656 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8657 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8658 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8659 | switch (status) { |
| 8660 | case -NFS4ERR_STALE_CLIENTID: |
| 8661 | case -NFS4ERR_DELAY: |
| 8662 | case -ETIMEDOUT: |
| 8663 | case -EACCES: |
| 8664 | case -EAGAIN: |
| 8665 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 8666 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8667 | |
| 8668 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8669 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8670 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8671 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8672 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8673 | if (status) |
| 8674 | goto out; |
| 8675 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8676 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8677 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8678 | return status; |
| 8679 | } |
| 8680 | |
| 8681 | /* |
| 8682 | * Issues a CREATE_SESSION operation to the server. |
| 8683 | * It is the responsibility of the caller to verify the session is |
| 8684 | * expired before calling this routine. |
| 8685 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8686 | 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] | 8687 | { |
| 8688 | int status; |
| 8689 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8690 | struct nfs4_session *session = clp->cl_session; |
| 8691 | |
| 8692 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8693 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8694 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8695 | if (status) |
| 8696 | goto out; |
| 8697 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8698 | /* Init or reset the session slot tables */ |
| 8699 | status = nfs4_setup_session_slot_tables(session); |
| 8700 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8701 | if (status) |
| 8702 | goto out; |
| 8703 | |
| 8704 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8705 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8706 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8707 | out: |
| 8708 | dprintk("<-- %s\n", __func__); |
| 8709 | return status; |
| 8710 | } |
| 8711 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8712 | /* |
| 8713 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8714 | * The caller must serialize access to this routine. |
| 8715 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8716 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8717 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8718 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8719 | struct rpc_message msg = { |
| 8720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8721 | .rpc_argp = session, |
| 8722 | .rpc_cred = cred, |
| 8723 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8724 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8725 | |
| 8726 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8727 | |
| 8728 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8729 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8730 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8731 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8732 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8733 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8734 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8735 | |
| 8736 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8737 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8738 | "Session has been destroyed regardless...\n", status); |
| 8739 | |
| 8740 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8741 | return status; |
| 8742 | } |
| 8743 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8744 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8745 | * Renew the cl_session lease. |
| 8746 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8747 | struct nfs4_sequence_data { |
| 8748 | struct nfs_client *clp; |
| 8749 | struct nfs4_sequence_args args; |
| 8750 | struct nfs4_sequence_res res; |
| 8751 | }; |
| 8752 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8753 | static void nfs41_sequence_release(void *data) |
| 8754 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8755 | struct nfs4_sequence_data *calldata = data; |
| 8756 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8757 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8758 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8759 | nfs4_schedule_state_renewal(clp); |
| 8760 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8761 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8762 | } |
| 8763 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8764 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8765 | { |
| 8766 | switch(task->tk_status) { |
| 8767 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8768 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8769 | return -EAGAIN; |
| 8770 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8771 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8772 | } |
| 8773 | return 0; |
| 8774 | } |
| 8775 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8776 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8777 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8778 | struct nfs4_sequence_data *calldata = data; |
| 8779 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8780 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8781 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8782 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8783 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8784 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8785 | if (task->tk_status < 0) { |
| 8786 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8787 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8788 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8789 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8790 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8791 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8792 | return; |
| 8793 | } |
| 8794 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8795 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8796 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8797 | dprintk("<-- %s\n", __func__); |
| 8798 | } |
| 8799 | |
| 8800 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8801 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8802 | struct nfs4_sequence_data *calldata = data; |
| 8803 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8804 | struct nfs4_sequence_args *args; |
| 8805 | struct nfs4_sequence_res *res; |
| 8806 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8807 | args = task->tk_msg.rpc_argp; |
| 8808 | res = task->tk_msg.rpc_resp; |
| 8809 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8810 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8811 | } |
| 8812 | |
| 8813 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8814 | .rpc_call_done = nfs41_sequence_call_done, |
| 8815 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8816 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8817 | }; |
| 8818 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8819 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8820 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8821 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8822 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8823 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8824 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8825 | struct rpc_message msg = { |
| 8826 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8827 | .rpc_cred = cred, |
| 8828 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8829 | struct rpc_task_setup task_setup_data = { |
| 8830 | .rpc_client = clp->cl_rpcclient, |
| 8831 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8832 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8833 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8834 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8835 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8836 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8837 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8838 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8839 | goto out_err; |
| 8840 | |
| 8841 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8842 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8843 | if (calldata == NULL) |
| 8844 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8845 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8846 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8847 | msg.rpc_argp = &calldata->args; |
| 8848 | msg.rpc_resp = &calldata->res; |
| 8849 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8850 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8851 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8852 | ret = rpc_run_task(&task_setup_data); |
| 8853 | if (IS_ERR(ret)) |
| 8854 | goto out_err; |
| 8855 | return ret; |
| 8856 | out_put_clp: |
| 8857 | nfs_put_client(clp); |
| 8858 | out_err: |
| 8859 | nfs41_release_slot(slot); |
| 8860 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8861 | } |
| 8862 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8863 | 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] | 8864 | { |
| 8865 | struct rpc_task *task; |
| 8866 | int ret = 0; |
| 8867 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8868 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8869 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8870 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8871 | if (IS_ERR(task)) |
| 8872 | ret = PTR_ERR(task); |
| 8873 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8874 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8875 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8876 | return ret; |
| 8877 | } |
| 8878 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8879 | 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] | 8880 | { |
| 8881 | struct rpc_task *task; |
| 8882 | int ret; |
| 8883 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8884 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8885 | if (IS_ERR(task)) { |
| 8886 | ret = PTR_ERR(task); |
| 8887 | goto out; |
| 8888 | } |
| 8889 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8890 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8891 | ret = task->tk_status; |
| 8892 | rpc_put_task(task); |
| 8893 | out: |
| 8894 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8895 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8896 | } |
| 8897 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8898 | struct nfs4_reclaim_complete_data { |
| 8899 | struct nfs_client *clp; |
| 8900 | struct nfs41_reclaim_complete_args arg; |
| 8901 | struct nfs41_reclaim_complete_res res; |
| 8902 | }; |
| 8903 | |
| 8904 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8905 | { |
| 8906 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8907 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8908 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8909 | &calldata->arg.seq_args, |
| 8910 | &calldata->res.seq_res, |
| 8911 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8912 | } |
| 8913 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8914 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8915 | { |
| 8916 | switch(task->tk_status) { |
| 8917 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8918 | wake_up_all(&clp->cl_lock_waitq); |
| 8919 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8920 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8921 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8922 | break; |
| 8923 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8924 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8925 | /* fall through */ |
| 8926 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8927 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8928 | case -NFS4ERR_BADSESSION: |
| 8929 | case -NFS4ERR_DEADSESSION: |
| 8930 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8931 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8932 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8933 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8934 | } |
| 8935 | return 0; |
| 8936 | } |
| 8937 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8938 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8939 | { |
| 8940 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8941 | struct nfs_client *clp = calldata->clp; |
| 8942 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8943 | |
| 8944 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8945 | if (!nfs41_sequence_done(task, res)) |
| 8946 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8947 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8948 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8949 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8950 | rpc_restart_call_prepare(task); |
| 8951 | return; |
| 8952 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8953 | dprintk("<-- %s\n", __func__); |
| 8954 | } |
| 8955 | |
| 8956 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8957 | { |
| 8958 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8959 | |
| 8960 | kfree(calldata); |
| 8961 | } |
| 8962 | |
| 8963 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8964 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8965 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8966 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8967 | }; |
| 8968 | |
| 8969 | /* |
| 8970 | * Issue a global reclaim complete. |
| 8971 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8972 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8973 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8974 | { |
| 8975 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8976 | struct rpc_message msg = { |
| 8977 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8978 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8979 | }; |
| 8980 | struct rpc_task_setup task_setup_data = { |
| 8981 | .rpc_client = clp->cl_rpcclient, |
| 8982 | .rpc_message = &msg, |
| 8983 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 8984 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8985 | }; |
| 8986 | int status = -ENOMEM; |
| 8987 | |
| 8988 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8989 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8990 | if (calldata == NULL) |
| 8991 | goto out; |
| 8992 | calldata->clp = clp; |
| 8993 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8994 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8995 | 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] | 8996 | msg.rpc_argp = &calldata->arg; |
| 8997 | msg.rpc_resp = &calldata->res; |
| 8998 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 8999 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9000 | out: |
| 9001 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9002 | return status; |
| 9003 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9004 | |
| 9005 | static void |
| 9006 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9007 | { |
| 9008 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9009 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9010 | |
| 9011 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9012 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9013 | &lgp->res.seq_res, task); |
| 9014 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9015 | } |
| 9016 | |
| 9017 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9018 | { |
| 9019 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9020 | |
| 9021 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9022 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9023 | dprintk("<-- %s\n", __func__); |
| 9024 | } |
| 9025 | |
| 9026 | static int |
| 9027 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9028 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9029 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9030 | struct inode *inode = lgp->args.inode; |
| 9031 | struct nfs_server *server = NFS_SERVER(inode); |
| 9032 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9033 | int nfs4err = task->tk_status; |
| 9034 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9035 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9036 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9037 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9038 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9039 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9040 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9041 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9042 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9043 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9044 | |
| 9045 | /* |
| 9046 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9047 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9048 | * retry go inband. |
| 9049 | */ |
| 9050 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9051 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9052 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9053 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9054 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9055 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9056 | */ |
| 9057 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9058 | status = -EOVERFLOW; |
| 9059 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9060 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9061 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9062 | * (or clients) writing to the same RAID stripe except when |
| 9063 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9064 | * |
| 9065 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9066 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9067 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9068 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9069 | if (lgp->args.minlength == 0) { |
| 9070 | status = -EOVERFLOW; |
| 9071 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9072 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9073 | status = -EBUSY; |
| 9074 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9075 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9076 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9077 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9078 | case -NFS4ERR_DELEG_REVOKED: |
| 9079 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9080 | case -NFS4ERR_EXPIRED: |
| 9081 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9082 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9083 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9084 | lo = NFS_I(inode)->layout; |
| 9085 | /* If the open stateid was bad, then recover it. */ |
| 9086 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9087 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9088 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9089 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9090 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9091 | break; |
| 9092 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9093 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9094 | /* |
| 9095 | * Mark the bad layout state as invalid, then retry |
| 9096 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9097 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9098 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9099 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9100 | pnfs_free_lseg_list(&head); |
| 9101 | status = -EAGAIN; |
| 9102 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9103 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9104 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9105 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9106 | if (!status) { |
| 9107 | if (exception->retry) |
| 9108 | status = -EAGAIN; |
| 9109 | else |
| 9110 | status = err; |
| 9111 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9112 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9113 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9114 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9115 | } |
| 9116 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9117 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9118 | { |
| 9119 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9120 | return nfs_page_array_len(0, max_resp_sz); |
| 9121 | } |
| 9122 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9123 | static void nfs4_layoutget_release(void *calldata) |
| 9124 | { |
| 9125 | struct nfs4_layoutget *lgp = calldata; |
| 9126 | |
| 9127 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9128 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9129 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9130 | dprintk("<-- %s\n", __func__); |
| 9131 | } |
| 9132 | |
| 9133 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9134 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9135 | .rpc_call_done = nfs4_layoutget_done, |
| 9136 | .rpc_release = nfs4_layoutget_release, |
| 9137 | }; |
| 9138 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9139 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9140 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9141 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9142 | struct inode *inode = lgp->args.inode; |
| 9143 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9144 | struct rpc_task *task; |
| 9145 | struct rpc_message msg = { |
| 9146 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9147 | .rpc_argp = &lgp->args, |
| 9148 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9149 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9150 | }; |
| 9151 | struct rpc_task_setup task_setup_data = { |
| 9152 | .rpc_client = server->client, |
| 9153 | .rpc_message = &msg, |
| 9154 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9155 | .callback_data = lgp, |
| 9156 | .flags = RPC_TASK_ASYNC, |
| 9157 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9158 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9159 | struct nfs4_exception exception = { |
| 9160 | .inode = inode, |
| 9161 | .timeout = *timeout, |
| 9162 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9163 | int status = 0; |
| 9164 | |
| 9165 | dprintk("--> %s\n", __func__); |
| 9166 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9167 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9168 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9169 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9170 | 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] | 9171 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9172 | task = rpc_run_task(&task_setup_data); |
| 9173 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9174 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9175 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9176 | if (status != 0) |
| 9177 | goto out; |
| 9178 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9179 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9180 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9181 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9182 | } else if (lgp->res.layoutp->len == 0) { |
| 9183 | status = -EAGAIN; |
| 9184 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9185 | } else |
| 9186 | lseg = pnfs_layout_process(lgp); |
| 9187 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9188 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9189 | &lgp->args.range, |
| 9190 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9191 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9192 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9193 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9194 | rpc_put_task(task); |
| 9195 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9196 | if (status) |
| 9197 | return ERR_PTR(status); |
| 9198 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9199 | } |
| 9200 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9201 | static void |
| 9202 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9203 | { |
| 9204 | struct nfs4_layoutreturn *lrp = calldata; |
| 9205 | |
| 9206 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9207 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9208 | &lrp->args.seq_args, |
| 9209 | &lrp->res.seq_res, |
| 9210 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9211 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9212 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9213 | } |
| 9214 | |
| 9215 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9216 | { |
| 9217 | struct nfs4_layoutreturn *lrp = calldata; |
| 9218 | struct nfs_server *server; |
| 9219 | |
| 9220 | dprintk("--> %s\n", __func__); |
| 9221 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9222 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9223 | return; |
| 9224 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9225 | /* |
| 9226 | * Was there an RPC level error? Assume the call succeeded, |
| 9227 | * and that we need to release the layout |
| 9228 | */ |
| 9229 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9230 | lrp->res.lrs_present = 0; |
| 9231 | return; |
| 9232 | } |
| 9233 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9234 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9235 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9236 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9237 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9238 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9239 | lrp->args.inode)) |
| 9240 | goto out_restart; |
| 9241 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9242 | default: |
| 9243 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9244 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9245 | case 0: |
| 9246 | break; |
| 9247 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9248 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9249 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9250 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9251 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9252 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9253 | return; |
| 9254 | out_restart: |
| 9255 | task->tk_status = 0; |
| 9256 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9257 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9258 | } |
| 9259 | |
| 9260 | static void nfs4_layoutreturn_release(void *calldata) |
| 9261 | { |
| 9262 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9263 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9264 | |
| 9265 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9266 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9267 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9268 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9269 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9270 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9271 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9272 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9273 | kfree(calldata); |
| 9274 | dprintk("<-- %s\n", __func__); |
| 9275 | } |
| 9276 | |
| 9277 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9278 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9279 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9280 | .rpc_release = nfs4_layoutreturn_release, |
| 9281 | }; |
| 9282 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9283 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9284 | { |
| 9285 | struct rpc_task *task; |
| 9286 | struct rpc_message msg = { |
| 9287 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9288 | .rpc_argp = &lrp->args, |
| 9289 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9290 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9291 | }; |
| 9292 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9293 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9294 | .rpc_message = &msg, |
| 9295 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9296 | .callback_data = lrp, |
| 9297 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9298 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9299 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9300 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9301 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9302 | &task_setup_data.rpc_client, &msg); |
| 9303 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9304 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9305 | if (!sync) { |
| 9306 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9307 | if (!lrp->inode) { |
| 9308 | nfs4_layoutreturn_release(lrp); |
| 9309 | return -EAGAIN; |
| 9310 | } |
| 9311 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9312 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9313 | 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] | 9314 | task = rpc_run_task(&task_setup_data); |
| 9315 | if (IS_ERR(task)) |
| 9316 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9317 | if (sync) |
| 9318 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9319 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9320 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9321 | rpc_put_task(task); |
| 9322 | return status; |
| 9323 | } |
| 9324 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9325 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9326 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9327 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9328 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9329 | { |
| 9330 | struct nfs4_getdeviceinfo_args args = { |
| 9331 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9332 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9333 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9334 | }; |
| 9335 | struct nfs4_getdeviceinfo_res res = { |
| 9336 | .pdev = pdev, |
| 9337 | }; |
| 9338 | struct rpc_message msg = { |
| 9339 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9340 | .rpc_argp = &args, |
| 9341 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9342 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9343 | }; |
| 9344 | int status; |
| 9345 | |
| 9346 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9347 | 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] | 9348 | if (res.notification & ~args.notify_types) |
| 9349 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9350 | if (res.notification != args.notify_types) |
| 9351 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9352 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9353 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9354 | |
| 9355 | return status; |
| 9356 | } |
| 9357 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9358 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9359 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9360 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9361 | { |
| 9362 | struct nfs4_exception exception = { }; |
| 9363 | int err; |
| 9364 | |
| 9365 | do { |
| 9366 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9367 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9368 | &exception); |
| 9369 | } while (exception.retry); |
| 9370 | return err; |
| 9371 | } |
| 9372 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9373 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9374 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9375 | { |
| 9376 | struct nfs4_layoutcommit_data *data = calldata; |
| 9377 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9378 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9379 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9380 | &data->args.seq_args, |
| 9381 | &data->res.seq_res, |
| 9382 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9383 | } |
| 9384 | |
| 9385 | static void |
| 9386 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9387 | { |
| 9388 | struct nfs4_layoutcommit_data *data = calldata; |
| 9389 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9390 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9391 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9392 | return; |
| 9393 | |
| 9394 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9395 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9396 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9397 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9398 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9399 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9400 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9401 | break; |
| 9402 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9403 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9404 | rpc_restart_call_prepare(task); |
| 9405 | return; |
| 9406 | } |
| 9407 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9408 | } |
| 9409 | |
| 9410 | static void nfs4_layoutcommit_release(void *calldata) |
| 9411 | { |
| 9412 | struct nfs4_layoutcommit_data *data = calldata; |
| 9413 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9414 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9415 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9416 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9417 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9418 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9419 | kfree(data); |
| 9420 | } |
| 9421 | |
| 9422 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9423 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9424 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9425 | .rpc_release = nfs4_layoutcommit_release, |
| 9426 | }; |
| 9427 | |
| 9428 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9429 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9430 | { |
| 9431 | struct rpc_message msg = { |
| 9432 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9433 | .rpc_argp = &data->args, |
| 9434 | .rpc_resp = &data->res, |
| 9435 | .rpc_cred = data->cred, |
| 9436 | }; |
| 9437 | struct rpc_task_setup task_setup_data = { |
| 9438 | .task = &data->task, |
| 9439 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9440 | .rpc_message = &msg, |
| 9441 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9442 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9443 | }; |
| 9444 | struct rpc_task *task; |
| 9445 | int status = 0; |
| 9446 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9447 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9448 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9449 | data->args.lastbytewritten, |
| 9450 | data->args.inode->i_ino); |
| 9451 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9452 | if (!sync) { |
| 9453 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9454 | if (data->inode == NULL) { |
| 9455 | nfs4_layoutcommit_release(data); |
| 9456 | return -EAGAIN; |
| 9457 | } |
| 9458 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9459 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9460 | 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] | 9461 | task = rpc_run_task(&task_setup_data); |
| 9462 | if (IS_ERR(task)) |
| 9463 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9464 | if (sync) |
| 9465 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9466 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9467 | dprintk("%s: status %d\n", __func__, status); |
| 9468 | rpc_put_task(task); |
| 9469 | return status; |
| 9470 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9471 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9472 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9473 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9474 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9475 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9476 | static int |
| 9477 | _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] | 9478 | struct nfs_fsinfo *info, |
| 9479 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9480 | { |
| 9481 | struct nfs41_secinfo_no_name_args args = { |
| 9482 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9483 | }; |
| 9484 | struct nfs4_secinfo_res res = { |
| 9485 | .flavors = flavors, |
| 9486 | }; |
| 9487 | struct rpc_message msg = { |
| 9488 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9489 | .rpc_argp = &args, |
| 9490 | .rpc_resp = &res, |
| 9491 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9492 | struct rpc_clnt *clnt = server->client; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9493 | struct nfs4_call_sync_data data = { |
| 9494 | .seq_server = server, |
| 9495 | .seq_args = &args.seq_args, |
| 9496 | .seq_res = &res.seq_res, |
| 9497 | }; |
| 9498 | struct rpc_task_setup task_setup = { |
| 9499 | .rpc_client = server->client, |
| 9500 | .rpc_message = &msg, |
| 9501 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9502 | .callback_data = &data, |
| 9503 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9504 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9505 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9506 | int status; |
| 9507 | |
| 9508 | if (use_integrity) { |
| 9509 | clnt = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9510 | task_setup.rpc_client = clnt; |
| 9511 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9512 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9513 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9514 | } |
| 9515 | |
| 9516 | dprintk("--> %s\n", __func__); |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9517 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9518 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9519 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9520 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9521 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9522 | |
| 9523 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9524 | } |
| 9525 | |
| 9526 | static int |
| 9527 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9528 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9529 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9530 | struct nfs4_exception exception = { |
| 9531 | .interruptible = true, |
| 9532 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9533 | int err; |
| 9534 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9535 | /* first try using integrity protection */ |
| 9536 | err = -NFS4ERR_WRONGSEC; |
| 9537 | |
| 9538 | /* try to use integrity protection with machine cred */ |
| 9539 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9540 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9541 | flavors, true); |
| 9542 | |
| 9543 | /* |
| 9544 | * if unable to use integrity protection, or SECINFO with |
| 9545 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9546 | * disallowed by spec, but exists in deployed servers) use |
| 9547 | * the current filesystem's rpc_client and the user cred. |
| 9548 | */ |
| 9549 | if (err == -NFS4ERR_WRONGSEC) |
| 9550 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9551 | flavors, false); |
| 9552 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9553 | switch (err) { |
| 9554 | case 0: |
| 9555 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9556 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9557 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9558 | default: |
| 9559 | err = nfs4_handle_exception(server, err, &exception); |
| 9560 | } |
| 9561 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9562 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9563 | return err; |
| 9564 | } |
| 9565 | |
| 9566 | static int |
| 9567 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9568 | struct nfs_fsinfo *info) |
| 9569 | { |
| 9570 | int err; |
| 9571 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9572 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9573 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9574 | struct nfs4_secinfo4 *secinfo; |
| 9575 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9576 | |
| 9577 | page = alloc_page(GFP_KERNEL); |
| 9578 | if (!page) { |
| 9579 | err = -ENOMEM; |
| 9580 | goto out; |
| 9581 | } |
| 9582 | |
| 9583 | flavors = page_address(page); |
| 9584 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9585 | |
| 9586 | /* |
| 9587 | * Fall back on "guess and check" method if |
| 9588 | * the server doesn't support SECINFO_NO_NAME |
| 9589 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9590 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9591 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9592 | goto out_freepage; |
| 9593 | } |
| 9594 | if (err) |
| 9595 | goto out_freepage; |
| 9596 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9597 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9598 | secinfo = &flavors->flavors[i]; |
| 9599 | |
| 9600 | switch (secinfo->flavor) { |
| 9601 | case RPC_AUTH_NULL: |
| 9602 | case RPC_AUTH_UNIX: |
| 9603 | case RPC_AUTH_GSS: |
| 9604 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9605 | &secinfo->flavor_info); |
| 9606 | break; |
| 9607 | default: |
| 9608 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9609 | break; |
| 9610 | } |
| 9611 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9612 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9613 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9614 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9615 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9616 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9617 | info, flavor); |
| 9618 | if (!err) |
| 9619 | break; |
| 9620 | } |
| 9621 | } |
| 9622 | |
| 9623 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9624 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9625 | |
| 9626 | out_freepage: |
| 9627 | put_page(page); |
| 9628 | if (err == -EACCES) |
| 9629 | return -EPERM; |
| 9630 | out: |
| 9631 | return err; |
| 9632 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9633 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9634 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9635 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9636 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9637 | { |
| 9638 | int status; |
| 9639 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9640 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9641 | }; |
| 9642 | struct nfs41_test_stateid_res res; |
| 9643 | struct rpc_message msg = { |
| 9644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9645 | .rpc_argp = &args, |
| 9646 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9647 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9648 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9649 | struct rpc_clnt *rpc_client = server->client; |
| 9650 | |
| 9651 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9652 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9653 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9654 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9655 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9656 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9657 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9658 | if (status != NFS_OK) { |
| 9659 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9660 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9661 | } |
| 9662 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9663 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9664 | } |
| 9665 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9666 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9667 | int err, struct nfs4_exception *exception) |
| 9668 | { |
| 9669 | exception->retry = 0; |
| 9670 | switch(err) { |
| 9671 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9672 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9673 | nfs4_handle_exception(server, err, exception); |
| 9674 | break; |
| 9675 | case -NFS4ERR_BADSESSION: |
| 9676 | case -NFS4ERR_BADSLOT: |
| 9677 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9678 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9679 | case -NFS4ERR_DEADSESSION: |
| 9680 | nfs4_do_handle_exception(server, err, exception); |
| 9681 | } |
| 9682 | } |
| 9683 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9684 | /** |
| 9685 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9686 | * |
| 9687 | * @server: server / transport on which to perform the operation |
| 9688 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9689 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9690 | * |
| 9691 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9692 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9693 | * failed or the state ID is not currently valid. |
| 9694 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9695 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9696 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9697 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9698 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9699 | struct nfs4_exception exception = { |
| 9700 | .interruptible = true, |
| 9701 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9702 | int err; |
| 9703 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9704 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9705 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9706 | } while (exception.retry); |
| 9707 | return err; |
| 9708 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9709 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9710 | struct nfs_free_stateid_data { |
| 9711 | struct nfs_server *server; |
| 9712 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9713 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9714 | }; |
| 9715 | |
| 9716 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9717 | { |
| 9718 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9719 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9720 | &data->args.seq_args, |
| 9721 | &data->res.seq_res, |
| 9722 | task); |
| 9723 | } |
| 9724 | |
| 9725 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9726 | { |
| 9727 | struct nfs_free_stateid_data *data = calldata; |
| 9728 | |
| 9729 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9730 | |
| 9731 | switch (task->tk_status) { |
| 9732 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9733 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9734 | rpc_restart_call_prepare(task); |
| 9735 | } |
| 9736 | } |
| 9737 | |
| 9738 | static void nfs41_free_stateid_release(void *calldata) |
| 9739 | { |
| 9740 | kfree(calldata); |
| 9741 | } |
| 9742 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9743 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9744 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9745 | .rpc_call_done = nfs41_free_stateid_done, |
| 9746 | .rpc_release = nfs41_free_stateid_release, |
| 9747 | }; |
| 9748 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9749 | /** |
| 9750 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9751 | * |
| 9752 | * @server: server / transport on which to perform the operation |
| 9753 | * @stateid: state ID to release |
| 9754 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9755 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9756 | * |
| 9757 | * Note: this function is always asynchronous. |
| 9758 | */ |
| 9759 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9760 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9761 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9762 | bool privileged) |
| 9763 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9764 | struct rpc_message msg = { |
| 9765 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9766 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9767 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9768 | struct rpc_task_setup task_setup = { |
| 9769 | .rpc_client = server->client, |
| 9770 | .rpc_message = &msg, |
| 9771 | .callback_ops = &nfs41_free_stateid_ops, |
| 9772 | .flags = RPC_TASK_ASYNC, |
| 9773 | }; |
| 9774 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9775 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9776 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9777 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9778 | &task_setup.rpc_client, &msg); |
| 9779 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9780 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9781 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9782 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9783 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9784 | data->server = server; |
| 9785 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9786 | |
| 9787 | task_setup.callback_data = data; |
| 9788 | |
| 9789 | msg.rpc_argp = &data->args; |
| 9790 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9791 | 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] | 9792 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9793 | if (IS_ERR(task)) |
| 9794 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9795 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9796 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9797 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9798 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9799 | static void |
| 9800 | 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] | 9801 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9802 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9803 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9804 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9805 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9806 | } |
| 9807 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9808 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9809 | const nfs4_stateid *s2) |
| 9810 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9811 | if (s1->type != s2->type) |
| 9812 | return false; |
| 9813 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9814 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9815 | return false; |
| 9816 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9817 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9818 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9819 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9820 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9821 | } |
| 9822 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9823 | #endif /* CONFIG_NFS_V4_1 */ |
| 9824 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9825 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9826 | const nfs4_stateid *s2) |
| 9827 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9828 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9829 | } |
| 9830 | |
| 9831 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9832 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9833 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9834 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9835 | .recover_open = nfs4_open_reclaim, |
| 9836 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9837 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9838 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9839 | }; |
| 9840 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9841 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9842 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9843 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9844 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9845 | .recover_open = nfs4_open_reclaim, |
| 9846 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9847 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9848 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9849 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9850 | }; |
| 9851 | #endif /* CONFIG_NFS_V4_1 */ |
| 9852 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9853 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9854 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9855 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9856 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9857 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9858 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9859 | }; |
| 9860 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9861 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9862 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9863 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9864 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9865 | .recover_open = nfs41_open_expired, |
| 9866 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9867 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9868 | }; |
| 9869 | #endif /* CONFIG_NFS_V4_1 */ |
| 9870 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9871 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9872 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9873 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9874 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9875 | }; |
| 9876 | |
| 9877 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9878 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9879 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9880 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9881 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9882 | }; |
| 9883 | #endif |
| 9884 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9885 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9886 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9887 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9888 | }; |
| 9889 | |
| 9890 | #if defined(CONFIG_NFS_V4_1) |
| 9891 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9892 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9893 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9894 | }; |
| 9895 | #endif /* CONFIG_NFS_V4_1 */ |
| 9896 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9897 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9898 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9899 | .init_caps = NFS_CAP_READDIRPLUS |
| 9900 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9901 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9902 | .init_client = nfs40_init_client, |
| 9903 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9904 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9905 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9906 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9907 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9908 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9909 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9910 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9911 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9912 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9913 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9914 | }; |
| 9915 | |
| 9916 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9917 | static struct nfs_seqid * |
| 9918 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9919 | { |
| 9920 | return NULL; |
| 9921 | } |
| 9922 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9923 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9924 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9925 | .init_caps = NFS_CAP_READDIRPLUS |
| 9926 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9927 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9928 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9929 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9930 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9931 | .init_client = nfs41_init_client, |
| 9932 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9933 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9934 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9935 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9936 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9937 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9938 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9939 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9940 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9941 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9942 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9943 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9944 | }; |
| 9945 | #endif |
| 9946 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9947 | #if defined(CONFIG_NFS_V4_2) |
| 9948 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9949 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9950 | .init_caps = NFS_CAP_READDIRPLUS |
| 9951 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9952 | | NFS_CAP_POSIX_LOCK |
| 9953 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9954 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9955 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9956 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9957 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 9958 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 9959 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9960 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9961 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9962 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 9963 | | NFS_CAP_CLONE |
| 9964 | | NFS_CAP_LAYOUTERROR, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9965 | .init_client = nfs41_init_client, |
| 9966 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9967 | .match_stateid = nfs41_match_stateid, |
| 9968 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9969 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9970 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9971 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9972 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9973 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9974 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9975 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9976 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9977 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9978 | }; |
| 9979 | #endif |
| 9980 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9981 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9982 | [0] = &nfs_v4_0_minor_ops, |
| 9983 | #if defined(CONFIG_NFS_V4_1) |
| 9984 | [1] = &nfs_v4_1_minor_ops, |
| 9985 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9986 | #if defined(CONFIG_NFS_V4_2) |
| 9987 | [2] = &nfs_v4_2_minor_ops, |
| 9988 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9989 | }; |
| 9990 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9991 | 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] | 9992 | { |
| 9993 | ssize_t error, error2; |
| 9994 | |
| 9995 | error = generic_listxattr(dentry, list, size); |
| 9996 | if (error < 0) |
| 9997 | return error; |
| 9998 | if (list) { |
| 9999 | list += error; |
| 10000 | size -= error; |
| 10001 | } |
| 10002 | |
| 10003 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10004 | if (error2 < 0) |
| 10005 | return error2; |
| 10006 | return error + error2; |
| 10007 | } |
| 10008 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10009 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10010 | .create = nfs_create, |
| 10011 | .lookup = nfs_lookup, |
| 10012 | .atomic_open = nfs_atomic_open, |
| 10013 | .link = nfs_link, |
| 10014 | .unlink = nfs_unlink, |
| 10015 | .symlink = nfs_symlink, |
| 10016 | .mkdir = nfs_mkdir, |
| 10017 | .rmdir = nfs_rmdir, |
| 10018 | .mknod = nfs_mknod, |
| 10019 | .rename = nfs_rename, |
| 10020 | .permission = nfs_permission, |
| 10021 | .getattr = nfs_getattr, |
| 10022 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10023 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10024 | }; |
| 10025 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10026 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10027 | .permission = nfs_permission, |
| 10028 | .getattr = nfs_getattr, |
| 10029 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10030 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10031 | }; |
| 10032 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10033 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10034 | .version = 4, /* protocol version */ |
| 10035 | .dentry_ops = &nfs4_dentry_operations, |
| 10036 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10037 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10038 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10039 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10040 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10041 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10042 | .getattr = nfs4_proc_getattr, |
| 10043 | .setattr = nfs4_proc_setattr, |
| 10044 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10045 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10046 | .access = nfs4_proc_access, |
| 10047 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10048 | .create = nfs4_proc_create, |
| 10049 | .remove = nfs4_proc_remove, |
| 10050 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10051 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10052 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10053 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10054 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10055 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10056 | .link = nfs4_proc_link, |
| 10057 | .symlink = nfs4_proc_symlink, |
| 10058 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10059 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10060 | .readdir = nfs4_proc_readdir, |
| 10061 | .mknod = nfs4_proc_mknod, |
| 10062 | .statfs = nfs4_proc_statfs, |
| 10063 | .fsinfo = nfs4_proc_fsinfo, |
| 10064 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10065 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10066 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10067 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10068 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10069 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10070 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10071 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10072 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10073 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10074 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10075 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10076 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10077 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10078 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10079 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10080 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10081 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10082 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10083 | .create_server = nfs4_create_server, |
| 10084 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10085 | }; |
| 10086 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10087 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10088 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10089 | .list = nfs4_xattr_list_nfs4_acl, |
| 10090 | .get = nfs4_xattr_get_nfs4_acl, |
| 10091 | .set = nfs4_xattr_set_nfs4_acl, |
| 10092 | }; |
| 10093 | |
| 10094 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10095 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10096 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10097 | &nfs4_xattr_nfs4_label_handler, |
| 10098 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10099 | NULL |
| 10100 | }; |
| 10101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10102 | /* |
| 10103 | * Local variables: |
| 10104 | * c-basic-offset: 8 |
| 10105 | * End: |
| 10106 | */ |