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 *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode); |
| 95 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 96 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 97 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 98 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 99 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 100 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 101 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 102 | struct rpc_cred *cred, |
| 103 | struct nfs4_slot *slot, |
| 104 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 105 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 106 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 107 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 108 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 109 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 110 | |
| 111 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 112 | static inline struct nfs4_label * |
| 113 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 114 | struct iattr *sattr, struct nfs4_label *label) |
| 115 | { |
| 116 | int err; |
| 117 | |
| 118 | if (label == NULL) |
| 119 | return NULL; |
| 120 | |
| 121 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 122 | return NULL; |
| 123 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 124 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 125 | &dentry->d_name, (void **)&label->label, &label->len); |
| 126 | if (err == 0) |
| 127 | return label; |
| 128 | |
| 129 | return NULL; |
| 130 | } |
| 131 | static inline void |
| 132 | nfs4_label_release_security(struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | security_release_secctx(label->label, label->len); |
| 136 | } |
| 137 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 138 | { |
| 139 | if (label) |
| 140 | return server->attr_bitmask; |
| 141 | |
| 142 | return server->attr_bitmask_nl; |
| 143 | } |
| 144 | #else |
| 145 | static inline struct nfs4_label * |
| 146 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 147 | struct iattr *sattr, struct nfs4_label *l) |
| 148 | { return NULL; } |
| 149 | static inline void |
| 150 | nfs4_label_release_security(struct nfs4_label *label) |
| 151 | { return; } |
| 152 | static inline u32 * |
| 153 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 154 | { return server->attr_bitmask; } |
| 155 | #endif |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 158 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 160 | if (err >= -1000) |
| 161 | return err; |
| 162 | switch (err) { |
| 163 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 164 | case -NFS4ERR_LAYOUTTRYLATER: |
| 165 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 166 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 167 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 168 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 169 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 170 | case -NFS4ERR_BADOWNER: |
| 171 | case -NFS4ERR_BADNAME: |
| 172 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 173 | case -NFS4ERR_SHARE_DENIED: |
| 174 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 175 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 176 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 177 | case -NFS4ERR_FILE_OPEN: |
| 178 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 181 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 182 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 184 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * This is our standard bitmap for GETATTR requests. |
| 189 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 190 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | FATTR4_WORD0_TYPE |
| 192 | | FATTR4_WORD0_CHANGE |
| 193 | | FATTR4_WORD0_SIZE |
| 194 | | FATTR4_WORD0_FSID |
| 195 | | FATTR4_WORD0_FILEID, |
| 196 | FATTR4_WORD1_MODE |
| 197 | | FATTR4_WORD1_NUMLINKS |
| 198 | | FATTR4_WORD1_OWNER |
| 199 | | FATTR4_WORD1_OWNER_GROUP |
| 200 | | FATTR4_WORD1_RAWDEV |
| 201 | | FATTR4_WORD1_SPACE_USED |
| 202 | | FATTR4_WORD1_TIME_ACCESS |
| 203 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 204 | | FATTR4_WORD1_TIME_MODIFY |
| 205 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 206 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 207 | FATTR4_WORD2_SECURITY_LABEL |
| 208 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 211 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 212 | FATTR4_WORD0_TYPE |
| 213 | | FATTR4_WORD0_CHANGE |
| 214 | | FATTR4_WORD0_SIZE |
| 215 | | FATTR4_WORD0_FSID |
| 216 | | FATTR4_WORD0_FILEID, |
| 217 | FATTR4_WORD1_MODE |
| 218 | | FATTR4_WORD1_NUMLINKS |
| 219 | | FATTR4_WORD1_OWNER |
| 220 | | FATTR4_WORD1_OWNER_GROUP |
| 221 | | FATTR4_WORD1_RAWDEV |
| 222 | | FATTR4_WORD1_SPACE_USED |
| 223 | | FATTR4_WORD1_TIME_ACCESS |
| 224 | | FATTR4_WORD1_TIME_METADATA |
| 225 | | FATTR4_WORD1_TIME_MODIFY, |
| 226 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 227 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 228 | | FATTR4_WORD2_SECURITY_LABEL |
| 229 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 230 | }; |
| 231 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 232 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 233 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 234 | | FATTR4_WORD0_FILEID, |
| 235 | }; |
| 236 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 237 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | FATTR4_WORD0_FILES_AVAIL |
| 239 | | FATTR4_WORD0_FILES_FREE |
| 240 | | FATTR4_WORD0_FILES_TOTAL, |
| 241 | FATTR4_WORD1_SPACE_AVAIL |
| 242 | | FATTR4_WORD1_SPACE_FREE |
| 243 | | FATTR4_WORD1_SPACE_TOTAL |
| 244 | }; |
| 245 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 246 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | FATTR4_WORD0_MAXLINK |
| 248 | | FATTR4_WORD0_MAXNAME, |
| 249 | 0 |
| 250 | }; |
| 251 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 252 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | | FATTR4_WORD0_MAXREAD |
| 254 | | FATTR4_WORD0_MAXWRITE |
| 255 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 256 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 257 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 258 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 259 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 262 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 263 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 264 | | FATTR4_WORD0_SIZE |
| 265 | | FATTR4_WORD0_FSID |
| 266 | | FATTR4_WORD0_FILEID |
| 267 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 268 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 269 | | FATTR4_WORD1_OWNER_GROUP |
| 270 | | FATTR4_WORD1_RAWDEV |
| 271 | | FATTR4_WORD1_SPACE_USED |
| 272 | | FATTR4_WORD1_TIME_ACCESS |
| 273 | | FATTR4_WORD1_TIME_METADATA |
| 274 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 275 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 276 | }; |
| 277 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 278 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 279 | struct inode *inode) |
| 280 | { |
| 281 | unsigned long cache_validity; |
| 282 | |
| 283 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 284 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 285 | return; |
| 286 | |
| 287 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 288 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 289 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 290 | | NFS_INO_INVALID_SIZE); |
| 291 | |
| 292 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 293 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 294 | |
| 295 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 296 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 297 | } |
| 298 | |
| 299 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 300 | const __u32 *src, struct inode *inode) |
| 301 | { |
| 302 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 303 | } |
| 304 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 305 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | struct nfs4_readdir_arg *readdir) |
| 307 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 308 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 309 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 312 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | readdir->cookie = 0; |
| 318 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 319 | if (cookie == 2) |
| 320 | return; |
| 321 | |
| 322 | /* |
| 323 | * NFSv4 servers do not return entries for '.' and '..' |
| 324 | * Therefore, we fake these entries here. We let '.' |
| 325 | * have cookie 0 and '..' have cookie 1. Note that |
| 326 | * when talking to the server, we always send cookie 0 |
| 327 | * instead of 1 or 2. |
| 328 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 329 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | if (cookie == 0) { |
| 332 | *p++ = xdr_one; /* next */ |
| 333 | *p++ = xdr_zero; /* cookie, first word */ |
| 334 | *p++ = xdr_one; /* cookie, second word */ |
| 335 | *p++ = xdr_one; /* entry len */ |
| 336 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 337 | p++; |
| 338 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 339 | *p++ = htonl(attrs); /* bitmap */ |
| 340 | *p++ = htonl(12); /* attribute buffer length */ |
| 341 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 342 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | *p++ = xdr_one; /* next */ |
| 346 | *p++ = xdr_zero; /* cookie, first word */ |
| 347 | *p++ = xdr_two; /* cookie, second word */ |
| 348 | *p++ = xdr_two; /* entry len */ |
| 349 | memcpy(p, "..\0\0", 4); /* entry */ |
| 350 | p++; |
| 351 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 352 | *p++ = htonl(attrs); /* bitmap */ |
| 353 | *p++ = htonl(12); /* attribute buffer length */ |
| 354 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 355 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | readdir->pgbase = (char *)p - (char *)start; |
| 358 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 359 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 362 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 363 | nfs4_stateid *stateid, |
| 364 | struct rpc_cred *cred) |
| 365 | { |
| 366 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 367 | |
| 368 | ops->test_and_free_expired(server, stateid, cred); |
| 369 | } |
| 370 | |
| 371 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 372 | nfs4_stateid *stateid, |
| 373 | struct rpc_cred *cred) |
| 374 | { |
| 375 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 376 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 377 | } |
| 378 | |
| 379 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 380 | const nfs4_stateid *stateid, |
| 381 | struct rpc_cred *cred) |
| 382 | { |
| 383 | nfs4_stateid tmp; |
| 384 | |
| 385 | nfs4_stateid_copy(&tmp, stateid); |
| 386 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 387 | } |
| 388 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 389 | static long nfs4_update_delay(long *timeout) |
| 390 | { |
| 391 | long ret; |
| 392 | if (!timeout) |
| 393 | return NFS4_POLL_RETRY_MAX; |
| 394 | if (*timeout <= 0) |
| 395 | *timeout = NFS4_POLL_RETRY_MIN; |
| 396 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 397 | *timeout = NFS4_POLL_RETRY_MAX; |
| 398 | ret = *timeout; |
| 399 | *timeout <<= 1; |
| 400 | return ret; |
| 401 | } |
| 402 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 403 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 404 | { |
| 405 | int res = 0; |
| 406 | |
| 407 | might_sleep(); |
| 408 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 409 | freezable_schedule_timeout_killable_unsafe( |
| 410 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 411 | if (fatal_signal_pending(current)) |
| 412 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 413 | return res; |
| 414 | } |
| 415 | |
| 416 | /* This is the error handling routine for processes that are allowed |
| 417 | * to sleep. |
| 418 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 419 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 420 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 421 | { |
| 422 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 423 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 424 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 425 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 426 | int ret = errorcode; |
| 427 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 428 | exception->delay = 0; |
| 429 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 430 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 431 | |
| 432 | if (stateid == NULL && state != NULL) |
| 433 | stateid = &state->stateid; |
| 434 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 435 | switch(errorcode) { |
| 436 | case 0: |
| 437 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 438 | case -NFS4ERR_BADHANDLE: |
| 439 | case -ESTALE: |
| 440 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 441 | pnfs_destroy_layout(NFS_I(inode)); |
| 442 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 443 | case -NFS4ERR_DELEG_REVOKED: |
| 444 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 445 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 446 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 447 | if (inode != NULL && stateid != NULL) { |
| 448 | nfs_inode_find_state_and_recover(inode, |
| 449 | stateid); |
| 450 | goto wait_on_recovery; |
| 451 | } |
| 452 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 453 | if (inode) { |
| 454 | int err; |
| 455 | |
| 456 | err = nfs_async_inode_return_delegation(inode, |
| 457 | stateid); |
| 458 | if (err == 0) |
| 459 | goto wait_on_recovery; |
| 460 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 461 | exception->retry = 1; |
| 462 | break; |
| 463 | } |
| 464 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 465 | if (state == NULL) |
| 466 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 467 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 468 | if (ret < 0) |
| 469 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 470 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 471 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 472 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 473 | nfs4_schedule_lease_recovery(clp); |
| 474 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 475 | case -NFS4ERR_MOVED: |
| 476 | ret = nfs4_schedule_migration_recovery(server); |
| 477 | if (ret < 0) |
| 478 | break; |
| 479 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 480 | case -NFS4ERR_LEASE_MOVED: |
| 481 | nfs4_schedule_lease_moved_recovery(clp); |
| 482 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 483 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 484 | case -NFS4ERR_BADSESSION: |
| 485 | case -NFS4ERR_BADSLOT: |
| 486 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 487 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 488 | case -NFS4ERR_DEADSESSION: |
| 489 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 490 | case -NFS4ERR_SEQ_MISORDERED: |
| 491 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 492 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 493 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 494 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 495 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 496 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 497 | if (exception->timeout > HZ) { |
| 498 | /* We have retried a decent amount, time to |
| 499 | * fail |
| 500 | */ |
| 501 | ret = -EBUSY; |
| 502 | break; |
| 503 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 504 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 505 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 506 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 507 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 508 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 509 | exception->delay = 1; |
| 510 | return 0; |
| 511 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 512 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 513 | case -NFS4ERR_OLD_STATEID: |
| 514 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 515 | break; |
| 516 | case -NFS4ERR_BADOWNER: |
| 517 | /* The following works around a Linux server bug! */ |
| 518 | case -NFS4ERR_BADNAME: |
| 519 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 520 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 521 | exception->retry = 1; |
| 522 | printk(KERN_WARNING "NFS: v4 server %s " |
| 523 | "does not accept raw " |
| 524 | "uid/gids. " |
| 525 | "Reenabling the idmapper.\n", |
| 526 | server->nfs_client->cl_hostname); |
| 527 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 528 | } |
| 529 | /* We failed to handle the error */ |
| 530 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 531 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 532 | exception->recovering = 1; |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | /* This is the error handling routine for processes that are allowed |
| 537 | * to sleep. |
| 538 | */ |
| 539 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 540 | { |
| 541 | struct nfs_client *clp = server->nfs_client; |
| 542 | int ret; |
| 543 | |
| 544 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 545 | if (exception->delay) { |
| 546 | ret = nfs4_delay(server->client, &exception->timeout); |
| 547 | goto out_retry; |
| 548 | } |
| 549 | if (exception->recovering) { |
| 550 | ret = nfs4_wait_clnt_recover(clp); |
| 551 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 552 | return -EIO; |
| 553 | goto out_retry; |
| 554 | } |
| 555 | return ret; |
| 556 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 557 | if (ret == 0) |
| 558 | exception->retry = 1; |
| 559 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 560 | } |
| 561 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 562 | static int |
| 563 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 564 | int errorcode, struct nfs4_exception *exception) |
| 565 | { |
| 566 | struct nfs_client *clp = server->nfs_client; |
| 567 | int ret; |
| 568 | |
| 569 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 570 | if (exception->delay) { |
| 571 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 572 | goto out_retry; |
| 573 | } |
| 574 | if (exception->recovering) { |
| 575 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 576 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 577 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 578 | goto out_retry; |
| 579 | } |
| 580 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 581 | ret = -EIO; |
| 582 | return ret; |
| 583 | out_retry: |
| 584 | if (ret == 0) |
| 585 | exception->retry = 1; |
| 586 | return ret; |
| 587 | } |
| 588 | |
| 589 | static int |
| 590 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 591 | struct nfs4_state *state, long *timeout) |
| 592 | { |
| 593 | struct nfs4_exception exception = { |
| 594 | .state = state, |
| 595 | }; |
| 596 | |
| 597 | if (task->tk_status >= 0) |
| 598 | return 0; |
| 599 | if (timeout) |
| 600 | exception.timeout = *timeout; |
| 601 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 602 | task->tk_status, |
| 603 | &exception); |
| 604 | if (exception.delay && timeout) |
| 605 | *timeout = exception.timeout; |
| 606 | if (exception.retry) |
| 607 | return -EAGAIN; |
| 608 | return 0; |
| 609 | } |
| 610 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 611 | /* |
| 612 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 613 | * or 'false' otherwise. |
| 614 | */ |
| 615 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 616 | { |
| 617 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 618 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 619 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 620 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 621 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | spin_lock(&clp->cl_lock); |
| 624 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 625 | clp->cl_last_renewal = timestamp; |
| 626 | spin_unlock(&clp->cl_lock); |
| 627 | } |
| 628 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 629 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 630 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 631 | struct nfs_client *clp = server->nfs_client; |
| 632 | |
| 633 | if (!nfs4_has_session(clp)) |
| 634 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 637 | struct nfs4_call_sync_data { |
| 638 | const struct nfs_server *seq_server; |
| 639 | struct nfs4_sequence_args *seq_args; |
| 640 | struct nfs4_sequence_res *seq_res; |
| 641 | }; |
| 642 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 643 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 644 | struct nfs4_sequence_res *res, int cache_reply, |
| 645 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 646 | { |
| 647 | args->sa_slot = NULL; |
| 648 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 649 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 650 | |
| 651 | res->sr_slot = NULL; |
| 652 | } |
| 653 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 654 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 655 | { |
| 656 | struct nfs4_slot *slot = res->sr_slot; |
| 657 | struct nfs4_slot_table *tbl; |
| 658 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 659 | tbl = slot->table; |
| 660 | spin_lock(&tbl->slot_tbl_lock); |
| 661 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 662 | nfs4_free_slot(tbl, slot); |
| 663 | spin_unlock(&tbl->slot_tbl_lock); |
| 664 | |
| 665 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int nfs40_sequence_done(struct rpc_task *task, |
| 669 | struct nfs4_sequence_res *res) |
| 670 | { |
| 671 | if (res->sr_slot != NULL) |
| 672 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 673 | return 1; |
| 674 | } |
| 675 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 676 | #if defined(CONFIG_NFS_V4_1) |
| 677 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 678 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 679 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 680 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 681 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 682 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 683 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 684 | if (!slot) |
| 685 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 686 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 687 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 688 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 689 | /* Bump the slot sequence number */ |
| 690 | if (slot->seq_done) |
| 691 | slot->seq_nr++; |
| 692 | slot->seq_done = 0; |
| 693 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 694 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 695 | /* Be nice to the server: try to ensure that the last transmitted |
| 696 | * value for highest_user_slotid <= target_highest_slotid |
| 697 | */ |
| 698 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 699 | send_new_highest_used_slotid = true; |
| 700 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 701 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 702 | send_new_highest_used_slotid = false; |
| 703 | goto out_unlock; |
| 704 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 705 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 706 | |
| 707 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 708 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 709 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 710 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 711 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 712 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 713 | if (waitqueue_active(&tbl->slot_waitq)) |
| 714 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 717 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 718 | { |
| 719 | nfs41_release_slot(res->sr_slot); |
| 720 | res->sr_slot = NULL; |
| 721 | } |
| 722 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 723 | static int nfs41_sequence_process(struct rpc_task *task, |
| 724 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 725 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 726 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 727 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 728 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 729 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 730 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 731 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 732 | if (slot == NULL) |
| 733 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 734 | /* don't increment the sequence number if the task wasn't sent */ |
| 735 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 736 | goto out; |
| 737 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 738 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 739 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 740 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 741 | if (res->sr_status != -NFS4ERR_DELAY) |
| 742 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 743 | interrupted = true; |
| 744 | } |
| 745 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 746 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 747 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 748 | switch (res->sr_status) { |
| 749 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 750 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 751 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 752 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 753 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 754 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 755 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 756 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 757 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 758 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 759 | case 1: |
| 760 | /* |
| 761 | * sr_status remains 1 if an RPC level error occurred. |
| 762 | * The server may or may not have processed the sequence |
| 763 | * operation.. |
| 764 | * Mark the slot as having hosted an interrupted RPC call. |
| 765 | */ |
| 766 | slot->interrupted = 1; |
| 767 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 768 | case -NFS4ERR_DELAY: |
| 769 | /* The server detected a resend of the RPC call and |
| 770 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 771 | * of RFC5661. |
| 772 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 773 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 774 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 775 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 776 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 777 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 778 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 779 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 780 | /* |
| 781 | * The server thinks we tried to replay a request. |
| 782 | * Retry the call after bumping the sequence ID. |
| 783 | */ |
| 784 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 785 | case -NFS4ERR_BADSLOT: |
| 786 | /* |
| 787 | * The slot id we used was probably retired. Try again |
| 788 | * using a different slot id. |
| 789 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 790 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 791 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 792 | goto retry_nowait; |
| 793 | case -NFS4ERR_SEQ_MISORDERED: |
| 794 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 795 | * Was the last operation on this sequence interrupted? |
| 796 | * If so, retry after bumping the sequence number. |
| 797 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 798 | if (interrupted) |
| 799 | goto retry_new_seq; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 800 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 801 | * Could this slot have been previously retired? |
| 802 | * If so, then the server may be expecting seq_nr = 1! |
| 803 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 804 | if (slot->seq_nr != 1) { |
| 805 | slot->seq_nr = 1; |
| 806 | goto retry_nowait; |
| 807 | } |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 808 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 809 | default: |
| 810 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 811 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 812 | } |
| 813 | out: |
| 814 | /* The session may be reset by one of the error handlers. */ |
| 815 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 816 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 817 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 818 | session_recover: |
| 819 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 820 | goto retry_nowait; |
| 821 | retry_new_seq: |
| 822 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 823 | retry_nowait: |
| 824 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 825 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 826 | task->tk_status = 0; |
| 827 | ret = 0; |
| 828 | } |
| 829 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 830 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 831 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 832 | goto out; |
| 833 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 834 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 835 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 836 | |
| 837 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 838 | { |
| 839 | if (!nfs41_sequence_process(task, res)) |
| 840 | return 0; |
| 841 | if (res->sr_slot != NULL) |
| 842 | nfs41_sequence_free_slot(res); |
| 843 | return 1; |
| 844 | |
| 845 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 846 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 847 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 848 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 849 | { |
| 850 | if (res->sr_slot == NULL) |
| 851 | return 1; |
| 852 | if (res->sr_slot->table->session != NULL) |
| 853 | return nfs41_sequence_process(task, res); |
| 854 | return nfs40_sequence_done(task, res); |
| 855 | } |
| 856 | |
| 857 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 858 | { |
| 859 | if (res->sr_slot != NULL) { |
| 860 | if (res->sr_slot->table->session != NULL) |
| 861 | nfs41_sequence_free_slot(res); |
| 862 | else |
| 863 | nfs40_sequence_free_slot(res); |
| 864 | } |
| 865 | } |
| 866 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 867 | 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] | 868 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 869 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 870 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 871 | if (!res->sr_slot->table->session) |
| 872 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 873 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 874 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 875 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 876 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 877 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 878 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 879 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 880 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 881 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 882 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 883 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 884 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 885 | } |
| 886 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 887 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 888 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 889 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 890 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 891 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 892 | } |
| 893 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 894 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 895 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 896 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | }; |
| 898 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 899 | static void |
| 900 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 901 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 902 | { |
| 903 | struct rpc_task *task; |
| 904 | |
| 905 | task = _nfs41_proc_sequence(client, cred, slot, true); |
| 906 | if (!IS_ERR(task)) |
| 907 | rpc_put_task_async(task); |
| 908 | } |
| 909 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 910 | #else /* !CONFIG_NFS_V4_1 */ |
| 911 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 912 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 913 | { |
| 914 | return nfs40_sequence_done(task, res); |
| 915 | } |
| 916 | |
| 917 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 918 | { |
| 919 | if (res->sr_slot != NULL) |
| 920 | nfs40_sequence_free_slot(res); |
| 921 | } |
| 922 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 923 | int nfs4_sequence_done(struct rpc_task *task, |
| 924 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 925 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 926 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 927 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 928 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 929 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 930 | static void |
| 931 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 932 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 933 | { |
| 934 | WARN_ON_ONCE(1); |
| 935 | slot->interrupted = 0; |
| 936 | } |
| 937 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 938 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 939 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 940 | static |
| 941 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 942 | struct nfs4_sequence_res *res, |
| 943 | struct nfs4_slot *slot) |
| 944 | { |
| 945 | if (!slot) |
| 946 | return; |
| 947 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 948 | args->sa_slot = slot; |
| 949 | |
| 950 | res->sr_slot = slot; |
| 951 | res->sr_timestamp = jiffies; |
| 952 | res->sr_status_flags = 0; |
| 953 | res->sr_status = 1; |
| 954 | |
| 955 | } |
| 956 | |
| 957 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 958 | struct nfs4_sequence_args *args, |
| 959 | struct nfs4_sequence_res *res, |
| 960 | struct rpc_task *task) |
| 961 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 962 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 963 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 964 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 965 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 966 | /* slot already allocated? */ |
| 967 | if (res->sr_slot != NULL) |
| 968 | goto out_start; |
| 969 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 970 | if (session) { |
| 971 | tbl = &session->fc_slot_table; |
| 972 | task->tk_timeout = 0; |
| 973 | } |
| 974 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 975 | for (;;) { |
| 976 | spin_lock(&tbl->slot_tbl_lock); |
| 977 | /* The state manager will wait until the slot table is empty */ |
| 978 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 979 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 980 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 981 | slot = nfs4_alloc_slot(tbl); |
| 982 | if (IS_ERR(slot)) { |
| 983 | /* Try again in 1/4 second */ |
| 984 | if (slot == ERR_PTR(-ENOMEM)) |
| 985 | task->tk_timeout = HZ >> 2; |
| 986 | goto out_sleep; |
| 987 | } |
| 988 | spin_unlock(&tbl->slot_tbl_lock); |
| 989 | |
| 990 | if (likely(!slot->interrupted)) |
| 991 | break; |
| 992 | nfs4_sequence_process_interrupted(client, |
| 993 | slot, task->tk_msg.rpc_cred); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 994 | } |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 995 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 996 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 997 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 998 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 999 | out_start: |
| 1000 | rpc_call_start(task); |
| 1001 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1002 | |
| 1003 | out_sleep: |
| 1004 | if (args->sa_privileged) |
| 1005 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 1006 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 1007 | else |
| 1008 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1009 | spin_unlock(&tbl->slot_tbl_lock); |
| 1010 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1011 | } |
| 1012 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1013 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1014 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1015 | { |
| 1016 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1017 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1018 | data->seq_args, data->seq_res, task); |
| 1019 | } |
| 1020 | |
| 1021 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1022 | { |
| 1023 | struct nfs4_call_sync_data *data = calldata; |
| 1024 | nfs4_sequence_done(task, data->seq_res); |
| 1025 | } |
| 1026 | |
| 1027 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1028 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1029 | .rpc_call_done = nfs40_call_sync_done, |
| 1030 | }; |
| 1031 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1032 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1033 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1034 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1035 | struct nfs4_sequence_args *args, |
| 1036 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1037 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1038 | int ret; |
| 1039 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1040 | struct nfs_client *clp = server->nfs_client; |
| 1041 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1042 | .seq_server = server, |
| 1043 | .seq_args = args, |
| 1044 | .seq_res = res, |
| 1045 | }; |
| 1046 | struct rpc_task_setup task_setup = { |
| 1047 | .rpc_client = clnt, |
| 1048 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1049 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1050 | .callback_data = &data |
| 1051 | }; |
| 1052 | |
| 1053 | task = rpc_run_task(&task_setup); |
| 1054 | if (IS_ERR(task)) |
| 1055 | ret = PTR_ERR(task); |
| 1056 | else { |
| 1057 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1058 | rpc_put_task(task); |
| 1059 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1060 | return ret; |
| 1061 | } |
| 1062 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1063 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1064 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1065 | struct rpc_message *msg, |
| 1066 | struct nfs4_sequence_args *args, |
| 1067 | struct nfs4_sequence_res *res, |
| 1068 | int cache_reply) |
| 1069 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1070 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1071 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1074 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1075 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
| 1077 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1078 | |
| 1079 | spin_lock(&dir->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1080 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1081 | | NFS_INO_INVALID_MTIME |
| 1082 | | NFS_INO_INVALID_DATA; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1083 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1084 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1085 | nfsi->attrtimeo_timestamp = jiffies; |
| 1086 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | nfs_force_lookup_revalidate(dir); |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1088 | if (cinfo->before != inode_peek_iversion_raw(dir)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1089 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1090 | NFS_INO_INVALID_ACL; |
| 1091 | } |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1092 | inode_set_iversion_raw(dir, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1093 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1094 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1095 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | spin_unlock(&dir->i_lock); |
| 1097 | } |
| 1098 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1099 | struct nfs4_open_createattrs { |
| 1100 | struct nfs4_label *label; |
| 1101 | struct iattr *sattr; |
| 1102 | const __u32 verf[2]; |
| 1103 | }; |
| 1104 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1105 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1106 | int err, struct nfs4_exception *exception) |
| 1107 | { |
| 1108 | if (err != -EINVAL) |
| 1109 | return false; |
| 1110 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1111 | return false; |
| 1112 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1113 | exception->retry = 1; |
| 1114 | return true; |
| 1115 | } |
| 1116 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1117 | static u32 |
| 1118 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1119 | fmode_t fmode, int openflags) |
| 1120 | { |
| 1121 | u32 res = 0; |
| 1122 | |
| 1123 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1124 | case FMODE_READ: |
| 1125 | res = NFS4_SHARE_ACCESS_READ; |
| 1126 | break; |
| 1127 | case FMODE_WRITE: |
| 1128 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1129 | break; |
| 1130 | case FMODE_READ|FMODE_WRITE: |
| 1131 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1132 | } |
| 1133 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1134 | goto out; |
| 1135 | /* Want no delegation if we're using O_DIRECT */ |
| 1136 | if (openflags & O_DIRECT) |
| 1137 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1138 | out: |
| 1139 | return res; |
| 1140 | } |
| 1141 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1142 | static enum open_claim_type4 |
| 1143 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1144 | enum open_claim_type4 claim) |
| 1145 | { |
| 1146 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1147 | return claim; |
| 1148 | switch (claim) { |
| 1149 | default: |
| 1150 | return claim; |
| 1151 | case NFS4_OPEN_CLAIM_FH: |
| 1152 | return NFS4_OPEN_CLAIM_NULL; |
| 1153 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1154 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1155 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1156 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1157 | } |
| 1158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
| 1160 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1161 | { |
| 1162 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1163 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1164 | p->o_res.seqid = p->o_arg.seqid; |
| 1165 | p->c_res.seqid = p->c_arg.seqid; |
| 1166 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1167 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1168 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1169 | 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] | 1170 | } |
| 1171 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1172 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1173 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1174 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1175 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1176 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1177 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1178 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1179 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1180 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1181 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1182 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1183 | struct nfs4_opendata *p; |
| 1184 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1185 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1186 | if (p == NULL) |
| 1187 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1188 | |
| 1189 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1190 | if (IS_ERR(p->f_label)) |
| 1191 | goto err_free_p; |
| 1192 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1193 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1194 | if (IS_ERR(p->a_label)) |
| 1195 | goto err_free_f; |
| 1196 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1197 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1198 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1199 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1200 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1201 | nfs_sb_active(dentry->d_sb); |
| 1202 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1203 | p->dir = parent; |
| 1204 | p->owner = sp; |
| 1205 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1206 | p->o_arg.open_flags = flags; |
| 1207 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1208 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1209 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1210 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1211 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1212 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1213 | * will return permission denied for all bits until close */ |
| 1214 | if (!(flags & O_EXCL)) { |
| 1215 | /* ask server to check for all possible rights as results |
| 1216 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1217 | switch (p->o_arg.claim) { |
| 1218 | default: |
| 1219 | break; |
| 1220 | case NFS4_OPEN_CLAIM_NULL: |
| 1221 | case NFS4_OPEN_CLAIM_FH: |
| 1222 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1223 | NFS4_ACCESS_MODIFY | |
| 1224 | NFS4_ACCESS_EXTEND | |
| 1225 | NFS4_ACCESS_EXECUTE; |
| 1226 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1227 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1228 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1229 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1230 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1231 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1232 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1233 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1234 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1235 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1236 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1237 | case NFS4_OPEN_CLAIM_NULL: |
| 1238 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1239 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1240 | p->o_arg.fh = NFS_FH(dir); |
| 1241 | break; |
| 1242 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1243 | case NFS4_OPEN_CLAIM_FH: |
| 1244 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1245 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1246 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1247 | } |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1248 | if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1249 | p->o_arg.u.attrs = &p->attrs; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1250 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1251 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1252 | memcpy(p->o_arg.u.verifier.data, c->verf, |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1253 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1254 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1255 | p->c_arg.fh = &p->o_res.fh; |
| 1256 | p->c_arg.stateid = &p->o_res.stateid; |
| 1257 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1258 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1259 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1260 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1261 | |
| 1262 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1263 | nfs4_label_free(p->a_label); |
| 1264 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1265 | nfs4_label_free(p->f_label); |
| 1266 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1267 | kfree(p); |
| 1268 | err: |
| 1269 | dput(parent); |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1273 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1274 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1275 | struct nfs4_opendata *p = container_of(kref, |
| 1276 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1277 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1278 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1279 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1280 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1281 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1282 | if (p->state != NULL) |
| 1283 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1284 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1285 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1286 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1287 | nfs4_label_free(p->f_label); |
| 1288 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1289 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1290 | dput(p->dentry); |
| 1291 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1292 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1293 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1294 | kfree(p); |
| 1295 | } |
| 1296 | |
| 1297 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1298 | { |
| 1299 | if (p != NULL) |
| 1300 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1303 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1304 | fmode_t fmode) |
| 1305 | { |
| 1306 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1307 | case FMODE_READ|FMODE_WRITE: |
| 1308 | return state->n_rdwr != 0; |
| 1309 | case FMODE_WRITE: |
| 1310 | return state->n_wronly != 0; |
| 1311 | case FMODE_READ: |
| 1312 | return state->n_rdonly != 0; |
| 1313 | } |
| 1314 | WARN_ON_ONCE(1); |
| 1315 | return false; |
| 1316 | } |
| 1317 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1318 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1319 | { |
| 1320 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1321 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1322 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1323 | goto out; |
| 1324 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1325 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1326 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1327 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1328 | break; |
| 1329 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1330 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1331 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1332 | break; |
| 1333 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1334 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1335 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1336 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1337 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1338 | return ret; |
| 1339 | } |
| 1340 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1341 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1342 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1343 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1344 | if (delegation == NULL) |
| 1345 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1347 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1348 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1349 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1350 | switch (claim) { |
| 1351 | case NFS4_OPEN_CLAIM_NULL: |
| 1352 | case NFS4_OPEN_CLAIM_FH: |
| 1353 | break; |
| 1354 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1355 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1356 | break; |
| 1357 | default: |
| 1358 | return 0; |
| 1359 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1360 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1361 | return 1; |
| 1362 | } |
| 1363 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1364 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1365 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1366 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1367 | case FMODE_WRITE: |
| 1368 | state->n_wronly++; |
| 1369 | break; |
| 1370 | case FMODE_READ: |
| 1371 | state->n_rdonly++; |
| 1372 | break; |
| 1373 | case FMODE_READ|FMODE_WRITE: |
| 1374 | state->n_rdwr++; |
| 1375 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1376 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1379 | #ifdef CONFIG_NFS_V4_1 |
| 1380 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1381 | { |
| 1382 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1383 | return true; |
| 1384 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1385 | return true; |
| 1386 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1387 | return true; |
| 1388 | return false; |
| 1389 | } |
| 1390 | #endif /* CONFIG_NFS_V4_1 */ |
| 1391 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1392 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1393 | { |
| 1394 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1395 | wake_up_all(&state->waitq); |
| 1396 | } |
| 1397 | |
| 1398 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1399 | const nfs4_stateid *stateid) |
| 1400 | { |
| 1401 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1402 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1403 | |
| 1404 | if (stateid_seqid == state_seqid + 1U || |
| 1405 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1406 | nfs_state_log_update_open_stateid(state); |
| 1407 | else |
| 1408 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1409 | } |
| 1410 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1411 | 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] | 1412 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1413 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1414 | bool need_recover = false; |
| 1415 | |
| 1416 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1417 | need_recover = true; |
| 1418 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1419 | need_recover = true; |
| 1420 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1421 | need_recover = true; |
| 1422 | if (need_recover) |
| 1423 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1424 | } |
| 1425 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1426 | /* |
| 1427 | * Check for whether or not the caller may update the open stateid |
| 1428 | * to the value passed in by stateid. |
| 1429 | * |
| 1430 | * Note: This function relies heavily on the server implementing |
| 1431 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1432 | * correctly. |
| 1433 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1434 | * are then incremented on every state transition. |
| 1435 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1436 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1437 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1438 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1439 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1440 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1441 | if (stateid->seqid == cpu_to_be32(1)) |
| 1442 | nfs_state_log_update_open_stateid(state); |
| 1443 | else |
| 1444 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1445 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1446 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1447 | |
| 1448 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1449 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1450 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1451 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
| 1454 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1455 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1456 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1457 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1458 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1459 | if (state->n_wronly) |
| 1460 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1461 | if (state->n_rdonly) |
| 1462 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1463 | if (state->n_rdwr) |
| 1464 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1465 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1466 | } |
| 1467 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1468 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1469 | nfs4_stateid *stateid, fmode_t fmode) |
| 1470 | { |
| 1471 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1472 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1473 | case FMODE_WRITE: |
| 1474 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1475 | break; |
| 1476 | case FMODE_READ: |
| 1477 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1478 | break; |
| 1479 | case 0: |
| 1480 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1481 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1482 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1483 | } |
| 1484 | if (stateid == NULL) |
| 1485 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1486 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1487 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1488 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1489 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1490 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1491 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1492 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1493 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1494 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1495 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1496 | out: |
| 1497 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1498 | } |
| 1499 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1500 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1501 | nfs4_stateid *arg_stateid, |
| 1502 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1503 | { |
| 1504 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1505 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1506 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1507 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1508 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1509 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1510 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1513 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1514 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1515 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1516 | DEFINE_WAIT(wait); |
| 1517 | int status = 0; |
| 1518 | for (;;) { |
| 1519 | |
| 1520 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1521 | return; |
| 1522 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1523 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1524 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1525 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1526 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1527 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1528 | break; |
| 1529 | |
| 1530 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1531 | /* |
| 1532 | * Ensure we process the state changes in the same order |
| 1533 | * in which the server processed them by delaying the |
| 1534 | * update of the stateid until we are in sequence. |
| 1535 | */ |
| 1536 | write_sequnlock(&state->seqlock); |
| 1537 | spin_unlock(&state->owner->so_lock); |
| 1538 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1539 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1540 | if (!signal_pending(current)) { |
| 1541 | if (schedule_timeout(5*HZ) == 0) |
| 1542 | status = -EAGAIN; |
| 1543 | else |
| 1544 | status = 0; |
| 1545 | } else |
| 1546 | status = -EINTR; |
| 1547 | finish_wait(&state->waitq, &wait); |
| 1548 | rcu_read_lock(); |
| 1549 | spin_lock(&state->owner->so_lock); |
| 1550 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1551 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1552 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1553 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1554 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1555 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1556 | nfs_test_and_clear_all_open_stateid(state); |
| 1557 | } |
| 1558 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1559 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1560 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1561 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1562 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1563 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1566 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1567 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1568 | fmode_t fmode, |
| 1569 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1571 | /* |
| 1572 | * Protect the call to nfs4_state_set_mode_locked and |
| 1573 | * serialise the stateid update |
| 1574 | */ |
| 1575 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1576 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1577 | switch (fmode) { |
| 1578 | case FMODE_READ: |
| 1579 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1580 | break; |
| 1581 | case FMODE_WRITE: |
| 1582 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1583 | break; |
| 1584 | case FMODE_READ|FMODE_WRITE: |
| 1585 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1586 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1587 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1588 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1592 | const nfs4_stateid *deleg_stateid, |
| 1593 | fmode_t fmode) |
| 1594 | { |
| 1595 | /* |
| 1596 | * Protect the call to nfs4_state_set_mode_locked and |
| 1597 | * serialise the stateid update |
| 1598 | */ |
| 1599 | write_seqlock(&state->seqlock); |
| 1600 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1601 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1602 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1605 | static int update_open_stateid(struct nfs4_state *state, |
| 1606 | const nfs4_stateid *open_stateid, |
| 1607 | const nfs4_stateid *delegation, |
| 1608 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1609 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1610 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1611 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1612 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1613 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1614 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1615 | int ret = 0; |
| 1616 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1617 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1618 | |
| 1619 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1620 | spin_lock(&state->owner->so_lock); |
| 1621 | if (open_stateid != NULL) { |
| 1622 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1623 | ret = 1; |
| 1624 | } |
| 1625 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1626 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1627 | if (deleg_cur == NULL) |
| 1628 | goto no_delegation; |
| 1629 | |
| 1630 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1631 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1632 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1633 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1634 | goto no_delegation_unlock; |
| 1635 | |
| 1636 | if (delegation == NULL) |
| 1637 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1638 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1639 | goto no_delegation_unlock; |
| 1640 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1641 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1642 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1643 | ret = 1; |
| 1644 | no_delegation_unlock: |
| 1645 | spin_unlock(&deleg_cur->lock); |
| 1646 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1647 | if (ret) |
| 1648 | update_open_stateflags(state, fmode); |
| 1649 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1650 | rcu_read_unlock(); |
| 1651 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1652 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1653 | nfs4_schedule_state_manager(clp); |
| 1654 | if (freeme.type != 0) |
| 1655 | nfs4_test_and_free_stateid(server, &freeme, |
| 1656 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1657 | |
| 1658 | return ret; |
| 1659 | } |
| 1660 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1661 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1662 | const nfs4_stateid *stateid) |
| 1663 | { |
| 1664 | struct nfs4_state *state = lsp->ls_state; |
| 1665 | bool ret = false; |
| 1666 | |
| 1667 | spin_lock(&state->state_lock); |
| 1668 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1669 | goto out_noupdate; |
| 1670 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1671 | goto out_noupdate; |
| 1672 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1673 | ret = true; |
| 1674 | out_noupdate: |
| 1675 | spin_unlock(&state->state_lock); |
| 1676 | return ret; |
| 1677 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1678 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1679 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1680 | { |
| 1681 | struct nfs_delegation *delegation; |
| 1682 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1683 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1684 | rcu_read_lock(); |
| 1685 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1686 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1687 | rcu_read_unlock(); |
| 1688 | return; |
| 1689 | } |
| 1690 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1691 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1692 | } |
| 1693 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1694 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1695 | { |
| 1696 | struct nfs4_state *state = opendata->state; |
| 1697 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1698 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1699 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1700 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1701 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1702 | nfs4_stateid stateid; |
| 1703 | int ret = -EAGAIN; |
| 1704 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1705 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1706 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1707 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1708 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1709 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1710 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1711 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1712 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1713 | rcu_read_lock(); |
| 1714 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1715 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1716 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1717 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1718 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1719 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1720 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1721 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1722 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1723 | if (!opendata->is_recover) { |
| 1724 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1725 | if (ret != 0) |
| 1726 | goto out; |
| 1727 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1728 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1729 | |
| 1730 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1731 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1732 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1733 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1734 | out: |
| 1735 | return ERR_PTR(ret); |
| 1736 | out_return_state: |
| 1737 | atomic_inc(&state->count); |
| 1738 | return state; |
| 1739 | } |
| 1740 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1741 | static void |
| 1742 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1743 | { |
| 1744 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1745 | struct nfs_delegation *delegation; |
| 1746 | int delegation_flags = 0; |
| 1747 | |
| 1748 | rcu_read_lock(); |
| 1749 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1750 | if (delegation) |
| 1751 | delegation_flags = delegation->flags; |
| 1752 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1753 | switch (data->o_arg.claim) { |
| 1754 | default: |
| 1755 | break; |
| 1756 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1757 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1758 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1759 | "returning a delegation for " |
| 1760 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1761 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1762 | return; |
| 1763 | } |
| 1764 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1765 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1766 | data->owner->so_cred, |
| 1767 | data->o_res.delegation_type, |
| 1768 | &data->o_res.delegation, |
| 1769 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1770 | else |
| 1771 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1772 | data->owner->so_cred, |
| 1773 | data->o_res.delegation_type, |
| 1774 | &data->o_res.delegation, |
| 1775 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | /* |
| 1779 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1780 | * and update the nfs4_state. |
| 1781 | */ |
| 1782 | static struct nfs4_state * |
| 1783 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1784 | { |
| 1785 | struct inode *inode = data->state->inode; |
| 1786 | struct nfs4_state *state = data->state; |
| 1787 | int ret; |
| 1788 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1789 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1790 | if (data->rpc_status) |
| 1791 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1792 | /* cached opens have already been processed */ |
| 1793 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1794 | } |
| 1795 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1796 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1797 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1798 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1799 | |
| 1800 | if (data->o_res.delegation_type != 0) |
| 1801 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1802 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1803 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1804 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1805 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1806 | |
| 1807 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1810 | static struct inode * |
| 1811 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1812 | { |
| 1813 | struct inode *inode; |
| 1814 | |
| 1815 | switch (data->o_arg.claim) { |
| 1816 | case NFS4_OPEN_CLAIM_NULL: |
| 1817 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1818 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1819 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1820 | return ERR_PTR(-EAGAIN); |
| 1821 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1822 | &data->f_attr, data->f_label); |
| 1823 | break; |
| 1824 | default: |
| 1825 | inode = d_inode(data->dentry); |
| 1826 | ihold(inode); |
| 1827 | nfs_refresh_inode(inode, &data->f_attr); |
| 1828 | } |
| 1829 | return inode; |
| 1830 | } |
| 1831 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1832 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1833 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1834 | { |
| 1835 | struct nfs4_state *state; |
| 1836 | struct inode *inode; |
| 1837 | |
| 1838 | inode = nfs4_opendata_get_inode(data); |
| 1839 | if (IS_ERR(inode)) |
| 1840 | return ERR_CAST(inode); |
| 1841 | if (data->state != NULL && data->state->inode == inode) { |
| 1842 | state = data->state; |
| 1843 | atomic_inc(&state->count); |
| 1844 | } else |
| 1845 | state = nfs4_get_open_state(inode, data->owner); |
| 1846 | iput(inode); |
| 1847 | if (state == NULL) |
| 1848 | state = ERR_PTR(-ENOMEM); |
| 1849 | return state; |
| 1850 | } |
| 1851 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1852 | static struct nfs4_state * |
| 1853 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1854 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1855 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1856 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1857 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1858 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1859 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1860 | goto out; |
| 1861 | } |
| 1862 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1863 | state = nfs4_opendata_find_nfs4_state(data); |
| 1864 | if (IS_ERR(state)) |
| 1865 | goto out; |
| 1866 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1867 | if (data->o_res.delegation_type != 0) |
| 1868 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1869 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1870 | data->o_arg.fmode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1871 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1872 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1873 | return state; |
| 1874 | } |
| 1875 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1876 | static struct nfs4_state * |
| 1877 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1878 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1879 | struct nfs4_state *ret; |
| 1880 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1881 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1882 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1883 | else |
| 1884 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1885 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1886 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1887 | } |
| 1888 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1889 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1890 | { |
| 1891 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1892 | struct nfs_open_context *ctx; |
| 1893 | |
| 1894 | spin_lock(&state->inode->i_lock); |
| 1895 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1896 | if (ctx->state != state) |
| 1897 | continue; |
| 1898 | get_nfs_open_context(ctx); |
| 1899 | spin_unlock(&state->inode->i_lock); |
| 1900 | return ctx; |
| 1901 | } |
| 1902 | spin_unlock(&state->inode->i_lock); |
| 1903 | return ERR_PTR(-ENOENT); |
| 1904 | } |
| 1905 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1906 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1907 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1908 | { |
| 1909 | struct nfs4_opendata *opendata; |
| 1910 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1911 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1912 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1913 | if (opendata == NULL) |
| 1914 | return ERR_PTR(-ENOMEM); |
| 1915 | opendata->state = state; |
| 1916 | atomic_inc(&state->count); |
| 1917 | return opendata; |
| 1918 | } |
| 1919 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1920 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1921 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1922 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1923 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1924 | int ret; |
| 1925 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1926 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1927 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1928 | opendata->o_arg.open_flags = 0; |
| 1929 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1930 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1931 | NFS_SB(opendata->dentry->d_sb), |
| 1932 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1933 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1934 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1935 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1936 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1937 | if (ret != 0) |
| 1938 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1939 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1940 | if (IS_ERR(newstate)) |
| 1941 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1942 | if (newstate != opendata->state) |
| 1943 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1944 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1945 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1949 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1950 | int ret; |
| 1951 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1952 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1953 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1954 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1955 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1956 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1957 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1958 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1959 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1960 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1961 | if (ret != 0) |
| 1962 | return ret; |
| 1963 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1964 | if (ret != 0) |
| 1965 | return ret; |
| 1966 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1967 | if (ret != 0) |
| 1968 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1969 | /* |
| 1970 | * We may have performed cached opens for all three recoveries. |
| 1971 | * Check if we need to update the current stateid. |
| 1972 | */ |
| 1973 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1974 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1975 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1976 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1977 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1978 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1979 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1980 | return 0; |
| 1981 | } |
| 1982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | /* |
| 1984 | * OPEN_RECLAIM: |
| 1985 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1987 | 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] | 1988 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1989 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1990 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1991 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | int status; |
| 1993 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1994 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1995 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1996 | if (IS_ERR(opendata)) |
| 1997 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1998 | rcu_read_lock(); |
| 1999 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2000 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2001 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2002 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2003 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2004 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2005 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | return status; |
| 2007 | } |
| 2008 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2009 | 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] | 2010 | { |
| 2011 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2012 | struct nfs4_exception exception = { }; |
| 2013 | int err; |
| 2014 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2015 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2016 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2017 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2018 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2019 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2020 | break; |
| 2021 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | } while (exception.retry); |
| 2023 | return err; |
| 2024 | } |
| 2025 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2026 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2027 | { |
| 2028 | struct nfs_open_context *ctx; |
| 2029 | int ret; |
| 2030 | |
| 2031 | ctx = nfs4_state_find_open_context(state); |
| 2032 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2033 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2034 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2035 | put_nfs_open_context(ctx); |
| 2036 | return ret; |
| 2037 | } |
| 2038 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2039 | 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] | 2040 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2041 | switch (err) { |
| 2042 | default: |
| 2043 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2044 | "%d.\n", __func__, err); |
| 2045 | case 0: |
| 2046 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2047 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2048 | case -ESTALE: |
| 2049 | break; |
| 2050 | case -NFS4ERR_BADSESSION: |
| 2051 | case -NFS4ERR_BADSLOT: |
| 2052 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2053 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2054 | case -NFS4ERR_DEADSESSION: |
| 2055 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2056 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 2057 | return -EAGAIN; |
| 2058 | case -NFS4ERR_STALE_CLIENTID: |
| 2059 | case -NFS4ERR_STALE_STATEID: |
| 2060 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2061 | /* Don't recall a delegation if it was lost */ |
| 2062 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2063 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2064 | case -NFS4ERR_MOVED: |
| 2065 | nfs4_schedule_migration_recovery(server); |
| 2066 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2067 | case -NFS4ERR_LEASE_MOVED: |
| 2068 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2069 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2070 | case -NFS4ERR_DELEG_REVOKED: |
| 2071 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2072 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2073 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2074 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2075 | nfs_inode_find_state_and_recover(state->inode, |
| 2076 | stateid); |
| 2077 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2078 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2079 | case -NFS4ERR_DELAY: |
| 2080 | case -NFS4ERR_GRACE: |
| 2081 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2082 | ssleep(1); |
| 2083 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2084 | case -ENOMEM: |
| 2085 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2086 | if (fl) { |
| 2087 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2088 | if (lsp) |
| 2089 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2090 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2091 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2092 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | return err; |
| 2094 | } |
| 2095 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2096 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2097 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2098 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2099 | { |
| 2100 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2101 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2102 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2103 | |
| 2104 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2105 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2106 | if (IS_ERR(opendata)) |
| 2107 | return PTR_ERR(opendata); |
| 2108 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2109 | write_seqlock(&state->seqlock); |
| 2110 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2111 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2112 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2113 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2114 | case FMODE_READ|FMODE_WRITE: |
| 2115 | case FMODE_WRITE: |
| 2116 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2117 | if (err) |
| 2118 | break; |
| 2119 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2120 | if (err) |
| 2121 | break; |
| 2122 | case FMODE_READ: |
| 2123 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2124 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2125 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2126 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2127 | } |
| 2128 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2129 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2130 | { |
| 2131 | struct nfs4_opendata *data = calldata; |
| 2132 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2133 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2134 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2135 | } |
| 2136 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2137 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2138 | { |
| 2139 | struct nfs4_opendata *data = calldata; |
| 2140 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2141 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2142 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2143 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2144 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2145 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2146 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2147 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2148 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2149 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | static void nfs4_open_confirm_release(void *calldata) |
| 2153 | { |
| 2154 | struct nfs4_opendata *data = calldata; |
| 2155 | struct nfs4_state *state = NULL; |
| 2156 | |
| 2157 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2158 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2159 | goto out_free; |
| 2160 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2161 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2162 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2163 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2164 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2165 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2166 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2167 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2171 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2172 | .rpc_call_done = nfs4_open_confirm_done, |
| 2173 | .rpc_release = nfs4_open_confirm_release, |
| 2174 | }; |
| 2175 | |
| 2176 | /* |
| 2177 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2178 | */ |
| 2179 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2180 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2181 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2182 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2183 | struct rpc_message msg = { |
| 2184 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2185 | .rpc_argp = &data->c_arg, |
| 2186 | .rpc_resp = &data->c_res, |
| 2187 | .rpc_cred = data->owner->so_cred, |
| 2188 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | struct rpc_task_setup task_setup_data = { |
| 2190 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2191 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2192 | .callback_ops = &nfs4_open_confirm_ops, |
| 2193 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2194 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2195 | .flags = RPC_TASK_ASYNC, |
| 2196 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | int status; |
| 2198 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2199 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2200 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2201 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2202 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2203 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2204 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2205 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2206 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2207 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2208 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2209 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2210 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2211 | smp_wmb(); |
| 2212 | } else |
| 2213 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2214 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | return status; |
| 2216 | } |
| 2217 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2218 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2220 | struct nfs4_opendata *data = calldata; |
| 2221 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2222 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2223 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2224 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2225 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2226 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2227 | /* |
| 2228 | * Check if we still need to send an OPEN call, or if we can use |
| 2229 | * a delegation instead. |
| 2230 | */ |
| 2231 | if (data->state != NULL) { |
| 2232 | struct nfs_delegation *delegation; |
| 2233 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2234 | if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2235 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2236 | rcu_read_lock(); |
| 2237 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2238 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2239 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2240 | rcu_read_unlock(); |
| 2241 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2242 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2243 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2244 | switch (claim) { |
| 2245 | default: |
| 2246 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2247 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2248 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2249 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2250 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2251 | case NFS4_OPEN_CLAIM_FH: |
| 2252 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2253 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2254 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2255 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2256 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2257 | &data->o_res.seq_res, |
| 2258 | task) != 0) |
| 2259 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2260 | |
| 2261 | /* Set the create mode (note dependency on the session type) */ |
| 2262 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2263 | if (data->o_arg.open_flags & O_EXCL) { |
| 2264 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2265 | if (nfs4_has_persistent_session(clp)) |
| 2266 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2267 | else if (clp->cl_mvops->minor_version > 0) |
| 2268 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2269 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2270 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2271 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2272 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2273 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2274 | out_no_action: |
| 2275 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2276 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2277 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2278 | } |
| 2279 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2280 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2281 | { |
| 2282 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2284 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2285 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2286 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2287 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2288 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2289 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2290 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2291 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2292 | case S_IFREG: |
| 2293 | break; |
| 2294 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2295 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2296 | break; |
| 2297 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2298 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2299 | break; |
| 2300 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2301 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2302 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2303 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2304 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2305 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2306 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2307 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2308 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2309 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2310 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2311 | static void nfs4_open_release(void *calldata) |
| 2312 | { |
| 2313 | struct nfs4_opendata *data = calldata; |
| 2314 | struct nfs4_state *state = NULL; |
| 2315 | |
| 2316 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2317 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2318 | goto out_free; |
| 2319 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2320 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2321 | goto out_free; |
| 2322 | /* In case we need an open_confirm, no cleanup! */ |
| 2323 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2324 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2325 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2326 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2327 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2328 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2329 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2333 | .rpc_call_prepare = nfs4_open_prepare, |
| 2334 | .rpc_call_done = nfs4_open_done, |
| 2335 | .rpc_release = nfs4_open_release, |
| 2336 | }; |
| 2337 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2338 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2339 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2340 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2341 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2342 | struct nfs_server *server = NFS_SERVER(dir); |
| 2343 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2344 | struct nfs_openres *o_res = &data->o_res; |
| 2345 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2346 | struct rpc_message msg = { |
| 2347 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2348 | .rpc_argp = o_arg, |
| 2349 | .rpc_resp = o_res, |
| 2350 | .rpc_cred = data->owner->so_cred, |
| 2351 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2352 | struct rpc_task_setup task_setup_data = { |
| 2353 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2354 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2355 | .callback_ops = &nfs4_open_ops, |
| 2356 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2357 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2358 | .flags = RPC_TASK_ASYNC, |
| 2359 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2360 | int status; |
| 2361 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2362 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2363 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2364 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2365 | data->cancelled = false; |
| 2366 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2367 | if (!ctx) { |
| 2368 | 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] | 2369 | data->is_recover = true; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2370 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2371 | 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] | 2372 | pnfs_lgopen_prepare(data, ctx); |
| 2373 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2374 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2375 | if (IS_ERR(task)) |
| 2376 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2377 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2378 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2379 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2380 | smp_wmb(); |
| 2381 | } else |
| 2382 | status = data->rpc_status; |
| 2383 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2384 | |
| 2385 | return status; |
| 2386 | } |
| 2387 | |
| 2388 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2389 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2390 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2391 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2392 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2393 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2394 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2395 | if (status != 0 || !data->rpc_done) |
| 2396 | return status; |
| 2397 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2398 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2399 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2400 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2401 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2402 | |
| 2403 | return status; |
| 2404 | } |
| 2405 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2406 | /* |
| 2407 | * Additional permission checks in order to distinguish between an |
| 2408 | * open for read, and an open for execute. This works around the |
| 2409 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2410 | * the same. |
| 2411 | * Note that in the non-execute case, we want to turn off permission |
| 2412 | * checking if we just created a new file (POSIX open() semantics). |
| 2413 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2414 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2415 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2416 | struct nfs4_state *state, fmode_t fmode, |
| 2417 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2418 | { |
| 2419 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2420 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2421 | |
| 2422 | /* access call failed or for some reason the server doesn't |
| 2423 | * support any access modes -- defer access call until later */ |
| 2424 | if (opendata->o_res.access_supported == 0) |
| 2425 | return 0; |
| 2426 | |
| 2427 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2428 | /* |
| 2429 | * Use openflags to check for exec, because fmode won't |
| 2430 | * always have FMODE_EXEC set when file open for exec. |
| 2431 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2432 | if (openflags & __FMODE_EXEC) { |
| 2433 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2434 | if (S_ISDIR(state->inode->i_mode)) |
| 2435 | mask = NFS4_ACCESS_LOOKUP; |
| 2436 | else |
| 2437 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2438 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2439 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2440 | |
| 2441 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2442 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2443 | nfs_access_add_cache(state->inode, &cache); |
| 2444 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2445 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2446 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2447 | return 0; |
| 2448 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2449 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2450 | } |
| 2451 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2452 | /* |
| 2453 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2454 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2455 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2456 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2457 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2458 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2459 | struct nfs_server *server = NFS_SERVER(dir); |
| 2460 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2461 | struct nfs_openres *o_res = &data->o_res; |
| 2462 | int status; |
| 2463 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2464 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2465 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2466 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2467 | if (status != 0) { |
| 2468 | if (status == -NFS4ERR_BADNAME && |
| 2469 | !(o_arg->open_flags & O_CREAT)) |
| 2470 | return -ENOENT; |
| 2471 | return status; |
| 2472 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2473 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2474 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2475 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2476 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2477 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2478 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2479 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2480 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2481 | if (data->file_created || |
| 2482 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2483 | update_changeattr(dir, &o_res->cinfo, |
| 2484 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2485 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2486 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2487 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2489 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2491 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2493 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2494 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2495 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2496 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2497 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2498 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | /* |
| 2502 | * OPEN_EXPIRED: |
| 2503 | * reclaim state on the server after a network partition. |
| 2504 | * Assumes caller holds the appropriate lock |
| 2505 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2506 | 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] | 2507 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2508 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2509 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2511 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2512 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2513 | if (IS_ERR(opendata)) |
| 2514 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2515 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2516 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2517 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2518 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2519 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2522 | 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] | 2523 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2524 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2525 | struct nfs4_exception exception = { }; |
| 2526 | int err; |
| 2527 | |
| 2528 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2529 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2530 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2531 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2532 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2533 | switch (err) { |
| 2534 | default: |
| 2535 | goto out; |
| 2536 | case -NFS4ERR_GRACE: |
| 2537 | case -NFS4ERR_DELAY: |
| 2538 | nfs4_handle_exception(server, err, &exception); |
| 2539 | err = 0; |
| 2540 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2541 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2542 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2543 | return err; |
| 2544 | } |
| 2545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2547 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2549 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2551 | ctx = nfs4_state_find_open_context(state); |
| 2552 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2553 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2554 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2555 | put_nfs_open_context(ctx); |
| 2556 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2559 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2560 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2561 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2562 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2563 | write_seqlock(&state->seqlock); |
| 2564 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2565 | write_sequnlock(&state->seqlock); |
| 2566 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2567 | } |
| 2568 | |
| 2569 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2570 | { |
| 2571 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2572 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2576 | { |
| 2577 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2578 | nfs40_clear_delegation_stateid(state); |
| 2579 | return nfs4_open_expired(sp, state); |
| 2580 | } |
| 2581 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2582 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2583 | nfs4_stateid *stateid, |
| 2584 | struct rpc_cred *cred) |
| 2585 | { |
| 2586 | return -NFS4ERR_BAD_STATEID; |
| 2587 | } |
| 2588 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2589 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2590 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2591 | nfs4_stateid *stateid, |
| 2592 | struct rpc_cred *cred) |
| 2593 | { |
| 2594 | int status; |
| 2595 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2596 | switch (stateid->type) { |
| 2597 | default: |
| 2598 | break; |
| 2599 | case NFS4_INVALID_STATEID_TYPE: |
| 2600 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2601 | return -NFS4ERR_BAD_STATEID; |
| 2602 | case NFS4_REVOKED_STATEID_TYPE: |
| 2603 | goto out_free; |
| 2604 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2605 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2606 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2607 | switch (status) { |
| 2608 | case -NFS4ERR_EXPIRED: |
| 2609 | case -NFS4ERR_ADMIN_REVOKED: |
| 2610 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2611 | break; |
| 2612 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2613 | return status; |
| 2614 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2615 | out_free: |
| 2616 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2617 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2618 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2619 | } |
| 2620 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2621 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2622 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2623 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2624 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2625 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2626 | struct rpc_cred *cred; |
| 2627 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2628 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2629 | /* Get the delegation credential for use by test/free_stateid */ |
| 2630 | rcu_read_lock(); |
| 2631 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2632 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2633 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2634 | return; |
| 2635 | } |
| 2636 | |
| 2637 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2638 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2639 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2640 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2641 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2642 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2643 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2644 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2645 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2646 | cred = get_rpccred(delegation->cred); |
| 2647 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2648 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2649 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2650 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2651 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2652 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2653 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2657 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2658 | * |
| 2659 | * @state: NFSv4 state for an inode |
| 2660 | * |
| 2661 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2662 | * Otherwise a negative NFS4ERR value is returned. |
| 2663 | */ |
| 2664 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2665 | { |
| 2666 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2667 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2668 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2669 | |
| 2670 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2671 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2672 | |
| 2673 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2674 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2675 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2676 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2677 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2678 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2679 | spin_unlock(&state->state_lock); |
| 2680 | |
| 2681 | nfs4_put_lock_state(prev); |
| 2682 | prev = lsp; |
| 2683 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2684 | status = nfs41_test_and_free_expired_stateid(server, |
| 2685 | &lsp->ls_stateid, |
| 2686 | cred); |
| 2687 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2688 | if (status == -NFS4ERR_EXPIRED || |
| 2689 | status == -NFS4ERR_BAD_STATEID) { |
| 2690 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2691 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2692 | if (!recover_lost_locks) |
| 2693 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2694 | } else if (status != NFS_OK) { |
| 2695 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2696 | nfs4_put_lock_state(prev); |
| 2697 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2698 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2699 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2700 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2701 | } |
| 2702 | spin_unlock(&state->state_lock); |
| 2703 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2704 | out: |
| 2705 | return ret; |
| 2706 | } |
| 2707 | |
| 2708 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2709 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2710 | * |
| 2711 | * @state: NFSv4 state for an inode |
| 2712 | * |
| 2713 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2714 | * Otherwise a negative NFS4ERR value is returned. |
| 2715 | */ |
| 2716 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2717 | { |
| 2718 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2719 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2720 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2721 | int status; |
| 2722 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2723 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2724 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2725 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2726 | return NFS_OK; |
| 2727 | return -NFS4ERR_OPENMODE; |
| 2728 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2729 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2730 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2731 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2732 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2733 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2734 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2735 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2736 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2737 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2738 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2739 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2740 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2741 | if (nfs_open_stateid_recover_openmode(state)) |
| 2742 | return -NFS4ERR_OPENMODE; |
| 2743 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2747 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2748 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2749 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2750 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2751 | status = nfs41_check_expired_locks(state); |
| 2752 | if (status != NFS_OK) |
| 2753 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2754 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2755 | if (status != NFS_OK) |
| 2756 | status = nfs4_open_expired(sp, state); |
| 2757 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2758 | } |
| 2759 | #endif |
| 2760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2762 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2763 | * fields corresponding to attributes that were used to store the verifier. |
| 2764 | * Make sure we clobber those fields in the later setattr call |
| 2765 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2766 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2767 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2768 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2769 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2770 | __u32 attrset[3]; |
| 2771 | unsigned ret; |
| 2772 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2773 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2774 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2775 | attrset[i] = opendata->o_res.attrset[i]; |
| 2776 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2777 | attrset[i] &= ~bitmask[i]; |
| 2778 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2779 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2780 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2781 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2782 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2783 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2784 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2785 | ret |= ATTR_ATIME_SET; |
| 2786 | else |
| 2787 | ret |= ATTR_ATIME; |
| 2788 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2789 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2790 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2791 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2792 | ret |= ATTR_MTIME_SET; |
| 2793 | else |
| 2794 | ret |= ATTR_MTIME; |
| 2795 | } |
| 2796 | |
| 2797 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2798 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2799 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2802 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2803 | fmode_t fmode, |
| 2804 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2805 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2806 | { |
| 2807 | struct nfs4_state_owner *sp = opendata->owner; |
| 2808 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2809 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2810 | struct nfs4_state *state; |
| 2811 | unsigned int seq; |
| 2812 | int ret; |
| 2813 | |
| 2814 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2815 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2816 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2817 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2818 | goto out; |
| 2819 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2820 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2821 | ret = PTR_ERR(state); |
| 2822 | if (IS_ERR(state)) |
| 2823 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2824 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2825 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2826 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2827 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2828 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2829 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2830 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2831 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2832 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2833 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2834 | alias = d_exact_alias(dentry, state->inode); |
| 2835 | if (!alias) |
| 2836 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2837 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2838 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2839 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2840 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2841 | } |
| 2842 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2843 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2844 | } |
| 2845 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2846 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2847 | if (ret != 0) |
| 2848 | goto out; |
| 2849 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2850 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2851 | nfs_inode_attach_open_context(ctx); |
| 2852 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2853 | nfs4_schedule_stateid_recovery(server, state); |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2854 | else |
| 2855 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2856 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2857 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2858 | out: |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2859 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2860 | return ret; |
| 2861 | } |
| 2862 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2863 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2864 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2866 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2867 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2868 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2869 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2870 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | { |
| 2872 | struct nfs4_state_owner *sp; |
| 2873 | struct nfs4_state *state = NULL; |
| 2874 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2875 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2876 | struct dentry *dentry = ctx->dentry; |
| 2877 | struct rpc_cred *cred = ctx->cred; |
| 2878 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2879 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2880 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2881 | struct iattr *sattr = c->sattr; |
| 2882 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2883 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2884 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | |
| 2886 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2888 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2889 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2891 | goto out_err; |
| 2892 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2893 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2894 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2895 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2896 | if (d_really_is_positive(dentry)) |
| 2897 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2898 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2899 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2900 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2901 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 2902 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2903 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2904 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2906 | if (label) { |
| 2907 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2908 | if (IS_ERR(olabel)) { |
| 2909 | status = PTR_ERR(olabel); |
| 2910 | goto err_opendata_put; |
| 2911 | } |
| 2912 | } |
| 2913 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2914 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2915 | if (!opendata->f_attr.mdsthreshold) { |
| 2916 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2917 | if (!opendata->f_attr.mdsthreshold) |
| 2918 | goto err_free_label; |
| 2919 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2920 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2921 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2922 | if (d_really_is_positive(dentry)) |
| 2923 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2924 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2925 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2926 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2927 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2928 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2929 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2930 | 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] | 2931 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2932 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2933 | /* |
| 2934 | * send create attributes which was not set by open |
| 2935 | * with an extra setattr. |
| 2936 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2937 | if (attrs || label) { |
| 2938 | unsigned ia_old = sattr->ia_valid; |
| 2939 | |
| 2940 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2941 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2942 | status = nfs4_do_setattr(state->inode, cred, |
| 2943 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2944 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2945 | if (status == 0) { |
| 2946 | nfs_setattr_update_inode(state->inode, sattr, |
| 2947 | opendata->o_res.f_attr); |
| 2948 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2949 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2950 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2951 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2952 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2953 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2954 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2955 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2956 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2957 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2958 | opendata->f_attr.mdsthreshold = NULL; |
| 2959 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2960 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2961 | nfs4_label_free(olabel); |
| 2962 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2963 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2966 | err_free_label: |
| 2967 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2968 | err_opendata_put: |
| 2969 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2970 | err_put_state_owner: |
| 2971 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | return status; |
| 2974 | } |
| 2975 | |
| 2976 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2977 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2978 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2979 | int flags, |
| 2980 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2981 | struct nfs4_label *label, |
| 2982 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2984 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | struct nfs4_exception exception = { }; |
| 2986 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2987 | struct nfs4_open_createattrs c = { |
| 2988 | .label = label, |
| 2989 | .sattr = sattr, |
| 2990 | .verf = { |
| 2991 | [0] = (__u32)jiffies, |
| 2992 | [1] = (__u32)current->pid, |
| 2993 | }, |
| 2994 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | int status; |
| 2996 | |
| 2997 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2998 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2999 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3000 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | if (status == 0) |
| 3002 | break; |
| 3003 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3004 | * book-keeping w.r.t. state-changing operations |
| 3005 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3006 | * It is actually a sign of a bug on the client or on the server. |
| 3007 | * |
| 3008 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3009 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | * have unhashed the old state_owner for us, and that we can |
| 3011 | * therefore safely retry using a new one. We should still warn |
| 3012 | * the user though... |
| 3013 | */ |
| 3014 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3015 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3016 | " returned a bad sequence-id error!\n", |
| 3017 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | exception.retry = 1; |
| 3019 | continue; |
| 3020 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3021 | /* |
| 3022 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3023 | * state before it received the OPEN_CONFIRM. |
| 3024 | * Recover by retrying the request as per the discussion |
| 3025 | * on Page 181 of RFC3530. |
| 3026 | */ |
| 3027 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3028 | exception.retry = 1; |
| 3029 | continue; |
| 3030 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3031 | if (status == -EAGAIN) { |
| 3032 | /* We must have found a delegation */ |
| 3033 | exception.retry = 1; |
| 3034 | continue; |
| 3035 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3036 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3037 | continue; |
| 3038 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | status, &exception)); |
| 3040 | } while (exception.retry); |
| 3041 | return res; |
| 3042 | } |
| 3043 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3044 | static int _nfs4_do_setattr(struct inode *inode, |
| 3045 | struct nfs_setattrargs *arg, |
| 3046 | struct nfs_setattrres *res, |
| 3047 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3048 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3049 | { |
| 3050 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3051 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3052 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3053 | .rpc_argp = arg, |
| 3054 | .rpc_resp = res, |
| 3055 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3056 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3057 | struct rpc_cred *delegation_cred = NULL; |
| 3058 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3059 | bool truncate; |
| 3060 | int status; |
| 3061 | |
| 3062 | nfs_fattr_init(res->fattr); |
| 3063 | |
| 3064 | /* Servers should only apply open mode checks for file size changes */ |
| 3065 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3066 | if (!truncate) |
| 3067 | goto zero_stateid; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3068 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3069 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3070 | /* Use that stateid */ |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3071 | } else if (ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3072 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3073 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3074 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3075 | l_ctx = nfs_get_lock_context(ctx); |
| 3076 | if (IS_ERR(l_ctx)) |
| 3077 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3078 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3079 | &arg->stateid, &delegation_cred); |
| 3080 | nfs_put_lock_context(l_ctx); |
| 3081 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3082 | return -EBADF; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3083 | } else { |
| 3084 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3085 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3086 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3087 | if (delegation_cred) |
| 3088 | msg.rpc_cred = delegation_cred; |
| 3089 | |
| 3090 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3091 | |
| 3092 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3093 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3094 | renew_lease(server, timestamp); |
| 3095 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3096 | return status; |
| 3097 | } |
| 3098 | |
| 3099 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 3100 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3101 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3102 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3104 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3105 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3106 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3107 | struct nfs_setattrargs arg = { |
| 3108 | .fh = NFS_FH(inode), |
| 3109 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3111 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3112 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3113 | }; |
| 3114 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3116 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3118 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3119 | struct nfs4_exception exception = { |
| 3120 | .state = state, |
| 3121 | .inode = inode, |
| 3122 | .stateid = &arg.stateid, |
| 3123 | }; |
| 3124 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3127 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3128 | nfs4_bitmask(server, olabel), |
| 3129 | inode); |
| 3130 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3131 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3132 | switch (err) { |
| 3133 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3134 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3135 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3136 | "applying open mode checks to " |
| 3137 | "a SETATTR that is not " |
| 3138 | "changing file size.\n", |
| 3139 | server->nfs_client->cl_hostname); |
| 3140 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3141 | if (state && !(state->state & FMODE_WRITE)) { |
| 3142 | err = -EBADF; |
| 3143 | if (sattr->ia_valid & ATTR_OPEN) |
| 3144 | err = -EACCES; |
| 3145 | goto out; |
| 3146 | } |
| 3147 | } |
| 3148 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3150 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | return err; |
| 3152 | } |
| 3153 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3154 | static bool |
| 3155 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3156 | { |
| 3157 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3158 | return false; |
| 3159 | |
| 3160 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3161 | } |
| 3162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | struct nfs4_closedata { |
| 3164 | struct inode *inode; |
| 3165 | struct nfs4_state *state; |
| 3166 | struct nfs_closeargs arg; |
| 3167 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3168 | struct { |
| 3169 | struct nfs4_layoutreturn_args arg; |
| 3170 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3171 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3172 | u32 roc_barrier; |
| 3173 | bool roc; |
| 3174 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3175 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3176 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | }; |
| 3178 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3179 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3180 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3181 | struct nfs4_closedata *calldata = data; |
| 3182 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3183 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3184 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3185 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3186 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3187 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3188 | nfs4_put_open_state(calldata->state); |
| 3189 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3190 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3191 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3192 | kfree(calldata); |
| 3193 | } |
| 3194 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3195 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3197 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3200 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3201 | struct nfs4_exception exception = { |
| 3202 | .state = state, |
| 3203 | .inode = calldata->inode, |
| 3204 | .stateid = &calldata->arg.stateid, |
| 3205 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3207 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3208 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3209 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3210 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3211 | |
| 3212 | /* Handle Layoutreturn errors */ |
| 3213 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3214 | switch (calldata->res.lr_ret) { |
| 3215 | default: |
| 3216 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3217 | break; |
| 3218 | case 0: |
| 3219 | calldata->arg.lr_args = NULL; |
| 3220 | calldata->res.lr_res = NULL; |
| 3221 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3222 | case -NFS4ERR_OLD_STATEID: |
| 3223 | if (nfs4_refresh_layout_stateid(&calldata->arg.lr_args->stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3224 | calldata->inode)) |
| 3225 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3226 | /* Fallthrough */ |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3227 | case -NFS4ERR_ADMIN_REVOKED: |
| 3228 | case -NFS4ERR_DELEG_REVOKED: |
| 3229 | case -NFS4ERR_EXPIRED: |
| 3230 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3231 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3232 | case -NFS4ERR_WRONG_CRED: |
| 3233 | calldata->arg.lr_args = NULL; |
| 3234 | calldata->res.lr_res = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3235 | goto lr_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3236 | } |
| 3237 | } |
| 3238 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3239 | /* 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] | 3240 | * the state_owner. we keep this around to process errors |
| 3241 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | switch (task->tk_status) { |
| 3243 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3244 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3245 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3246 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3247 | case -NFS4ERR_ACCESS: |
| 3248 | if (calldata->arg.bitmask != NULL) { |
| 3249 | calldata->arg.bitmask = NULL; |
| 3250 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3251 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3252 | |
| 3253 | } |
| 3254 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3255 | case -NFS4ERR_OLD_STATEID: |
| 3256 | /* Did we race with OPEN? */ |
| 3257 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3258 | state)) |
| 3259 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3260 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3261 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3263 | case -NFS4ERR_EXPIRED: |
| 3264 | nfs4_free_revoked_stateid(server, |
| 3265 | &calldata->arg.stateid, |
| 3266 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3267 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3268 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3269 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3271 | task->tk_status = nfs4_async_handle_exception(task, |
| 3272 | server, task->tk_status, &exception); |
| 3273 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3274 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3276 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3277 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3278 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3279 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3280 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3281 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3282 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3283 | return; |
| 3284 | lr_restart: |
| 3285 | calldata->res.lr_ret = 0; |
| 3286 | out_restart: |
| 3287 | task->tk_status = 0; |
| 3288 | rpc_restart_call_prepare(task); |
| 3289 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3292 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3294 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3295 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3296 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame^] | 3297 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3298 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3299 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3300 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3301 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3302 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3303 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3304 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3305 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3306 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3307 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3308 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3309 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3310 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3311 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3312 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3313 | if (state->n_rdonly == 0) |
| 3314 | call_close |= is_rdonly; |
| 3315 | else if (is_rdonly) |
| 3316 | calldata->arg.fmode |= FMODE_READ; |
| 3317 | if (state->n_wronly == 0) |
| 3318 | call_close |= is_wronly; |
| 3319 | else if (is_wronly) |
| 3320 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3321 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3322 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3323 | } else if (is_rdwr) |
| 3324 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3325 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3326 | if (!nfs4_valid_open_stateid(state) || |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3327 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3328 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3329 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3330 | |
| 3331 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3332 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3333 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3334 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3335 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3336 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3337 | nfs_release_seqid(calldata->arg.seqid); |
| 3338 | goto out_wait; |
| 3339 | } |
| 3340 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame^] | 3341 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3342 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3343 | calldata->arg.lr_args = NULL; |
| 3344 | calldata->res.lr_res = NULL; |
| 3345 | } |
| 3346 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3347 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3348 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3349 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3350 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3351 | /* Close-to-open cache consistency revalidation */ |
| 3352 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3353 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3354 | else |
| 3355 | calldata->arg.bitmask = NULL; |
| 3356 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3357 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3358 | calldata->arg.share_access = |
| 3359 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3360 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3361 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3362 | if (calldata->res.fattr == NULL) |
| 3363 | calldata->arg.bitmask = NULL; |
| 3364 | else if (calldata->arg.bitmask == NULL) |
| 3365 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3366 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3367 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3368 | &calldata->arg.seq_args, |
| 3369 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3370 | task) != 0) |
| 3371 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3372 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3373 | return; |
| 3374 | out_no_action: |
| 3375 | task->tk_action = NULL; |
| 3376 | out_wait: |
| 3377 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3380 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3381 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3382 | .rpc_call_done = nfs4_close_done, |
| 3383 | .rpc_release = nfs4_free_closedata, |
| 3384 | }; |
| 3385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | /* |
| 3387 | * It is possible for data to be read/written from a mem-mapped file |
| 3388 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3389 | * This means that we can't safely call nfsv4 close on a file until |
| 3390 | * the inode is cleared. This in turn means that we are not good |
| 3391 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3392 | * share state even when we are done with one of the three share |
| 3393 | * stateid's in the inode. |
| 3394 | * |
| 3395 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3396 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3397 | 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] | 3398 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3399 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3400 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3402 | struct nfs4_state_owner *sp = state->owner; |
| 3403 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3404 | struct rpc_message msg = { |
| 3405 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3406 | .rpc_cred = state->owner->so_cred, |
| 3407 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3408 | struct rpc_task_setup task_setup_data = { |
| 3409 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3410 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3411 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3412 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3413 | .flags = RPC_TASK_ASYNC, |
| 3414 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3415 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3417 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3418 | &task_setup_data.rpc_client, &msg); |
| 3419 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3420 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3422 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3423 | 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] | 3424 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3426 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3427 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3428 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3430 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3431 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3432 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3433 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3434 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3435 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3436 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3437 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3438 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3439 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3440 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3441 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3442 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3443 | if (calldata->lr.roc) { |
| 3444 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3445 | calldata->res.lr_res = &calldata->lr.res; |
| 3446 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3447 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3448 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3449 | msg.rpc_argp = &calldata->arg; |
| 3450 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3451 | task_setup_data.callback_data = calldata; |
| 3452 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3453 | if (IS_ERR(task)) |
| 3454 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3455 | status = 0; |
| 3456 | if (wait) |
| 3457 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3458 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3459 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3460 | out_free_calldata: |
| 3461 | kfree(calldata); |
| 3462 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3463 | nfs4_put_open_state(state); |
| 3464 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3465 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3468 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3469 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3470 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3473 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3474 | |
| 3475 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3477 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3478 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3479 | |
| 3480 | nfs4_label_release_security(label); |
| 3481 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3482 | if (IS_ERR(state)) |
| 3483 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3484 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | } |
| 3486 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3487 | 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] | 3488 | { |
| 3489 | if (ctx->state == NULL) |
| 3490 | return; |
| 3491 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3492 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3493 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3494 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3497 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3498 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3499 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3502 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3503 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3504 | struct nfs4_server_caps_arg args = { |
| 3505 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3506 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3507 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | struct nfs4_server_caps_res res = {}; |
| 3509 | struct rpc_message msg = { |
| 3510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3511 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | .rpc_resp = &res, |
| 3513 | }; |
| 3514 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3515 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3517 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3518 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3519 | FATTR4_WORD0_LINK_SUPPORT | |
| 3520 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3521 | FATTR4_WORD0_ACLSUPPORT; |
| 3522 | if (minorversion) |
| 3523 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3524 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3525 | 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] | 3526 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3527 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3528 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3529 | case 0: |
| 3530 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3531 | res.attr_bitmask[2] = 0; |
| 3532 | break; |
| 3533 | case 1: |
| 3534 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3535 | break; |
| 3536 | case 2: |
| 3537 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3540 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3541 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3542 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3543 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3544 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3545 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3546 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3547 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | server->caps |= NFS_CAP_ACLS; |
| 3549 | if (res.has_links != 0) |
| 3550 | server->caps |= NFS_CAP_HARDLINKS; |
| 3551 | if (res.has_symlinks != 0) |
| 3552 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3553 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3554 | server->caps |= NFS_CAP_FILEID; |
| 3555 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3556 | server->caps |= NFS_CAP_MODE; |
| 3557 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3558 | server->caps |= NFS_CAP_NLINK; |
| 3559 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3560 | server->caps |= NFS_CAP_OWNER; |
| 3561 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3562 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3563 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3564 | server->caps |= NFS_CAP_ATIME; |
| 3565 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3566 | server->caps |= NFS_CAP_CTIME; |
| 3567 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3568 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3569 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3570 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3571 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3572 | #endif |
| 3573 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3574 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3575 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3576 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3577 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3578 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3579 | 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] | 3580 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3581 | |
| 3582 | /* Avoid a regression due to buggy server */ |
| 3583 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3584 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3585 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3586 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3589 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | return status; |
| 3593 | } |
| 3594 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3595 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | { |
| 3597 | struct nfs4_exception exception = { }; |
| 3598 | int err; |
| 3599 | do { |
| 3600 | err = nfs4_handle_exception(server, |
| 3601 | _nfs4_server_capabilities(server, fhandle), |
| 3602 | &exception); |
| 3603 | } while (exception.retry); |
| 3604 | return err; |
| 3605 | } |
| 3606 | |
| 3607 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3608 | struct nfs_fsinfo *info) |
| 3609 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3610 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3612 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | }; |
| 3614 | struct nfs4_lookup_res res = { |
| 3615 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3616 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | .fh = fhandle, |
| 3618 | }; |
| 3619 | struct rpc_message msg = { |
| 3620 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3621 | .rpc_argp = &args, |
| 3622 | .rpc_resp = &res, |
| 3623 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3624 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3625 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3626 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3627 | /* |
| 3628 | * Process the label in the upcoming getfattr |
| 3629 | */ |
| 3630 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3631 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3632 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3633 | 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] | 3634 | } |
| 3635 | |
| 3636 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3637 | struct nfs_fsinfo *info) |
| 3638 | { |
| 3639 | struct nfs4_exception exception = { }; |
| 3640 | int err; |
| 3641 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3642 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3643 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3644 | switch (err) { |
| 3645 | case 0: |
| 3646 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3647 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3648 | default: |
| 3649 | err = nfs4_handle_exception(server, err, &exception); |
| 3650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3652 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | return err; |
| 3654 | } |
| 3655 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3656 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3657 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3658 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3659 | struct rpc_auth_create_args auth_args = { |
| 3660 | .pseudoflavor = flavor, |
| 3661 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3662 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3663 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3664 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3665 | if (IS_ERR(auth)) |
| 3666 | return -EACCES; |
| 3667 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3670 | /* |
| 3671 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3672 | * |
| 3673 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3674 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3675 | * |
| 3676 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3677 | * negative errno value. |
| 3678 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3679 | 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] | 3680 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3682 | /* Per 3530bis 15.33.5 */ |
| 3683 | static const rpc_authflavor_t flav_array[] = { |
| 3684 | RPC_AUTH_GSS_KRB5P, |
| 3685 | RPC_AUTH_GSS_KRB5I, |
| 3686 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3687 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3688 | RPC_AUTH_NULL, |
| 3689 | }; |
| 3690 | int status = -EPERM; |
| 3691 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3693 | if (server->auth_info.flavor_len > 0) { |
| 3694 | /* try each flavor specified by user */ |
| 3695 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3696 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3697 | server->auth_info.flavors[i]); |
| 3698 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3699 | continue; |
| 3700 | break; |
| 3701 | } |
| 3702 | } else { |
| 3703 | /* no flavors specified by user, try default list */ |
| 3704 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3705 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3706 | flav_array[i]); |
| 3707 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3708 | continue; |
| 3709 | break; |
| 3710 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3711 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3712 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3713 | /* |
| 3714 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3715 | * to access the mount. It could also mean that we tried to mount |
| 3716 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3717 | * existing mount programs don't handle -EACCES very well so it should |
| 3718 | * be mapped to -EPERM instead. |
| 3719 | */ |
| 3720 | if (status == -EACCES) |
| 3721 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3722 | return status; |
| 3723 | } |
| 3724 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3725 | /** |
| 3726 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3727 | * @server: initialized nfs_server handle |
| 3728 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3729 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3730 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3731 | * |
| 3732 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3733 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3734 | 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] | 3735 | struct nfs_fsinfo *info, |
| 3736 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3737 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3738 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3739 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3740 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3741 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3742 | |
| 3743 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3744 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3745 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | if (status == 0) |
| 3748 | status = nfs4_server_capabilities(server, fhandle); |
| 3749 | if (status == 0) |
| 3750 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3751 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3752 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | } |
| 3754 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3755 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3756 | struct nfs_fsinfo *info) |
| 3757 | { |
| 3758 | int error; |
| 3759 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3760 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3761 | |
| 3762 | error = nfs4_server_capabilities(server, mntfh); |
| 3763 | if (error < 0) { |
| 3764 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3765 | return error; |
| 3766 | } |
| 3767 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3768 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3769 | if (IS_ERR(label)) |
| 3770 | return PTR_ERR(label); |
| 3771 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3772 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3773 | if (error < 0) { |
| 3774 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3775 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3779 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3780 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3781 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3782 | err_free_label: |
| 3783 | nfs4_label_free(label); |
| 3784 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3785 | return error; |
| 3786 | } |
| 3787 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3788 | /* |
| 3789 | * Get locations and (maybe) other attributes of a referral. |
| 3790 | * Note that we'll actually follow the referral later when |
| 3791 | * we detect fsid mismatch in inode revalidation |
| 3792 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3793 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3794 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3795 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3796 | { |
| 3797 | int status = -ENOMEM; |
| 3798 | struct page *page = NULL; |
| 3799 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3800 | |
| 3801 | page = alloc_page(GFP_KERNEL); |
| 3802 | if (page == NULL) |
| 3803 | goto out; |
| 3804 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3805 | if (locations == NULL) |
| 3806 | goto out; |
| 3807 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3808 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3809 | if (status != 0) |
| 3810 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3811 | |
| 3812 | /* |
| 3813 | * If the fsid didn't change, this is a migration event, not a |
| 3814 | * referral. Cause us to drop into the exception handler, which |
| 3815 | * will kick off migration recovery. |
| 3816 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3817 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3818 | dprintk("%s: server did not return a different fsid for" |
| 3819 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3820 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3821 | goto out; |
| 3822 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3823 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3824 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3825 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3826 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3827 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3828 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3829 | out: |
| 3830 | if (page) |
| 3831 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3832 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3833 | return status; |
| 3834 | } |
| 3835 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3836 | 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] | 3837 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3838 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3840 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | struct nfs4_getattr_arg args = { |
| 3842 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3843 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | }; |
| 3845 | struct nfs4_getattr_res res = { |
| 3846 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3847 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | .server = server, |
| 3849 | }; |
| 3850 | struct rpc_message msg = { |
| 3851 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3852 | .rpc_argp = &args, |
| 3853 | .rpc_resp = &res, |
| 3854 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3855 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3856 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3857 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3858 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3859 | 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] | 3860 | } |
| 3861 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3862 | 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] | 3863 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3864 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | { |
| 3866 | struct nfs4_exception exception = { }; |
| 3867 | int err; |
| 3868 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3869 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3870 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3871 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | &exception); |
| 3873 | } while (exception.retry); |
| 3874 | return err; |
| 3875 | } |
| 3876 | |
| 3877 | /* |
| 3878 | * The file is not closed if it is opened due to the a request to change |
| 3879 | * the size of the file. The open call will not be needed once the |
| 3880 | * VFS layer lookup-intents are implemented. |
| 3881 | * |
| 3882 | * Close is called when the inode is destroyed. |
| 3883 | * If we haven't opened the file for O_WRONLY, we |
| 3884 | * need to in the size_change case to obtain a stateid. |
| 3885 | * |
| 3886 | * Got race? |
| 3887 | * Because OPEN is always done by name in nfsv4, it is |
| 3888 | * possible that we opened a different file by the same |
| 3889 | * name. We can recognize this race condition, but we |
| 3890 | * can't do anything about it besides returning an error. |
| 3891 | * |
| 3892 | * This will be fixed with VFS changes (lookup-intent). |
| 3893 | */ |
| 3894 | static int |
| 3895 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3896 | struct iattr *sattr) |
| 3897 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3898 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3899 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3900 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3901 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | int status; |
| 3903 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3904 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3905 | sattr->ia_valid & ATTR_SIZE && |
| 3906 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3907 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3908 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3909 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3911 | /* Deal with open(O_TRUNC) */ |
| 3912 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3913 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3914 | |
| 3915 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3916 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3917 | return 0; |
| 3918 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3919 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3920 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3921 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3922 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3923 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3924 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3925 | } |
| 3926 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3927 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3928 | if (IS_ERR(label)) |
| 3929 | return PTR_ERR(label); |
| 3930 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3931 | /* Return any delegations if we're going to change ACLs */ |
| 3932 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 3933 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3934 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3935 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3936 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3937 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3938 | nfs_setsecurity(inode, fattr, label); |
| 3939 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3940 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | return status; |
| 3942 | } |
| 3943 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3944 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3945 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3946 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3947 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3948 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3949 | int status; |
| 3950 | struct nfs4_lookup_arg args = { |
| 3951 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3952 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3953 | .name = name, |
| 3954 | }; |
| 3955 | struct nfs4_lookup_res res = { |
| 3956 | .server = server, |
| 3957 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3958 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3959 | .fh = fhandle, |
| 3960 | }; |
| 3961 | struct rpc_message msg = { |
| 3962 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3963 | .rpc_argp = &args, |
| 3964 | .rpc_resp = &res, |
| 3965 | }; |
| 3966 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3967 | args.bitmask = nfs4_bitmask(server, label); |
| 3968 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3969 | nfs_fattr_init(fattr); |
| 3970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3972 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | dprintk("NFS reply lookup: %d\n", status); |
| 3974 | return status; |
| 3975 | } |
| 3976 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3977 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3978 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3979 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3980 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3981 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3982 | fattr->nlink = 2; |
| 3983 | } |
| 3984 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3985 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3986 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3987 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3988 | { |
| 3989 | struct nfs4_exception exception = { }; |
| 3990 | struct rpc_clnt *client = *clnt; |
| 3991 | int err; |
| 3992 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3993 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3994 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3995 | switch (err) { |
| 3996 | case -NFS4ERR_BADNAME: |
| 3997 | err = -ENOENT; |
| 3998 | goto out; |
| 3999 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4000 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4001 | if (err == -NFS4ERR_MOVED) |
| 4002 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4003 | goto out; |
| 4004 | case -NFS4ERR_WRONGSEC: |
| 4005 | err = -EPERM; |
| 4006 | if (client != *clnt) |
| 4007 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4008 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4009 | if (IS_ERR(client)) |
| 4010 | return PTR_ERR(client); |
| 4011 | |
| 4012 | exception.retry = 1; |
| 4013 | break; |
| 4014 | default: |
| 4015 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4016 | } |
| 4017 | } while (exception.retry); |
| 4018 | |
| 4019 | out: |
| 4020 | if (err == 0) |
| 4021 | *clnt = client; |
| 4022 | else if (client != *clnt) |
| 4023 | rpc_shutdown_client(client); |
| 4024 | |
| 4025 | return err; |
| 4026 | } |
| 4027 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4028 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4029 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4030 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4032 | int status; |
| 4033 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4034 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4035 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4036 | if (client != NFS_CLIENT(dir)) { |
| 4037 | rpc_shutdown_client(client); |
| 4038 | nfs_fixup_secinfo_attributes(fattr); |
| 4039 | } |
| 4040 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4043 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4044 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4045 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4046 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4047 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4048 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4049 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4050 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4051 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4052 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4053 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4054 | } |
| 4055 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4056 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4057 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4058 | struct nfs4_label *label) |
| 4059 | { |
| 4060 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4061 | struct nfs_server *server = NFS_SERVER(inode); |
| 4062 | int status; |
| 4063 | struct nfs4_lookupp_arg args = { |
| 4064 | .bitmask = server->attr_bitmask, |
| 4065 | .fh = NFS_FH(inode), |
| 4066 | }; |
| 4067 | struct nfs4_lookupp_res res = { |
| 4068 | .server = server, |
| 4069 | .fattr = fattr, |
| 4070 | .label = label, |
| 4071 | .fh = fhandle, |
| 4072 | }; |
| 4073 | struct rpc_message msg = { |
| 4074 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4075 | .rpc_argp = &args, |
| 4076 | .rpc_resp = &res, |
| 4077 | }; |
| 4078 | |
| 4079 | args.bitmask = nfs4_bitmask(server, label); |
| 4080 | |
| 4081 | nfs_fattr_init(fattr); |
| 4082 | |
| 4083 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4084 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4085 | &res.seq_res, 0); |
| 4086 | dprintk("NFS reply lookupp: %d\n", status); |
| 4087 | return status; |
| 4088 | } |
| 4089 | |
| 4090 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4091 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4092 | { |
| 4093 | struct nfs4_exception exception = { }; |
| 4094 | int err; |
| 4095 | do { |
| 4096 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4097 | trace_nfs4_lookupp(inode, err); |
| 4098 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4099 | &exception); |
| 4100 | } while (exception.retry); |
| 4101 | return err; |
| 4102 | } |
| 4103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4105 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4106 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | struct nfs4_accessargs args = { |
| 4108 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4109 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4111 | struct nfs4_accessres res = { |
| 4112 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4113 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | struct rpc_message msg = { |
| 4115 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4116 | .rpc_argp = &args, |
| 4117 | .rpc_resp = &res, |
| 4118 | .rpc_cred = entry->cred, |
| 4119 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4120 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4122 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4123 | res.fattr = nfs_alloc_fattr(); |
| 4124 | if (res.fattr == NULL) |
| 4125 | return -ENOMEM; |
| 4126 | args.bitmask = server->cache_consistency_bitmask; |
| 4127 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4128 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4129 | 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] | 4130 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4131 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4132 | if (res.fattr) |
| 4133 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4135 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | return status; |
| 4137 | } |
| 4138 | |
| 4139 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4140 | { |
| 4141 | struct nfs4_exception exception = { }; |
| 4142 | int err; |
| 4143 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4144 | err = _nfs4_proc_access(inode, entry); |
| 4145 | trace_nfs4_access(inode, err); |
| 4146 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | &exception); |
| 4148 | } while (exception.retry); |
| 4149 | return err; |
| 4150 | } |
| 4151 | |
| 4152 | /* |
| 4153 | * TODO: For the time being, we don't try to get any attributes |
| 4154 | * along with any of the zero-copy operations READ, READDIR, |
| 4155 | * READLINK, WRITE. |
| 4156 | * |
| 4157 | * In the case of the first three, we want to put the GETATTR |
| 4158 | * after the read-type operation -- this is because it is hard |
| 4159 | * to predict the length of a GETATTR response in v4, and thus |
| 4160 | * align the READ data correctly. This means that the GETATTR |
| 4161 | * may end up partially falling into the page cache, and we should |
| 4162 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4163 | * To do this efficiently, we need to know the total length |
| 4164 | * of data received, which doesn't seem to be available outside |
| 4165 | * of the RPC layer. |
| 4166 | * |
| 4167 | * In the case of WRITE, we also want to put the GETATTR after |
| 4168 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4169 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | * |
| 4171 | * Both of these changes to the XDR layer would in fact be quite |
| 4172 | * minor, but I decided to leave them for a subsequent patch. |
| 4173 | */ |
| 4174 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4175 | unsigned int pgbase, unsigned int pglen) |
| 4176 | { |
| 4177 | struct nfs4_readlink args = { |
| 4178 | .fh = NFS_FH(inode), |
| 4179 | .pgbase = pgbase, |
| 4180 | .pglen = pglen, |
| 4181 | .pages = &page, |
| 4182 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4183 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | struct rpc_message msg = { |
| 4185 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4186 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4187 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | }; |
| 4189 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4190 | 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] | 4191 | } |
| 4192 | |
| 4193 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4194 | unsigned int pgbase, unsigned int pglen) |
| 4195 | { |
| 4196 | struct nfs4_exception exception = { }; |
| 4197 | int err; |
| 4198 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4199 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4200 | trace_nfs4_readlink(inode, err); |
| 4201 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | &exception); |
| 4203 | } while (exception.retry); |
| 4204 | return err; |
| 4205 | } |
| 4206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4208 | * 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] | 4209 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | static int |
| 4211 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4212 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4214 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4215 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4216 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | int status = 0; |
| 4219 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4220 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4221 | if (IS_ERR(ctx)) |
| 4222 | return PTR_ERR(ctx); |
| 4223 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4224 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4225 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4226 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4227 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4228 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | if (IS_ERR(state)) { |
| 4230 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4231 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4234 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4235 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | return status; |
| 4237 | } |
| 4238 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4239 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4241 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4242 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4244 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4246 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4247 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4248 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4250 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4251 | .rpc_argp = &args, |
| 4252 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4254 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4255 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4256 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4257 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4258 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4259 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | return status; |
| 4261 | } |
| 4262 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4263 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4264 | { |
| 4265 | struct nfs4_exception exception = { }; |
| 4266 | struct inode *inode = d_inode(dentry); |
| 4267 | int err; |
| 4268 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4269 | if (inode) { |
| 4270 | if (inode->i_nlink == 1) |
| 4271 | nfs4_inode_return_delegation(inode); |
| 4272 | else |
| 4273 | nfs4_inode_make_writeable(inode); |
| 4274 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4275 | do { |
| 4276 | err = _nfs4_proc_remove(dir, &dentry->d_name); |
| 4277 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4278 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4279 | &exception); |
| 4280 | } while (exception.retry); |
| 4281 | return err; |
| 4282 | } |
| 4283 | |
| 4284 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | { |
| 4286 | struct nfs4_exception exception = { }; |
| 4287 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4290 | err = _nfs4_proc_remove(dir, name); |
| 4291 | trace_nfs4_remove(dir, name, err); |
| 4292 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | &exception); |
| 4294 | } while (exception.retry); |
| 4295 | return err; |
| 4296 | } |
| 4297 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4298 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4299 | struct dentry *dentry, |
| 4300 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4302 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4303 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4305 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4307 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4308 | |
| 4309 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4310 | |
| 4311 | if (inode) |
| 4312 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4315 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4316 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4317 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4318 | &data->args.seq_args, |
| 4319 | &data->res.seq_res, |
| 4320 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4323 | 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] | 4324 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4325 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4326 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4327 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4328 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4329 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4330 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4331 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4332 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4333 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4334 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4335 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4338 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4339 | struct dentry *old_dentry, |
| 4340 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4341 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4342 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4343 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4344 | struct inode *old_inode = d_inode(old_dentry); |
| 4345 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4346 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4347 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4348 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4349 | if (new_inode) |
| 4350 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4351 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4352 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4353 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4354 | } |
| 4355 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4356 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4357 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4358 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4359 | &data->args.seq_args, |
| 4360 | &data->res.seq_res, |
| 4361 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4365 | struct inode *new_dir) |
| 4366 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4367 | struct nfs_renamedata *data = task->tk_calldata; |
| 4368 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4369 | |
| 4370 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4371 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4372 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4373 | return 0; |
| 4374 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4375 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4376 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4377 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4378 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4379 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4380 | return 1; |
| 4381 | } |
| 4382 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4383 | 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] | 4384 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4385 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4386 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | struct nfs4_link_arg arg = { |
| 4388 | .fh = NFS_FH(inode), |
| 4389 | .dir_fh = NFS_FH(dir), |
| 4390 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4391 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4393 | struct nfs4_link_res res = { |
| 4394 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4395 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4396 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | struct rpc_message msg = { |
| 4398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4399 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4400 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4402 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4404 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4405 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4406 | goto out; |
| 4407 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4408 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4409 | if (IS_ERR(res.label)) { |
| 4410 | status = PTR_ERR(res.label); |
| 4411 | goto out; |
| 4412 | } |
| 4413 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4414 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4415 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4416 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4417 | 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] | 4418 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4419 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4420 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4421 | if (!status) |
| 4422 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4423 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4424 | |
| 4425 | |
| 4426 | nfs4_label_free(res.label); |
| 4427 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4428 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4429 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | return status; |
| 4431 | } |
| 4432 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4433 | 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] | 4434 | { |
| 4435 | struct nfs4_exception exception = { }; |
| 4436 | int err; |
| 4437 | do { |
| 4438 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4439 | _nfs4_proc_link(inode, dir, name), |
| 4440 | &exception); |
| 4441 | } while (exception.retry); |
| 4442 | return err; |
| 4443 | } |
| 4444 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4445 | struct nfs4_createdata { |
| 4446 | struct rpc_message msg; |
| 4447 | struct nfs4_create_arg arg; |
| 4448 | struct nfs4_create_res res; |
| 4449 | struct nfs_fh fh; |
| 4450 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4451 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4452 | }; |
| 4453 | |
| 4454 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4455 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4456 | { |
| 4457 | struct nfs4_createdata *data; |
| 4458 | |
| 4459 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4460 | if (data != NULL) { |
| 4461 | struct nfs_server *server = NFS_SERVER(dir); |
| 4462 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4463 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4464 | if (IS_ERR(data->label)) |
| 4465 | goto out_free; |
| 4466 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4467 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4468 | data->msg.rpc_argp = &data->arg; |
| 4469 | data->msg.rpc_resp = &data->res; |
| 4470 | data->arg.dir_fh = NFS_FH(dir); |
| 4471 | data->arg.server = server; |
| 4472 | data->arg.name = name; |
| 4473 | data->arg.attrs = sattr; |
| 4474 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4475 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4476 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4477 | data->res.server = server; |
| 4478 | data->res.fh = &data->fh; |
| 4479 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4480 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4481 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4482 | } |
| 4483 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4484 | out_free: |
| 4485 | kfree(data); |
| 4486 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4490 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4491 | 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] | 4492 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4493 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4494 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4495 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4496 | 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] | 4497 | } |
| 4498 | return status; |
| 4499 | } |
| 4500 | |
| 4501 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4502 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4503 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4504 | kfree(data); |
| 4505 | } |
| 4506 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4507 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4508 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4509 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4511 | struct nfs4_createdata *data; |
| 4512 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4514 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4515 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4516 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4517 | status = -ENOMEM; |
| 4518 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4519 | if (data == NULL) |
| 4520 | goto out; |
| 4521 | |
| 4522 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4523 | data->arg.u.symlink.pages = &page; |
| 4524 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4525 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4527 | status = nfs4_do_create(dir, dentry, data); |
| 4528 | |
| 4529 | nfs4_free_createdata(data); |
| 4530 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | return status; |
| 4532 | } |
| 4533 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4534 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4535 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | { |
| 4537 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4538 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4540 | |
| 4541 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4544 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4545 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4546 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | &exception); |
| 4548 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4549 | |
| 4550 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | return err; |
| 4552 | } |
| 4553 | |
| 4554 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4555 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4557 | struct nfs4_createdata *data; |
| 4558 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4560 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4561 | if (data == NULL) |
| 4562 | goto out; |
| 4563 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4564 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4565 | status = nfs4_do_create(dir, dentry, data); |
| 4566 | |
| 4567 | nfs4_free_createdata(data); |
| 4568 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | return status; |
| 4570 | } |
| 4571 | |
| 4572 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4573 | struct iattr *sattr) |
| 4574 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4575 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4577 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4579 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4580 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4581 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4582 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4583 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4585 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4586 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4587 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | &exception); |
| 4589 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4590 | nfs4_label_release_security(label); |
| 4591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | return err; |
| 4593 | } |
| 4594 | |
| 4595 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4596 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4598 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | struct nfs4_readdir_arg args = { |
| 4600 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4601 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | .pgbase = 0, |
| 4603 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4604 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4605 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | }; |
| 4607 | struct nfs4_readdir_res res; |
| 4608 | struct rpc_message msg = { |
| 4609 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4610 | .rpc_argp = &args, |
| 4611 | .rpc_resp = &res, |
| 4612 | .rpc_cred = cred, |
| 4613 | }; |
| 4614 | int status; |
| 4615 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4616 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4617 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4618 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4619 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4621 | 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] | 4622 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4623 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4624 | status += args.pgbase; |
| 4625 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4626 | |
| 4627 | nfs_invalidate_atime(dir); |
| 4628 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4629 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | return status; |
| 4631 | } |
| 4632 | |
| 4633 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4634 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | { |
| 4636 | struct nfs4_exception exception = { }; |
| 4637 | int err; |
| 4638 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4639 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4640 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4641 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4642 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | &exception); |
| 4644 | } while (exception.retry); |
| 4645 | return err; |
| 4646 | } |
| 4647 | |
| 4648 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4649 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4651 | struct nfs4_createdata *data; |
| 4652 | int mode = sattr->ia_mode; |
| 4653 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4655 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4656 | if (data == NULL) |
| 4657 | goto out; |
| 4658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4660 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4662 | data->arg.ftype = NF4BLK; |
| 4663 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4664 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | } |
| 4666 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4667 | data->arg.ftype = NF4CHR; |
| 4668 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4669 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4670 | } else if (!S_ISSOCK(mode)) { |
| 4671 | status = -EINVAL; |
| 4672 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4674 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4675 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4676 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4677 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4678 | nfs4_free_createdata(data); |
| 4679 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | return status; |
| 4681 | } |
| 4682 | |
| 4683 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4684 | struct iattr *sattr, dev_t rdev) |
| 4685 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4686 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4688 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4690 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4691 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4692 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4693 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4694 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4696 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4697 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4698 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | &exception); |
| 4700 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4701 | |
| 4702 | nfs4_label_release_security(label); |
| 4703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | return err; |
| 4705 | } |
| 4706 | |
| 4707 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4708 | struct nfs_fsstat *fsstat) |
| 4709 | { |
| 4710 | struct nfs4_statfs_arg args = { |
| 4711 | .fh = fhandle, |
| 4712 | .bitmask = server->attr_bitmask, |
| 4713 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4714 | struct nfs4_statfs_res res = { |
| 4715 | .fsstat = fsstat, |
| 4716 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | struct rpc_message msg = { |
| 4718 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4719 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4720 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | }; |
| 4722 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4723 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4724 | 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] | 4725 | } |
| 4726 | |
| 4727 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4728 | { |
| 4729 | struct nfs4_exception exception = { }; |
| 4730 | int err; |
| 4731 | do { |
| 4732 | err = nfs4_handle_exception(server, |
| 4733 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4734 | &exception); |
| 4735 | } while (exception.retry); |
| 4736 | return err; |
| 4737 | } |
| 4738 | |
| 4739 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4740 | struct nfs_fsinfo *fsinfo) |
| 4741 | { |
| 4742 | struct nfs4_fsinfo_arg args = { |
| 4743 | .fh = fhandle, |
| 4744 | .bitmask = server->attr_bitmask, |
| 4745 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4746 | struct nfs4_fsinfo_res res = { |
| 4747 | .fsinfo = fsinfo, |
| 4748 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | struct rpc_message msg = { |
| 4750 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4751 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4752 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | }; |
| 4754 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4755 | 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] | 4756 | } |
| 4757 | |
| 4758 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4759 | { |
| 4760 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4761 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | int err; |
| 4763 | |
| 4764 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4765 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4766 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4767 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4768 | nfs4_set_lease_period(server->nfs_client, |
| 4769 | fsinfo->lease_time * HZ, |
| 4770 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4771 | break; |
| 4772 | } |
| 4773 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | } while (exception.retry); |
| 4775 | return err; |
| 4776 | } |
| 4777 | |
| 4778 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4779 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4780 | int error; |
| 4781 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4782 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4783 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4784 | if (error == 0) { |
| 4785 | /* block layout checks this! */ |
| 4786 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4787 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4788 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4789 | |
| 4790 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4794 | struct nfs_pathconf *pathconf) |
| 4795 | { |
| 4796 | struct nfs4_pathconf_arg args = { |
| 4797 | .fh = fhandle, |
| 4798 | .bitmask = server->attr_bitmask, |
| 4799 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4800 | struct nfs4_pathconf_res res = { |
| 4801 | .pathconf = pathconf, |
| 4802 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | struct rpc_message msg = { |
| 4804 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4805 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4806 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | }; |
| 4808 | |
| 4809 | /* None of the pathconf attributes are mandatory to implement */ |
| 4810 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4811 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4812 | return 0; |
| 4813 | } |
| 4814 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4815 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4816 | 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] | 4817 | } |
| 4818 | |
| 4819 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4820 | struct nfs_pathconf *pathconf) |
| 4821 | { |
| 4822 | struct nfs4_exception exception = { }; |
| 4823 | int err; |
| 4824 | |
| 4825 | do { |
| 4826 | err = nfs4_handle_exception(server, |
| 4827 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4828 | &exception); |
| 4829 | } while (exception.retry); |
| 4830 | return err; |
| 4831 | } |
| 4832 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4833 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4834 | const struct nfs_open_context *ctx, |
| 4835 | const struct nfs_lock_context *l_ctx, |
| 4836 | fmode_t fmode) |
| 4837 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4838 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4839 | } |
| 4840 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4841 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4842 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4843 | const struct nfs_open_context *ctx, |
| 4844 | const struct nfs_lock_context *l_ctx, |
| 4845 | fmode_t fmode) |
| 4846 | { |
| 4847 | nfs4_stateid current_stateid; |
| 4848 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4849 | /* If the current stateid represents a lost lock, then exit */ |
| 4850 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4851 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4852 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4853 | } |
| 4854 | |
| 4855 | static bool nfs4_error_stateid_expired(int err) |
| 4856 | { |
| 4857 | switch (err) { |
| 4858 | case -NFS4ERR_DELEG_REVOKED: |
| 4859 | case -NFS4ERR_ADMIN_REVOKED: |
| 4860 | case -NFS4ERR_BAD_STATEID: |
| 4861 | case -NFS4ERR_STALE_STATEID: |
| 4862 | case -NFS4ERR_OLD_STATEID: |
| 4863 | case -NFS4ERR_OPENMODE: |
| 4864 | case -NFS4ERR_EXPIRED: |
| 4865 | return true; |
| 4866 | } |
| 4867 | return false; |
| 4868 | } |
| 4869 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4870 | 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] | 4871 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4872 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4874 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4875 | if (task->tk_status < 0) { |
| 4876 | struct nfs4_exception exception = { |
| 4877 | .inode = hdr->inode, |
| 4878 | .state = hdr->args.context->state, |
| 4879 | .stateid = &hdr->args.stateid, |
| 4880 | }; |
| 4881 | task->tk_status = nfs4_async_handle_exception(task, |
| 4882 | server, task->tk_status, &exception); |
| 4883 | if (exception.retry) { |
| 4884 | rpc_restart_call_prepare(task); |
| 4885 | return -EAGAIN; |
| 4886 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4890 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4891 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | } |
| 4893 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4894 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4895 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4896 | { |
| 4897 | |
| 4898 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4899 | nfs4_stateid_is_current(&args->stateid, |
| 4900 | args->context, |
| 4901 | args->lock_context, |
| 4902 | FMODE_READ)) |
| 4903 | return false; |
| 4904 | rpc_restart_call_prepare(task); |
| 4905 | return true; |
| 4906 | } |
| 4907 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4908 | 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] | 4909 | { |
| 4910 | |
| 4911 | dprintk("--> %s\n", __func__); |
| 4912 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4913 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4914 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4915 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4916 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4917 | if (task->tk_status > 0) |
| 4918 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4919 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4920 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4923 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4924 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4926 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4927 | if (!hdr->pgio_done_cb) |
| 4928 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4929 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4930 | 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] | 4931 | } |
| 4932 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4933 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4934 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4935 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4936 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4937 | &hdr->args.seq_args, |
| 4938 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4939 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4940 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4941 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4942 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4943 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4944 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4945 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4946 | return -EIO; |
| 4947 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | } |
| 4949 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4950 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4951 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4953 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4954 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4955 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4956 | if (task->tk_status < 0) { |
| 4957 | struct nfs4_exception exception = { |
| 4958 | .inode = hdr->inode, |
| 4959 | .state = hdr->args.context->state, |
| 4960 | .stateid = &hdr->args.stateid, |
| 4961 | }; |
| 4962 | task->tk_status = nfs4_async_handle_exception(task, |
| 4963 | NFS_SERVER(inode), task->tk_status, |
| 4964 | &exception); |
| 4965 | if (exception.retry) { |
| 4966 | rpc_restart_call_prepare(task); |
| 4967 | return -EAGAIN; |
| 4968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4970 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4971 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4972 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4973 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4974 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4977 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4978 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4979 | { |
| 4980 | |
| 4981 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4982 | nfs4_stateid_is_current(&args->stateid, |
| 4983 | args->context, |
| 4984 | args->lock_context, |
| 4985 | FMODE_WRITE)) |
| 4986 | return false; |
| 4987 | rpc_restart_call_prepare(task); |
| 4988 | return true; |
| 4989 | } |
| 4990 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4991 | 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] | 4992 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4993 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4994 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4995 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4996 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4997 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4998 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4999 | } |
| 5000 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5001 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5002 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5003 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5004 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5005 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5006 | return false; |
| 5007 | /* Otherwise, request attributes if and only if we don't hold |
| 5008 | * a delegation |
| 5009 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5010 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5011 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5012 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5013 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5014 | struct rpc_message *msg, |
| 5015 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5017 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5018 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5019 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5020 | hdr->args.bitmask = NULL; |
| 5021 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5022 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5023 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5024 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5025 | if (!hdr->pgio_done_cb) |
| 5026 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5027 | hdr->res.server = server; |
| 5028 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5030 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5031 | 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] | 5032 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | } |
| 5034 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5035 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5036 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5037 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5038 | &data->args.seq_args, |
| 5039 | &data->res.seq_res, |
| 5040 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | } |
| 5042 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5043 | 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] | 5044 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5046 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5047 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5048 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5049 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5050 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5051 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5053 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5056 | 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] | 5057 | { |
| 5058 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5059 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5060 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5063 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5064 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5066 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5067 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5068 | if (data->commit_done_cb == NULL) |
| 5069 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5070 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5071 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5072 | 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] | 5073 | 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] | 5074 | } |
| 5075 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5076 | struct nfs4_renewdata { |
| 5077 | struct nfs_client *client; |
| 5078 | unsigned long timestamp; |
| 5079 | }; |
| 5080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | /* |
| 5082 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5083 | * standalone procedure for queueing an asynchronous RENEW. |
| 5084 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5085 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5086 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5087 | struct nfs4_renewdata *data = calldata; |
| 5088 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5089 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5090 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5091 | nfs4_schedule_state_renewal(clp); |
| 5092 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5093 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5094 | } |
| 5095 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5096 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5098 | struct nfs4_renewdata *data = calldata; |
| 5099 | struct nfs_client *clp = data->client; |
| 5100 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5102 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5103 | switch (task->tk_status) { |
| 5104 | case 0: |
| 5105 | break; |
| 5106 | case -NFS4ERR_LEASE_MOVED: |
| 5107 | nfs4_schedule_lease_moved_recovery(clp); |
| 5108 | break; |
| 5109 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5110 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5111 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5112 | return; |
| 5113 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5114 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5115 | return; |
| 5116 | } |
| 5117 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5119 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5122 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5123 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5124 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5125 | }; |
| 5126 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5127 | static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | { |
| 5129 | struct rpc_message msg = { |
| 5130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5131 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5132 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5134 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5135 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5136 | if (renew_flags == 0) |
| 5137 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5138 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5139 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5140 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5141 | if (data == NULL) { |
| 5142 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5143 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5144 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5145 | data->client = clp; |
| 5146 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5147 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5148 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5151 | static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | { |
| 5153 | struct rpc_message msg = { |
| 5154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5155 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5156 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | }; |
| 5158 | unsigned long now = jiffies; |
| 5159 | int status; |
| 5160 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5161 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | if (status < 0) |
| 5163 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5164 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | return 0; |
| 5166 | } |
| 5167 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5168 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5169 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5170 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5173 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5174 | * 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] | 5175 | * the stack. |
| 5176 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5177 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5178 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5179 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5180 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5181 | { |
| 5182 | struct page *newpage, **spages; |
| 5183 | int rc = 0; |
| 5184 | size_t len; |
| 5185 | spages = pages; |
| 5186 | |
| 5187 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5188 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5189 | newpage = alloc_page(GFP_KERNEL); |
| 5190 | |
| 5191 | if (newpage == NULL) |
| 5192 | goto unwind; |
| 5193 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5194 | buf += len; |
| 5195 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5196 | *pages++ = newpage; |
| 5197 | rc++; |
| 5198 | } while (buflen != 0); |
| 5199 | |
| 5200 | return rc; |
| 5201 | |
| 5202 | unwind: |
| 5203 | for(; rc > 0; rc--) |
| 5204 | __free_page(spages[rc-1]); |
| 5205 | return -ENOMEM; |
| 5206 | } |
| 5207 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5208 | struct nfs4_cached_acl { |
| 5209 | int cached; |
| 5210 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5211 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5212 | }; |
| 5213 | |
| 5214 | 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] | 5215 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5216 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5217 | |
| 5218 | spin_lock(&inode->i_lock); |
| 5219 | kfree(nfsi->nfs4_acl); |
| 5220 | nfsi->nfs4_acl = acl; |
| 5221 | spin_unlock(&inode->i_lock); |
| 5222 | } |
| 5223 | |
| 5224 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5225 | { |
| 5226 | nfs4_set_cached_acl(inode, NULL); |
| 5227 | } |
| 5228 | |
| 5229 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5230 | { |
| 5231 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5232 | struct nfs4_cached_acl *acl; |
| 5233 | int ret = -ENOENT; |
| 5234 | |
| 5235 | spin_lock(&inode->i_lock); |
| 5236 | acl = nfsi->nfs4_acl; |
| 5237 | if (acl == NULL) |
| 5238 | goto out; |
| 5239 | if (buf == NULL) /* user is just asking for length */ |
| 5240 | goto out_len; |
| 5241 | if (acl->cached == 0) |
| 5242 | goto out; |
| 5243 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5244 | if (acl->len > buflen) |
| 5245 | goto out; |
| 5246 | memcpy(buf, acl->data, acl->len); |
| 5247 | out_len: |
| 5248 | ret = acl->len; |
| 5249 | out: |
| 5250 | spin_unlock(&inode->i_lock); |
| 5251 | return ret; |
| 5252 | } |
| 5253 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5254 | 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] | 5255 | { |
| 5256 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5257 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5258 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5259 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5260 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5261 | if (acl == NULL) |
| 5262 | goto out; |
| 5263 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5264 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5265 | } else { |
| 5266 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5267 | if (acl == NULL) |
| 5268 | goto out; |
| 5269 | acl->cached = 0; |
| 5270 | } |
| 5271 | acl->len = acl_len; |
| 5272 | out: |
| 5273 | nfs4_set_cached_acl(inode, acl); |
| 5274 | } |
| 5275 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5276 | /* |
| 5277 | * The getxattr API returns the required buffer length when called with a |
| 5278 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5279 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5280 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5281 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5282 | * the cache. If not so, we throw away the page, and cache the required |
| 5283 | * length. The next getxattr call will then produce another round trip to |
| 5284 | * the server, this time with the input buf of the required size. |
| 5285 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5286 | 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] | 5287 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5288 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5289 | struct nfs_getaclargs args = { |
| 5290 | .fh = NFS_FH(inode), |
| 5291 | .acl_pages = pages, |
| 5292 | .acl_len = buflen, |
| 5293 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5294 | struct nfs_getaclres res = { |
| 5295 | .acl_len = buflen, |
| 5296 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5297 | struct rpc_message msg = { |
| 5298 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5299 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5300 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5301 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5302 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5303 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5304 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5305 | if (npages > ARRAY_SIZE(pages)) |
| 5306 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5307 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5308 | for (i = 0; i < npages; i++) { |
| 5309 | pages[i] = alloc_page(GFP_KERNEL); |
| 5310 | if (!pages[i]) |
| 5311 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5312 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5313 | |
| 5314 | /* for decoding across pages */ |
| 5315 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5316 | if (!res.acl_scratch) |
| 5317 | goto out_free; |
| 5318 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5319 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5320 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5321 | 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] | 5322 | __func__, buf, buflen, npages, args.acl_len); |
| 5323 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5324 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5325 | if (ret) |
| 5326 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5327 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5328 | /* Handle the case where the passed-in buffer is too short */ |
| 5329 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5330 | /* Did the user only issue a request for the acl length? */ |
| 5331 | if (buf == NULL) |
| 5332 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5333 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5334 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5335 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5336 | 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] | 5337 | if (buf) { |
| 5338 | if (res.acl_len > buflen) { |
| 5339 | ret = -ERANGE; |
| 5340 | goto out_free; |
| 5341 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5342 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5343 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5344 | out_ok: |
| 5345 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5346 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5347 | for (i = 0; i < npages; i++) |
| 5348 | if (pages[i]) |
| 5349 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5350 | if (res.acl_scratch) |
| 5351 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5352 | return ret; |
| 5353 | } |
| 5354 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5355 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5356 | { |
| 5357 | struct nfs4_exception exception = { }; |
| 5358 | ssize_t ret; |
| 5359 | do { |
| 5360 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5361 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5362 | if (ret >= 0) |
| 5363 | break; |
| 5364 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5365 | } while (exception.retry); |
| 5366 | return ret; |
| 5367 | } |
| 5368 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5369 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5370 | { |
| 5371 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5372 | int ret; |
| 5373 | |
| 5374 | if (!nfs4_server_supports_acls(server)) |
| 5375 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5376 | ret = nfs_revalidate_inode(server, inode); |
| 5377 | if (ret < 0) |
| 5378 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5379 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5380 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5381 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5382 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5383 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5384 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5385 | return ret; |
| 5386 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5387 | } |
| 5388 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5389 | 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] | 5390 | { |
| 5391 | struct nfs_server *server = NFS_SERVER(inode); |
| 5392 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5393 | struct nfs_setaclargs arg = { |
| 5394 | .fh = NFS_FH(inode), |
| 5395 | .acl_pages = pages, |
| 5396 | .acl_len = buflen, |
| 5397 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5398 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5399 | struct rpc_message msg = { |
| 5400 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5401 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5402 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5403 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5404 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5405 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5406 | |
| 5407 | if (!nfs4_server_supports_acls(server)) |
| 5408 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5409 | if (npages > ARRAY_SIZE(pages)) |
| 5410 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5411 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5412 | if (i < 0) |
| 5413 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5414 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5415 | 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] | 5416 | |
| 5417 | /* |
| 5418 | * Free each page after tx, so the only ref left is |
| 5419 | * held by the network stack |
| 5420 | */ |
| 5421 | for (; i > 0; i--) |
| 5422 | put_page(pages[i-1]); |
| 5423 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5424 | /* |
| 5425 | * Acl update can result in inode attribute update. |
| 5426 | * so mark the attribute cache invalid. |
| 5427 | */ |
| 5428 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5429 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5430 | | NFS_INO_INVALID_CTIME |
| 5431 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5432 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5433 | nfs_access_zap_cache(inode); |
| 5434 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5435 | return ret; |
| 5436 | } |
| 5437 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5438 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5439 | { |
| 5440 | struct nfs4_exception exception = { }; |
| 5441 | int err; |
| 5442 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5443 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5444 | trace_nfs4_set_acl(inode, err); |
| 5445 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5446 | &exception); |
| 5447 | } while (exception.retry); |
| 5448 | return err; |
| 5449 | } |
| 5450 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5451 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5452 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5453 | size_t buflen) |
| 5454 | { |
| 5455 | struct nfs_server *server = NFS_SERVER(inode); |
| 5456 | struct nfs_fattr fattr; |
| 5457 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5458 | |
| 5459 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5460 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5461 | .fh = NFS_FH(inode), |
| 5462 | .bitmask = bitmask, |
| 5463 | }; |
| 5464 | struct nfs4_getattr_res res = { |
| 5465 | .fattr = &fattr, |
| 5466 | .label = &label, |
| 5467 | .server = server, |
| 5468 | }; |
| 5469 | struct rpc_message msg = { |
| 5470 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5471 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5472 | .rpc_resp = &res, |
| 5473 | }; |
| 5474 | int ret; |
| 5475 | |
| 5476 | nfs_fattr_init(&fattr); |
| 5477 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5478 | 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] | 5479 | if (ret) |
| 5480 | return ret; |
| 5481 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5482 | return -ENOENT; |
| 5483 | if (buflen < label.len) |
| 5484 | return -ERANGE; |
| 5485 | return 0; |
| 5486 | } |
| 5487 | |
| 5488 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5489 | size_t buflen) |
| 5490 | { |
| 5491 | struct nfs4_exception exception = { }; |
| 5492 | int err; |
| 5493 | |
| 5494 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5495 | return -EOPNOTSUPP; |
| 5496 | |
| 5497 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5498 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5499 | trace_nfs4_get_security_label(inode, err); |
| 5500 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5501 | &exception); |
| 5502 | } while (exception.retry); |
| 5503 | return err; |
| 5504 | } |
| 5505 | |
| 5506 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5507 | struct nfs4_label *ilabel, |
| 5508 | struct nfs_fattr *fattr, |
| 5509 | struct nfs4_label *olabel) |
| 5510 | { |
| 5511 | |
| 5512 | struct iattr sattr = {0}; |
| 5513 | struct nfs_server *server = NFS_SERVER(inode); |
| 5514 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5515 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5516 | .fh = NFS_FH(inode), |
| 5517 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5518 | .server = server, |
| 5519 | .bitmask = bitmask, |
| 5520 | .label = ilabel, |
| 5521 | }; |
| 5522 | struct nfs_setattrres res = { |
| 5523 | .fattr = fattr, |
| 5524 | .label = olabel, |
| 5525 | .server = server, |
| 5526 | }; |
| 5527 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5528 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5529 | .rpc_argp = &arg, |
| 5530 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5531 | }; |
| 5532 | int status; |
| 5533 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5534 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5535 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5536 | 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] | 5537 | if (status) |
| 5538 | dprintk("%s failed: %d\n", __func__, status); |
| 5539 | |
| 5540 | return status; |
| 5541 | } |
| 5542 | |
| 5543 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5544 | struct nfs4_label *ilabel, |
| 5545 | struct nfs_fattr *fattr, |
| 5546 | struct nfs4_label *olabel) |
| 5547 | { |
| 5548 | struct nfs4_exception exception = { }; |
| 5549 | int err; |
| 5550 | |
| 5551 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5552 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5553 | fattr, olabel); |
| 5554 | trace_nfs4_set_security_label(inode, err); |
| 5555 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5556 | &exception); |
| 5557 | } while (exception.retry); |
| 5558 | return err; |
| 5559 | } |
| 5560 | |
| 5561 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5562 | 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] | 5563 | { |
| 5564 | struct nfs4_label ilabel, *olabel = NULL; |
| 5565 | struct nfs_fattr fattr; |
| 5566 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5567 | int status; |
| 5568 | |
| 5569 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5570 | return -EOPNOTSUPP; |
| 5571 | |
| 5572 | nfs_fattr_init(&fattr); |
| 5573 | |
| 5574 | ilabel.pi = 0; |
| 5575 | ilabel.lfs = 0; |
| 5576 | ilabel.label = (char *)buf; |
| 5577 | ilabel.len = buflen; |
| 5578 | |
| 5579 | cred = rpc_lookup_cred(); |
| 5580 | if (IS_ERR(cred)) |
| 5581 | return PTR_ERR(cred); |
| 5582 | |
| 5583 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5584 | if (IS_ERR(olabel)) { |
| 5585 | status = -PTR_ERR(olabel); |
| 5586 | goto out; |
| 5587 | } |
| 5588 | |
| 5589 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5590 | if (status == 0) |
| 5591 | nfs_setsecurity(inode, &fattr, olabel); |
| 5592 | |
| 5593 | nfs4_label_free(olabel); |
| 5594 | out: |
| 5595 | put_rpccred(cred); |
| 5596 | return status; |
| 5597 | } |
| 5598 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5599 | |
| 5600 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5601 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5602 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5603 | { |
| 5604 | __be32 verf[2]; |
| 5605 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5606 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5607 | /* An impossible timestamp guarantees this value |
| 5608 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5609 | verf[0] = cpu_to_be32(U32_MAX); |
| 5610 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5611 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5612 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5613 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5614 | |
| 5615 | verf[0] = cpu_to_be32(ns >> 32); |
| 5616 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5617 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5618 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5619 | } |
| 5620 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5621 | static int |
| 5622 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5623 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5624 | size_t len; |
| 5625 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5626 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5627 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5628 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5629 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5630 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5631 | len = 14 + |
| 5632 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5633 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5634 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5635 | 1; |
| 5636 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5637 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5638 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5639 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5640 | return -EINVAL; |
| 5641 | |
| 5642 | /* |
| 5643 | * Since this string is allocated at mount time, and held until the |
| 5644 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5645 | * about a memory-reclaim deadlock. |
| 5646 | */ |
| 5647 | str = kmalloc(len, GFP_KERNEL); |
| 5648 | if (!str) |
| 5649 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5650 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5651 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5652 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5653 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5654 | clp->cl_rpcclient->cl_nodename, |
| 5655 | nfs4_client_id_uniquifier, |
| 5656 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5657 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5658 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5659 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5660 | clp->cl_rpcclient->cl_nodename, |
| 5661 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5662 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5663 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5664 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5665 | clp->cl_owner_id = str; |
| 5666 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5667 | } |
| 5668 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5669 | static int |
| 5670 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5671 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5672 | size_t len; |
| 5673 | char *str; |
| 5674 | |
| 5675 | len = 10 + 10 + 1 + 10 + 1 + |
| 5676 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5677 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5678 | |
| 5679 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5680 | return -EINVAL; |
| 5681 | |
| 5682 | /* |
| 5683 | * Since this string is allocated at mount time, and held until the |
| 5684 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5685 | * about a memory-reclaim deadlock. |
| 5686 | */ |
| 5687 | str = kmalloc(len, GFP_KERNEL); |
| 5688 | if (!str) |
| 5689 | return -ENOMEM; |
| 5690 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5691 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5692 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5693 | nfs4_client_id_uniquifier, |
| 5694 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5695 | clp->cl_owner_id = str; |
| 5696 | return 0; |
| 5697 | } |
| 5698 | |
| 5699 | static int |
| 5700 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5701 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5702 | size_t len; |
| 5703 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5704 | |
| 5705 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5706 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5707 | |
| 5708 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5709 | return nfs4_init_uniquifier_client_string(clp); |
| 5710 | |
| 5711 | len = 10 + 10 + 1 + 10 + 1 + |
| 5712 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5713 | |
| 5714 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5715 | return -EINVAL; |
| 5716 | |
| 5717 | /* |
| 5718 | * Since this string is allocated at mount time, and held until the |
| 5719 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5720 | * about a memory-reclaim deadlock. |
| 5721 | */ |
| 5722 | str = kmalloc(len, GFP_KERNEL); |
| 5723 | if (!str) |
| 5724 | return -ENOMEM; |
| 5725 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5726 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5727 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5728 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5729 | clp->cl_owner_id = str; |
| 5730 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5731 | } |
| 5732 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5733 | /* |
| 5734 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5735 | * services. Advertise one based on the address family of the |
| 5736 | * clientaddr. |
| 5737 | */ |
| 5738 | static unsigned int |
| 5739 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5740 | { |
| 5741 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5742 | return scnprintf(buf, len, "tcp6"); |
| 5743 | else |
| 5744 | return scnprintf(buf, len, "tcp"); |
| 5745 | } |
| 5746 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5747 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5748 | { |
| 5749 | struct nfs4_setclientid *sc = calldata; |
| 5750 | |
| 5751 | if (task->tk_status == 0) |
| 5752 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5753 | } |
| 5754 | |
| 5755 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5756 | .rpc_call_done = nfs4_setclientid_done, |
| 5757 | }; |
| 5758 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5759 | /** |
| 5760 | * nfs4_proc_setclientid - Negotiate client ID |
| 5761 | * @clp: state data structure |
| 5762 | * @program: RPC program for NFSv4 callback service |
| 5763 | * @port: IP port number for NFS4 callback service |
| 5764 | * @cred: RPC credential to use for this call |
| 5765 | * @res: where to place the result |
| 5766 | * |
| 5767 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5768 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5769 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5770 | unsigned short port, struct rpc_cred *cred, |
| 5771 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5772 | { |
| 5773 | nfs4_verifier sc_verifier; |
| 5774 | struct nfs4_setclientid setclientid = { |
| 5775 | .sc_verifier = &sc_verifier, |
| 5776 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5777 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5778 | }; |
| 5779 | struct rpc_message msg = { |
| 5780 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5781 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5782 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5783 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5785 | struct rpc_task *task; |
| 5786 | struct rpc_task_setup task_setup_data = { |
| 5787 | .rpc_client = clp->cl_rpcclient, |
| 5788 | .rpc_message = &msg, |
| 5789 | .callback_ops = &nfs4_setclientid_ops, |
| 5790 | .callback_data = &setclientid, |
| 5791 | .flags = RPC_TASK_TIMEOUT, |
| 5792 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5793 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5795 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5796 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5797 | |
| 5798 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5799 | status = nfs4_init_uniform_client_string(clp); |
| 5800 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5801 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5802 | |
| 5803 | if (status) |
| 5804 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5805 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5806 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5807 | setclientid.sc_netid_len = |
| 5808 | nfs4_init_callback_netid(clp, |
| 5809 | setclientid.sc_netid, |
| 5810 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5811 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5812 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5814 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5815 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5816 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5817 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5818 | task = rpc_run_task(&task_setup_data); |
| 5819 | if (IS_ERR(task)) { |
| 5820 | status = PTR_ERR(task); |
| 5821 | goto out; |
| 5822 | } |
| 5823 | status = task->tk_status; |
| 5824 | if (setclientid.sc_cred) { |
| 5825 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5826 | put_rpccred(setclientid.sc_cred); |
| 5827 | } |
| 5828 | rpc_put_task(task); |
| 5829 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5830 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5831 | dprintk("NFS reply setclientid: %d\n", status); |
| 5832 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5835 | /** |
| 5836 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5837 | * @clp: state data structure |
| 5838 | * @res: result of a previous SETCLIENTID |
| 5839 | * @cred: RPC credential to use for this call |
| 5840 | * |
| 5841 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5842 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5843 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5844 | struct nfs4_setclientid_res *arg, |
| 5845 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5846 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | struct rpc_message msg = { |
| 5848 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5849 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5850 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5851 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5852 | int status; |
| 5853 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5854 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5855 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5856 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5857 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5858 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5859 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5860 | return status; |
| 5861 | } |
| 5862 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5863 | struct nfs4_delegreturndata { |
| 5864 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5865 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5866 | struct nfs_fh fh; |
| 5867 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5868 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5869 | struct { |
| 5870 | struct nfs4_layoutreturn_args arg; |
| 5871 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5872 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5873 | u32 roc_barrier; |
| 5874 | bool roc; |
| 5875 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5876 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5877 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5878 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5879 | }; |
| 5880 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5881 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5882 | { |
| 5883 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5884 | struct nfs4_exception exception = { |
| 5885 | .inode = data->inode, |
| 5886 | .stateid = &data->stateid, |
| 5887 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5888 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5889 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5890 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5891 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5892 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5893 | |
| 5894 | /* Handle Layoutreturn errors */ |
| 5895 | if (data->args.lr_args && task->tk_status != 0) { |
| 5896 | switch(data->res.lr_ret) { |
| 5897 | default: |
| 5898 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5899 | break; |
| 5900 | case 0: |
| 5901 | data->args.lr_args = NULL; |
| 5902 | data->res.lr_res = NULL; |
| 5903 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5904 | case -NFS4ERR_OLD_STATEID: |
| 5905 | if (nfs4_refresh_layout_stateid(&data->args.lr_args->stateid, |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5906 | data->inode)) |
| 5907 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5908 | /* Fallthrough */ |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5909 | case -NFS4ERR_ADMIN_REVOKED: |
| 5910 | case -NFS4ERR_DELEG_REVOKED: |
| 5911 | case -NFS4ERR_EXPIRED: |
| 5912 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5913 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5914 | case -NFS4ERR_WRONG_CRED: |
| 5915 | data->args.lr_args = NULL; |
| 5916 | data->res.lr_res = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5917 | goto lr_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5918 | } |
| 5919 | } |
| 5920 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5921 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5922 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5923 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5924 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5925 | case -NFS4ERR_ADMIN_REVOKED: |
| 5926 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5927 | case -NFS4ERR_EXPIRED: |
| 5928 | nfs4_free_revoked_stateid(data->res.server, |
| 5929 | data->args.stateid, |
| 5930 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5931 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5932 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5933 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5934 | task->tk_status = 0; |
| 5935 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5936 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5937 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 5938 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5939 | task->tk_status = 0; |
| 5940 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5941 | case -NFS4ERR_ACCESS: |
| 5942 | if (data->args.bitmask) { |
| 5943 | data->args.bitmask = NULL; |
| 5944 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5945 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5946 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5947 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5948 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5949 | task->tk_status = nfs4_async_handle_exception(task, |
| 5950 | data->res.server, task->tk_status, |
| 5951 | &exception); |
| 5952 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5953 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5954 | } |
| 5955 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5956 | return; |
| 5957 | lr_restart: |
| 5958 | data->res.lr_ret = 0; |
| 5959 | out_restart: |
| 5960 | task->tk_status = 0; |
| 5961 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | static void nfs4_delegreturn_release(void *calldata) |
| 5965 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5966 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5967 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5968 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5969 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5970 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5971 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5972 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5973 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5974 | nfs_iput_and_deactive(inode); |
| 5975 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5976 | kfree(calldata); |
| 5977 | } |
| 5978 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5979 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5980 | { |
| 5981 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame^] | 5982 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5983 | |
| 5984 | d_data = (struct nfs4_delegreturndata *)data; |
| 5985 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5986 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5987 | return; |
| 5988 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame^] | 5989 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 5990 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 5991 | d_data->args.lr_args = NULL; |
| 5992 | d_data->res.lr_res = NULL; |
| 5993 | } |
| 5994 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5995 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5996 | &d_data->args.seq_args, |
| 5997 | &d_data->res.seq_res, |
| 5998 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5999 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6000 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6001 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6002 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6003 | .rpc_call_done = nfs4_delegreturn_done, |
| 6004 | .rpc_release = nfs4_delegreturn_release, |
| 6005 | }; |
| 6006 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6007 | static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6008 | { |
| 6009 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6010 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6011 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6012 | struct rpc_message msg = { |
| 6013 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6014 | .rpc_cred = cred, |
| 6015 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6016 | struct rpc_task_setup task_setup_data = { |
| 6017 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6018 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6019 | .callback_ops = &nfs4_delegreturn_ops, |
| 6020 | .flags = RPC_TASK_ASYNC, |
| 6021 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6022 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6023 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6024 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6025 | if (data == NULL) |
| 6026 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6027 | 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] | 6028 | |
| 6029 | nfs4_state_protect(server->nfs_client, |
| 6030 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6031 | &task_setup_data.rpc_client, &msg); |
| 6032 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6033 | data->args.fhandle = &data->fh; |
| 6034 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6035 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6036 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6037 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6038 | data->res.fattr = &data->fattr; |
| 6039 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6040 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6041 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6042 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6043 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6044 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6045 | 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] | 6046 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6047 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6048 | if (data->lr.roc) { |
| 6049 | data->args.lr_args = &data->lr.arg; |
| 6050 | data->res.lr_res = &data->lr.res; |
| 6051 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6052 | } else if (data->lr.roc) { |
| 6053 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6054 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6055 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6056 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6057 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6058 | msg.rpc_argp = &data->args; |
| 6059 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6060 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6061 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6062 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6063 | if (!issync) |
| 6064 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6065 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6066 | if (status != 0) |
| 6067 | goto out; |
| 6068 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6069 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6070 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6071 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6072 | } |
| 6073 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6074 | int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6075 | { |
| 6076 | struct nfs_server *server = NFS_SERVER(inode); |
| 6077 | struct nfs4_exception exception = { }; |
| 6078 | int err; |
| 6079 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6080 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6081 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | switch (err) { |
| 6083 | case -NFS4ERR_STALE_STATEID: |
| 6084 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6085 | case 0: |
| 6086 | return 0; |
| 6087 | } |
| 6088 | err = nfs4_handle_exception(server, err, &exception); |
| 6089 | } while (exception.retry); |
| 6090 | return err; |
| 6091 | } |
| 6092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6093 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6094 | { |
| 6095 | struct inode *inode = state->inode; |
| 6096 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6097 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6098 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6099 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6100 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6102 | struct nfs_lockt_res res = { |
| 6103 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6104 | }; |
| 6105 | struct rpc_message msg = { |
| 6106 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6107 | .rpc_argp = &arg, |
| 6108 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | .rpc_cred = state->owner->so_cred, |
| 6110 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6111 | struct nfs4_lock_state *lsp; |
| 6112 | int status; |
| 6113 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6114 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6115 | status = nfs4_set_lock_state(state, request); |
| 6116 | if (status != 0) |
| 6117 | goto out; |
| 6118 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6119 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6120 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6121 | 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] | 6122 | switch (status) { |
| 6123 | case 0: |
| 6124 | request->fl_type = F_UNLCK; |
| 6125 | break; |
| 6126 | case -NFS4ERR_DENIED: |
| 6127 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6128 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6129 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6130 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6131 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6132 | return status; |
| 6133 | } |
| 6134 | |
| 6135 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6136 | { |
| 6137 | struct nfs4_exception exception = { }; |
| 6138 | int err; |
| 6139 | |
| 6140 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6141 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6142 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6143 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | &exception); |
| 6145 | } while (exception.retry); |
| 6146 | return err; |
| 6147 | } |
| 6148 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6149 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6150 | struct nfs_locku_args arg; |
| 6151 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6152 | struct nfs4_lock_state *lsp; |
| 6153 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6154 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6155 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6156 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6157 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6158 | }; |
| 6159 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6160 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6161 | struct nfs_open_context *ctx, |
| 6162 | struct nfs4_lock_state *lsp, |
| 6163 | struct nfs_seqid *seqid) |
| 6164 | { |
| 6165 | struct nfs4_unlockdata *p; |
| 6166 | struct inode *inode = lsp->ls_state->inode; |
| 6167 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6168 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6169 | if (p == NULL) |
| 6170 | return NULL; |
| 6171 | p->arg.fh = NFS_FH(inode); |
| 6172 | p->arg.fl = &p->fl; |
| 6173 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6174 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6175 | p->lsp = lsp; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6176 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6177 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6178 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6179 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6180 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6181 | p->server = NFS_SERVER(inode); |
| 6182 | return p; |
| 6183 | } |
| 6184 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6185 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6186 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6187 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6188 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6189 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6190 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6191 | put_nfs_open_context(calldata->ctx); |
| 6192 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6195 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6196 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6197 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6198 | struct nfs4_exception exception = { |
| 6199 | .inode = calldata->lsp->ls_state->inode, |
| 6200 | .stateid = &calldata->arg.stateid, |
| 6201 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6202 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6203 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6204 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6205 | switch (task->tk_status) { |
| 6206 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6207 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6208 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6209 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6210 | &calldata->res.stateid)) |
| 6211 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6212 | case -NFS4ERR_ADMIN_REVOKED: |
| 6213 | case -NFS4ERR_EXPIRED: |
| 6214 | nfs4_free_revoked_stateid(calldata->server, |
| 6215 | &calldata->arg.stateid, |
| 6216 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6217 | case -NFS4ERR_BAD_STATEID: |
| 6218 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6219 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6220 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 6221 | &calldata->lsp->ls_stateid)) |
| 6222 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6223 | break; |
| 6224 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6225 | task->tk_status = nfs4_async_handle_exception(task, |
| 6226 | calldata->server, task->tk_status, |
| 6227 | &exception); |
| 6228 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6229 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6230 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6231 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6232 | } |
| 6233 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6234 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6235 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6236 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6238 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6239 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6240 | return; |
| 6241 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6242 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6243 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6244 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6245 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6246 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6247 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6248 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6249 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6250 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6251 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6252 | &calldata->res.seq_res, |
| 6253 | task) != 0) |
| 6254 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6255 | return; |
| 6256 | out_no_action: |
| 6257 | task->tk_action = NULL; |
| 6258 | out_wait: |
| 6259 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6260 | } |
| 6261 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6262 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6263 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6264 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6265 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6266 | }; |
| 6267 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6268 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6269 | struct nfs_open_context *ctx, |
| 6270 | struct nfs4_lock_state *lsp, |
| 6271 | struct nfs_seqid *seqid) |
| 6272 | { |
| 6273 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6274 | struct rpc_message msg = { |
| 6275 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6276 | .rpc_cred = ctx->cred, |
| 6277 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6278 | struct rpc_task_setup task_setup_data = { |
| 6279 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6280 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6281 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6282 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6283 | .flags = RPC_TASK_ASYNC, |
| 6284 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6285 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6286 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6287 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6288 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6289 | /* Ensure this is an unlock - when canceling a lock, the |
| 6290 | * canceled lock is passed in, and it won't be an unlock. |
| 6291 | */ |
| 6292 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6293 | if (fl->fl_flags & FL_CLOSE) |
| 6294 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6295 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6296 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6297 | if (data == NULL) { |
| 6298 | nfs_free_seqid(seqid); |
| 6299 | return ERR_PTR(-ENOMEM); |
| 6300 | } |
| 6301 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6302 | 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] | 6303 | msg.rpc_argp = &data->arg; |
| 6304 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6305 | task_setup_data.callback_data = data; |
| 6306 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6307 | } |
| 6308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6310 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6311 | struct inode *inode = state->inode; |
| 6312 | struct nfs4_state_owner *sp = state->owner; |
| 6313 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6314 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6315 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6316 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6317 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6318 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6319 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6320 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6321 | status = nfs4_set_lock_state(state, request); |
| 6322 | /* Unlock _before_ we do the RPC call */ |
| 6323 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6324 | /* Exclude nfs_delegation_claim_locks() */ |
| 6325 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6326 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6327 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6328 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6329 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6330 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6331 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6332 | } |
| 6333 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6334 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6335 | if (status != 0) |
| 6336 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6337 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6338 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6339 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6340 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6341 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6342 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6343 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6344 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6345 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6346 | 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] | 6347 | status = PTR_ERR(task); |
| 6348 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6349 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6350 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6351 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6352 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6353 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6354 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6355 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6356 | } |
| 6357 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6358 | struct nfs4_lockdata { |
| 6359 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6360 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6361 | struct nfs4_lock_state *lsp; |
| 6362 | struct nfs_open_context *ctx; |
| 6363 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6364 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6365 | int rpc_status; |
| 6366 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6367 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6368 | }; |
| 6369 | |
| 6370 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6371 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6372 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6373 | { |
| 6374 | struct nfs4_lockdata *p; |
| 6375 | struct inode *inode = lsp->ls_state->inode; |
| 6376 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6377 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6378 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6379 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6380 | if (p == NULL) |
| 6381 | return NULL; |
| 6382 | |
| 6383 | p->arg.fh = NFS_FH(inode); |
| 6384 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6385 | 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] | 6386 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6387 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6388 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6389 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6390 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6391 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6392 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6393 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6394 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6395 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6396 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6397 | p->server = server; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6398 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6399 | p->ctx = get_nfs_open_context(ctx); |
| 6400 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6401 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6402 | out_free_seqid: |
| 6403 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6404 | out_free: |
| 6405 | kfree(p); |
| 6406 | return NULL; |
| 6407 | } |
| 6408 | |
| 6409 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6410 | { |
| 6411 | struct nfs4_lockdata *data = calldata; |
| 6412 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6414 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6415 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6416 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6417 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6418 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6419 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6420 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6421 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6422 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6423 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6424 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6425 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6426 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6427 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6428 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6429 | &data->lsp->ls_stateid); |
| 6430 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6431 | if (!nfs4_valid_open_stateid(state)) { |
| 6432 | data->rpc_status = -EBADF; |
| 6433 | task->tk_action = NULL; |
| 6434 | goto out_release_open_seqid; |
| 6435 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6436 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6437 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6438 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6439 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6440 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6441 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6442 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6443 | nfs_release_seqid(data->arg.open_seqid); |
| 6444 | out_release_lock_seqid: |
| 6445 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6446 | out_wait: |
| 6447 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6448 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6449 | } |
| 6450 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6451 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6452 | { |
| 6453 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6454 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6455 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6456 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6457 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6458 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6459 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6460 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6461 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6462 | switch (task->tk_status) { |
| 6463 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6464 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6465 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6466 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6467 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6468 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6469 | break; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6470 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6471 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6472 | if (data->arg.new_lock_owner != 0) { |
| 6473 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6474 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6475 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6476 | goto out_done; |
| 6477 | } else if (nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6478 | goto out_done; |
| 6479 | |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6480 | break; |
| 6481 | case -NFS4ERR_BAD_STATEID: |
| 6482 | case -NFS4ERR_OLD_STATEID: |
| 6483 | case -NFS4ERR_STALE_STATEID: |
| 6484 | case -NFS4ERR_EXPIRED: |
| 6485 | if (data->arg.new_lock_owner != 0) { |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6486 | if (nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6487 | &lsp->ls_state->open_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6488 | goto out_done; |
| 6489 | } else if (nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6490 | &lsp->ls_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6491 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6492 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6493 | if (!data->cancelled) |
| 6494 | rpc_restart_call_prepare(task); |
| 6495 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6496 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6497 | } |
| 6498 | |
| 6499 | static void nfs4_lock_release(void *calldata) |
| 6500 | { |
| 6501 | struct nfs4_lockdata *data = calldata; |
| 6502 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6503 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6504 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6505 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6506 | struct rpc_task *task; |
| 6507 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6508 | data->arg.lock_seqid); |
| 6509 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6510 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6511 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6512 | } else |
| 6513 | nfs_free_seqid(data->arg.lock_seqid); |
| 6514 | nfs4_put_lock_state(data->lsp); |
| 6515 | put_nfs_open_context(data->ctx); |
| 6516 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6517 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6518 | } |
| 6519 | |
| 6520 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6521 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6522 | .rpc_call_done = nfs4_lock_done, |
| 6523 | .rpc_release = nfs4_lock_release, |
| 6524 | }; |
| 6525 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6526 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6527 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6528 | switch (error) { |
| 6529 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6530 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6531 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6532 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6533 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6534 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6535 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6536 | break; |
| 6537 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6538 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6539 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6540 | }; |
| 6541 | } |
| 6542 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6543 | 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] | 6544 | { |
| 6545 | struct nfs4_lockdata *data; |
| 6546 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6547 | struct rpc_message msg = { |
| 6548 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6549 | .rpc_cred = state->owner->so_cred, |
| 6550 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6551 | struct rpc_task_setup task_setup_data = { |
| 6552 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6553 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6554 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6555 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6556 | .flags = RPC_TASK_ASYNC, |
| 6557 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6558 | int ret; |
| 6559 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6560 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6561 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6562 | fl->fl_u.nfs4_fl.owner, |
| 6563 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6564 | if (data == NULL) |
| 6565 | return -ENOMEM; |
| 6566 | if (IS_SETLKW(cmd)) |
| 6567 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6568 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6569 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6570 | msg.rpc_argp = &data->arg; |
| 6571 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6572 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6573 | if (recovery_type > NFS_LOCK_NEW) { |
| 6574 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6575 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6576 | } else |
| 6577 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6578 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6579 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6580 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6581 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6582 | if (ret == 0) { |
| 6583 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6584 | if (ret) |
| 6585 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6586 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6587 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6588 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6589 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6590 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6591 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6592 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6596 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6597 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6598 | struct nfs4_exception exception = { |
| 6599 | .inode = state->inode, |
| 6600 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6601 | int err; |
| 6602 | |
| 6603 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6604 | /* Cache the lock if possible... */ |
| 6605 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6606 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6607 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6608 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6609 | break; |
| 6610 | nfs4_handle_exception(server, err, &exception); |
| 6611 | } while (exception.retry); |
| 6612 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6616 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6617 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6618 | struct nfs4_exception exception = { |
| 6619 | .inode = state->inode, |
| 6620 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6621 | int err; |
| 6622 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6623 | err = nfs4_set_lock_state(state, request); |
| 6624 | if (err != 0) |
| 6625 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6626 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6627 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6628 | return 0; |
| 6629 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6630 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6631 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6632 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6633 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6634 | switch (err) { |
| 6635 | default: |
| 6636 | goto out; |
| 6637 | case -NFS4ERR_GRACE: |
| 6638 | case -NFS4ERR_DELAY: |
| 6639 | nfs4_handle_exception(server, err, &exception); |
| 6640 | err = 0; |
| 6641 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6642 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6643 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6644 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6645 | } |
| 6646 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6647 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6648 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6649 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6650 | struct nfs4_lock_state *lsp; |
| 6651 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6652 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6653 | status = nfs4_set_lock_state(state, request); |
| 6654 | if (status != 0) |
| 6655 | return status; |
| 6656 | lsp = request->fl_u.nfs4_fl.owner; |
| 6657 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6658 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6659 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6660 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6661 | } |
| 6662 | #endif |
| 6663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6664 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6665 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6666 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6667 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6668 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6669 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6670 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6671 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6672 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6673 | if (status < 0) |
| 6674 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6675 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6676 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6677 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6678 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6679 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6680 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6681 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6682 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6683 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6684 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6685 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6686 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6687 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6688 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6689 | out: |
| 6690 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6691 | return status; |
| 6692 | } |
| 6693 | |
| 6694 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6695 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6696 | struct nfs4_exception exception = { |
| 6697 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6698 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6699 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6700 | int err; |
| 6701 | |
| 6702 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6703 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6704 | if (err == -NFS4ERR_DENIED) |
| 6705 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6706 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6707 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6708 | } while (exception.retry); |
| 6709 | return err; |
| 6710 | } |
| 6711 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6712 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6713 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6714 | |
| 6715 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6716 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6717 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6718 | { |
| 6719 | int status = -ERESTARTSYS; |
| 6720 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6721 | |
| 6722 | while(!signalled()) { |
| 6723 | status = nfs4_proc_setlk(state, cmd, request); |
| 6724 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6725 | break; |
| 6726 | freezable_schedule_timeout_interruptible(timeout); |
| 6727 | timeout *= 2; |
| 6728 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6729 | status = -ERESTARTSYS; |
| 6730 | } |
| 6731 | return status; |
| 6732 | } |
| 6733 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6734 | #ifdef CONFIG_NFS_V4_1 |
| 6735 | struct nfs4_lock_waiter { |
| 6736 | struct task_struct *task; |
| 6737 | struct inode *inode; |
| 6738 | struct nfs_lowner *owner; |
| 6739 | bool notified; |
| 6740 | }; |
| 6741 | |
| 6742 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6743 | 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] | 6744 | { |
| 6745 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6746 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6747 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6748 | /* NULL key means to wake up everyone */ |
| 6749 | if (key) { |
| 6750 | struct cb_notify_lock_args *cbnl = key; |
| 6751 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6752 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6753 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6754 | /* Only wake if the callback was for the same owner. */ |
| 6755 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 6756 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6757 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6758 | /* Make sure it's for the right inode */ |
| 6759 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6760 | return 0; |
| 6761 | |
| 6762 | waiter->notified = true; |
| 6763 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6764 | |
| 6765 | /* override "private" so we can use default_wake_function */ |
| 6766 | wait->private = waiter->task; |
| 6767 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6768 | wait->private = waiter; |
| 6769 | return ret; |
| 6770 | } |
| 6771 | |
| 6772 | static int |
| 6773 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6774 | { |
| 6775 | int status = -ERESTARTSYS; |
| 6776 | unsigned long flags; |
| 6777 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6778 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6779 | struct nfs_client *clp = server->nfs_client; |
| 6780 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6781 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6782 | .id = lsp->ls_seqid.owner_id, |
| 6783 | .s_dev = server->s_dev }; |
| 6784 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6785 | .inode = state->inode, |
| 6786 | .owner = &owner, |
| 6787 | .notified = false }; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6788 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6789 | |
| 6790 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6791 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6792 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6793 | |
| 6794 | init_wait(&wait); |
| 6795 | wait.private = &waiter; |
| 6796 | wait.func = nfs4_wake_lock_waiter; |
| 6797 | add_wait_queue(q, &wait); |
| 6798 | |
| 6799 | while(!signalled()) { |
Jeff Layton | 41a7462 | 2018-03-18 08:37:01 -0400 | [diff] [blame] | 6800 | waiter.notified = false; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6801 | status = nfs4_proc_setlk(state, cmd, request); |
| 6802 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6803 | break; |
| 6804 | |
| 6805 | status = -ERESTARTSYS; |
| 6806 | spin_lock_irqsave(&q->lock, flags); |
| 6807 | if (waiter.notified) { |
| 6808 | spin_unlock_irqrestore(&q->lock, flags); |
| 6809 | continue; |
| 6810 | } |
| 6811 | set_current_state(TASK_INTERRUPTIBLE); |
| 6812 | spin_unlock_irqrestore(&q->lock, flags); |
| 6813 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6814 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6815 | } |
| 6816 | |
| 6817 | finish_wait(q, &wait); |
| 6818 | return status; |
| 6819 | } |
| 6820 | #else /* !CONFIG_NFS_V4_1 */ |
| 6821 | static inline int |
| 6822 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6823 | { |
| 6824 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6825 | } |
| 6826 | #endif |
| 6827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6828 | static int |
| 6829 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6830 | { |
| 6831 | struct nfs_open_context *ctx; |
| 6832 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6833 | int status; |
| 6834 | |
| 6835 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6836 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6837 | state = ctx->state; |
| 6838 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6839 | if (IS_GETLK(cmd)) { |
| 6840 | if (state != NULL) |
| 6841 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6842 | return 0; |
| 6843 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6844 | |
| 6845 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6846 | return -EINVAL; |
| 6847 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6848 | if (request->fl_type == F_UNLCK) { |
| 6849 | if (state != NULL) |
| 6850 | return nfs4_proc_unlck(state, cmd, request); |
| 6851 | return 0; |
| 6852 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6853 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6854 | if (state == NULL) |
| 6855 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6856 | |
| 6857 | if ((request->fl_flags & FL_POSIX) && |
| 6858 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6859 | return -ENOLCK; |
| 6860 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 6861 | /* |
| 6862 | * Don't rely on the VFS having checked the file open mode, |
| 6863 | * since it won't do this for flock() locks. |
| 6864 | */ |
| 6865 | switch (request->fl_type) { |
| 6866 | case F_RDLCK: |
| 6867 | if (!(filp->f_mode & FMODE_READ)) |
| 6868 | return -EBADF; |
| 6869 | break; |
| 6870 | case F_WRLCK: |
| 6871 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6872 | return -EBADF; |
| 6873 | } |
| 6874 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6875 | status = nfs4_set_lock_state(state, request); |
| 6876 | if (status != 0) |
| 6877 | return status; |
| 6878 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6879 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6880 | } |
| 6881 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6882 | 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] | 6883 | { |
| 6884 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6885 | int err; |
| 6886 | |
| 6887 | err = nfs4_set_lock_state(state, fl); |
| 6888 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6889 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6890 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 6891 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6892 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6893 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6894 | struct nfs_release_lockowner_data { |
| 6895 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6896 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6897 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6898 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6899 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6900 | }; |
| 6901 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6902 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6903 | { |
| 6904 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6905 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6906 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6907 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6908 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6909 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6910 | } |
| 6911 | |
| 6912 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6913 | { |
| 6914 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6915 | struct nfs_server *server = data->server; |
| 6916 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6917 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6918 | |
| 6919 | switch (task->tk_status) { |
| 6920 | case 0: |
| 6921 | renew_lease(server, data->timestamp); |
| 6922 | break; |
| 6923 | case -NFS4ERR_STALE_CLIENTID: |
| 6924 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6925 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6926 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6927 | case -NFS4ERR_LEASE_MOVED: |
| 6928 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6929 | if (nfs4_async_handle_error(task, server, |
| 6930 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6931 | rpc_restart_call_prepare(task); |
| 6932 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6933 | } |
| 6934 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6935 | static void nfs4_release_lockowner_release(void *calldata) |
| 6936 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6937 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6938 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6939 | kfree(calldata); |
| 6940 | } |
| 6941 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6942 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6943 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6944 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6945 | .rpc_release = nfs4_release_lockowner_release, |
| 6946 | }; |
| 6947 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6948 | static void |
| 6949 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6950 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6951 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6952 | struct rpc_message msg = { |
| 6953 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6954 | }; |
| 6955 | |
| 6956 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6957 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6958 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6959 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6960 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6961 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6962 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6963 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6964 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6965 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6966 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6967 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6968 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6969 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6970 | 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] | 6971 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6972 | } |
| 6973 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6974 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6975 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6976 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6977 | struct dentry *unused, struct inode *inode, |
| 6978 | const char *key, const void *buf, |
| 6979 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6980 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6981 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6982 | } |
| 6983 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6984 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6985 | struct dentry *unused, struct inode *inode, |
| 6986 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6987 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6988 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6989 | } |
| 6990 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6991 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6992 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6993 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6994 | } |
| 6995 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6996 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6997 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6998 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6999 | struct dentry *unused, struct inode *inode, |
| 7000 | const char *key, const void *buf, |
| 7001 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7002 | { |
| 7003 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7004 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7005 | |
| 7006 | return -EOPNOTSUPP; |
| 7007 | } |
| 7008 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7009 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7010 | struct dentry *unused, struct inode *inode, |
| 7011 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7012 | { |
| 7013 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7014 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7015 | return -EOPNOTSUPP; |
| 7016 | } |
| 7017 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7018 | static ssize_t |
| 7019 | 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] | 7020 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7021 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7022 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7023 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7024 | len = security_inode_listsecurity(inode, list, list_len); |
| 7025 | if (list_len && len > list_len) |
| 7026 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7027 | } |
| 7028 | return len; |
| 7029 | } |
| 7030 | |
| 7031 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7032 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7033 | .get = nfs4_xattr_get_nfs4_label, |
| 7034 | .set = nfs4_xattr_set_nfs4_label, |
| 7035 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7036 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7037 | #else |
| 7038 | |
| 7039 | static ssize_t |
| 7040 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7041 | { |
| 7042 | return 0; |
| 7043 | } |
| 7044 | |
| 7045 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7046 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7047 | /* |
| 7048 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7049 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7050 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7051 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7052 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7053 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7054 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7055 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7056 | return; |
| 7057 | |
| 7058 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7059 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7060 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7061 | fattr->nlink = 2; |
| 7062 | } |
| 7063 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7064 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7065 | const struct qstr *name, |
| 7066 | struct nfs4_fs_locations *fs_locations, |
| 7067 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7068 | { |
| 7069 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7070 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7071 | struct nfs4_fs_locations_arg args = { |
| 7072 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7073 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7074 | .page = page, |
| 7075 | .bitmask = bitmask, |
| 7076 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7077 | struct nfs4_fs_locations_res res = { |
| 7078 | .fs_locations = fs_locations, |
| 7079 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7080 | struct rpc_message msg = { |
| 7081 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7082 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7083 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7084 | }; |
| 7085 | int status; |
| 7086 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7087 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7088 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7089 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7090 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7091 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7092 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7093 | * is not supported */ |
| 7094 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7095 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7096 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7097 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7098 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7099 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7100 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7101 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7102 | 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] | 7103 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7104 | return status; |
| 7105 | } |
| 7106 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7107 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7108 | const struct qstr *name, |
| 7109 | struct nfs4_fs_locations *fs_locations, |
| 7110 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7111 | { |
| 7112 | struct nfs4_exception exception = { }; |
| 7113 | int err; |
| 7114 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7115 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7116 | fs_locations, page); |
| 7117 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7118 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7119 | &exception); |
| 7120 | } while (exception.retry); |
| 7121 | return err; |
| 7122 | } |
| 7123 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7124 | /* |
| 7125 | * This operation also signals the server that this client is |
| 7126 | * performing migration recovery. The server can stop returning |
| 7127 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7128 | * appended to this compound to identify the client ID which is |
| 7129 | * performing recovery. |
| 7130 | */ |
| 7131 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7132 | struct nfs4_fs_locations *locations, |
| 7133 | struct page *page, struct rpc_cred *cred) |
| 7134 | { |
| 7135 | struct nfs_server *server = NFS_SERVER(inode); |
| 7136 | struct rpc_clnt *clnt = server->client; |
| 7137 | u32 bitmask[2] = { |
| 7138 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7139 | }; |
| 7140 | struct nfs4_fs_locations_arg args = { |
| 7141 | .clientid = server->nfs_client->cl_clientid, |
| 7142 | .fh = NFS_FH(inode), |
| 7143 | .page = page, |
| 7144 | .bitmask = bitmask, |
| 7145 | .migration = 1, /* skip LOOKUP */ |
| 7146 | .renew = 1, /* append RENEW */ |
| 7147 | }; |
| 7148 | struct nfs4_fs_locations_res res = { |
| 7149 | .fs_locations = locations, |
| 7150 | .migration = 1, |
| 7151 | .renew = 1, |
| 7152 | }; |
| 7153 | struct rpc_message msg = { |
| 7154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7155 | .rpc_argp = &args, |
| 7156 | .rpc_resp = &res, |
| 7157 | .rpc_cred = cred, |
| 7158 | }; |
| 7159 | unsigned long now = jiffies; |
| 7160 | int status; |
| 7161 | |
| 7162 | nfs_fattr_init(&locations->fattr); |
| 7163 | locations->server = server; |
| 7164 | locations->nlocations = 0; |
| 7165 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7166 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7167 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7168 | &args.seq_args, &res.seq_res); |
| 7169 | if (status) |
| 7170 | return status; |
| 7171 | |
| 7172 | renew_lease(server, now); |
| 7173 | return 0; |
| 7174 | } |
| 7175 | |
| 7176 | #ifdef CONFIG_NFS_V4_1 |
| 7177 | |
| 7178 | /* |
| 7179 | * This operation also signals the server that this client is |
| 7180 | * performing migration recovery. The server can stop asserting |
| 7181 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7182 | * performing this operation is identified in the SEQUENCE |
| 7183 | * operation in this compound. |
| 7184 | * |
| 7185 | * When the client supports GETATTR(fs_locations_info), it can |
| 7186 | * be plumbed in here. |
| 7187 | */ |
| 7188 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7189 | struct nfs4_fs_locations *locations, |
| 7190 | struct page *page, struct rpc_cred *cred) |
| 7191 | { |
| 7192 | struct nfs_server *server = NFS_SERVER(inode); |
| 7193 | struct rpc_clnt *clnt = server->client; |
| 7194 | u32 bitmask[2] = { |
| 7195 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7196 | }; |
| 7197 | struct nfs4_fs_locations_arg args = { |
| 7198 | .fh = NFS_FH(inode), |
| 7199 | .page = page, |
| 7200 | .bitmask = bitmask, |
| 7201 | .migration = 1, /* skip LOOKUP */ |
| 7202 | }; |
| 7203 | struct nfs4_fs_locations_res res = { |
| 7204 | .fs_locations = locations, |
| 7205 | .migration = 1, |
| 7206 | }; |
| 7207 | struct rpc_message msg = { |
| 7208 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7209 | .rpc_argp = &args, |
| 7210 | .rpc_resp = &res, |
| 7211 | .rpc_cred = cred, |
| 7212 | }; |
| 7213 | int status; |
| 7214 | |
| 7215 | nfs_fattr_init(&locations->fattr); |
| 7216 | locations->server = server; |
| 7217 | locations->nlocations = 0; |
| 7218 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7219 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7220 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7221 | &args.seq_args, &res.seq_res); |
| 7222 | if (status == NFS4_OK && |
| 7223 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7224 | status = -NFS4ERR_LEASE_MOVED; |
| 7225 | return status; |
| 7226 | } |
| 7227 | |
| 7228 | #endif /* CONFIG_NFS_V4_1 */ |
| 7229 | |
| 7230 | /** |
| 7231 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7232 | * @inode: inode on FSID that is migrating |
| 7233 | * @locations: result of query |
| 7234 | * @page: buffer |
| 7235 | * @cred: credential to use for this operation |
| 7236 | * |
| 7237 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7238 | * operation failed, or a negative errno if a local error occurred. |
| 7239 | * |
| 7240 | * On success, "locations" is filled in, but if the server has |
| 7241 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7242 | * asserted. |
| 7243 | * |
| 7244 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7245 | * from this client that require migration recovery. |
| 7246 | */ |
| 7247 | int nfs4_proc_get_locations(struct inode *inode, |
| 7248 | struct nfs4_fs_locations *locations, |
| 7249 | struct page *page, struct rpc_cred *cred) |
| 7250 | { |
| 7251 | struct nfs_server *server = NFS_SERVER(inode); |
| 7252 | struct nfs_client *clp = server->nfs_client; |
| 7253 | const struct nfs4_mig_recovery_ops *ops = |
| 7254 | clp->cl_mvops->mig_recovery_ops; |
| 7255 | struct nfs4_exception exception = { }; |
| 7256 | int status; |
| 7257 | |
| 7258 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7259 | (unsigned long long)server->fsid.major, |
| 7260 | (unsigned long long)server->fsid.minor, |
| 7261 | clp->cl_hostname); |
| 7262 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7263 | |
| 7264 | do { |
| 7265 | status = ops->get_locations(inode, locations, page, cred); |
| 7266 | if (status != -NFS4ERR_DELAY) |
| 7267 | break; |
| 7268 | nfs4_handle_exception(server, status, &exception); |
| 7269 | } while (exception.retry); |
| 7270 | return status; |
| 7271 | } |
| 7272 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7273 | /* |
| 7274 | * This operation also signals the server that this client is |
| 7275 | * performing "lease moved" recovery. The server can stop |
| 7276 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7277 | * is appended to this compound to identify the client ID which is |
| 7278 | * performing recovery. |
| 7279 | */ |
| 7280 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7281 | { |
| 7282 | struct nfs_server *server = NFS_SERVER(inode); |
| 7283 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7284 | struct rpc_clnt *clnt = server->client; |
| 7285 | struct nfs4_fsid_present_arg args = { |
| 7286 | .fh = NFS_FH(inode), |
| 7287 | .clientid = clp->cl_clientid, |
| 7288 | .renew = 1, /* append RENEW */ |
| 7289 | }; |
| 7290 | struct nfs4_fsid_present_res res = { |
| 7291 | .renew = 1, |
| 7292 | }; |
| 7293 | struct rpc_message msg = { |
| 7294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7295 | .rpc_argp = &args, |
| 7296 | .rpc_resp = &res, |
| 7297 | .rpc_cred = cred, |
| 7298 | }; |
| 7299 | unsigned long now = jiffies; |
| 7300 | int status; |
| 7301 | |
| 7302 | res.fh = nfs_alloc_fhandle(); |
| 7303 | if (res.fh == NULL) |
| 7304 | return -ENOMEM; |
| 7305 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7306 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7307 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7308 | &args.seq_args, &res.seq_res); |
| 7309 | nfs_free_fhandle(res.fh); |
| 7310 | if (status) |
| 7311 | return status; |
| 7312 | |
| 7313 | do_renew_lease(clp, now); |
| 7314 | return 0; |
| 7315 | } |
| 7316 | |
| 7317 | #ifdef CONFIG_NFS_V4_1 |
| 7318 | |
| 7319 | /* |
| 7320 | * This operation also signals the server that this client is |
| 7321 | * performing "lease moved" recovery. The server can stop asserting |
| 7322 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7323 | * this operation is identified in the SEQUENCE operation in this |
| 7324 | * compound. |
| 7325 | */ |
| 7326 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7327 | { |
| 7328 | struct nfs_server *server = NFS_SERVER(inode); |
| 7329 | struct rpc_clnt *clnt = server->client; |
| 7330 | struct nfs4_fsid_present_arg args = { |
| 7331 | .fh = NFS_FH(inode), |
| 7332 | }; |
| 7333 | struct nfs4_fsid_present_res res = { |
| 7334 | }; |
| 7335 | struct rpc_message msg = { |
| 7336 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7337 | .rpc_argp = &args, |
| 7338 | .rpc_resp = &res, |
| 7339 | .rpc_cred = cred, |
| 7340 | }; |
| 7341 | int status; |
| 7342 | |
| 7343 | res.fh = nfs_alloc_fhandle(); |
| 7344 | if (res.fh == NULL) |
| 7345 | return -ENOMEM; |
| 7346 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7347 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7348 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7349 | &args.seq_args, &res.seq_res); |
| 7350 | nfs_free_fhandle(res.fh); |
| 7351 | if (status == NFS4_OK && |
| 7352 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7353 | status = -NFS4ERR_LEASE_MOVED; |
| 7354 | return status; |
| 7355 | } |
| 7356 | |
| 7357 | #endif /* CONFIG_NFS_V4_1 */ |
| 7358 | |
| 7359 | /** |
| 7360 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7361 | * @inode: inode on FSID to check |
| 7362 | * @cred: credential to use for this operation |
| 7363 | * |
| 7364 | * Server indicates whether the FSID is present, moved, or not |
| 7365 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7366 | * condition for this client ID. |
| 7367 | * |
| 7368 | * Returns NFS4_OK if the FSID is present on this server, |
| 7369 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7370 | * NFS4ERR code if some error occurred on the server, or a |
| 7371 | * negative errno if a local failure occurred. |
| 7372 | */ |
| 7373 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7374 | { |
| 7375 | struct nfs_server *server = NFS_SERVER(inode); |
| 7376 | struct nfs_client *clp = server->nfs_client; |
| 7377 | const struct nfs4_mig_recovery_ops *ops = |
| 7378 | clp->cl_mvops->mig_recovery_ops; |
| 7379 | struct nfs4_exception exception = { }; |
| 7380 | int status; |
| 7381 | |
| 7382 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7383 | (unsigned long long)server->fsid.major, |
| 7384 | (unsigned long long)server->fsid.minor, |
| 7385 | clp->cl_hostname); |
| 7386 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7387 | |
| 7388 | do { |
| 7389 | status = ops->fsid_present(inode, cred); |
| 7390 | if (status != -NFS4ERR_DELAY) |
| 7391 | break; |
| 7392 | nfs4_handle_exception(server, status, &exception); |
| 7393 | } while (exception.retry); |
| 7394 | return status; |
| 7395 | } |
| 7396 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7397 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7398 | * If 'use_integrity' is true and the state managment nfs_client |
| 7399 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7400 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7401 | * Considerations sections. Otherwise, just use the user cred with the |
| 7402 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7403 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7404 | 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] | 7405 | { |
| 7406 | int status; |
| 7407 | struct nfs4_secinfo_arg args = { |
| 7408 | .dir_fh = NFS_FH(dir), |
| 7409 | .name = name, |
| 7410 | }; |
| 7411 | struct nfs4_secinfo_res res = { |
| 7412 | .flavors = flavors, |
| 7413 | }; |
| 7414 | struct rpc_message msg = { |
| 7415 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7416 | .rpc_argp = &args, |
| 7417 | .rpc_resp = &res, |
| 7418 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7419 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7420 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7421 | |
| 7422 | if (use_integrity) { |
| 7423 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7424 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7425 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7426 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7427 | |
| 7428 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7429 | |
| 7430 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7431 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7432 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7433 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7434 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7435 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7436 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7437 | if (cred) |
| 7438 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7439 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7440 | return status; |
| 7441 | } |
| 7442 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7443 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7444 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7445 | { |
| 7446 | struct nfs4_exception exception = { }; |
| 7447 | int err; |
| 7448 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7449 | err = -NFS4ERR_WRONGSEC; |
| 7450 | |
| 7451 | /* try to use integrity protection with machine cred */ |
| 7452 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7453 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7454 | |
| 7455 | /* |
| 7456 | * if unable to use integrity protection, or SECINFO with |
| 7457 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7458 | * disallowed by spec, but exists in deployed servers) use |
| 7459 | * the current filesystem's rpc_client and the user cred. |
| 7460 | */ |
| 7461 | if (err == -NFS4ERR_WRONGSEC) |
| 7462 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7463 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7464 | trace_nfs4_secinfo(dir, name, err); |
| 7465 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7466 | &exception); |
| 7467 | } while (exception.retry); |
| 7468 | return err; |
| 7469 | } |
| 7470 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7471 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7472 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7473 | * Check the exchange flags returned by the server for invalid flags, having |
| 7474 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7475 | * DS flags set. |
| 7476 | */ |
| 7477 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7478 | { |
| 7479 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7480 | goto out_inval; |
| 7481 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7482 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7483 | goto out_inval; |
| 7484 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7485 | goto out_inval; |
| 7486 | return NFS_OK; |
| 7487 | out_inval: |
| 7488 | return -NFS4ERR_INVAL; |
| 7489 | } |
| 7490 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7491 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7492 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7493 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7494 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7495 | if (a->server_scope_sz != b->server_scope_sz) |
| 7496 | return false; |
| 7497 | 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] | 7498 | } |
| 7499 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7500 | static void |
| 7501 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7502 | { |
| 7503 | } |
| 7504 | |
| 7505 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7506 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7507 | }; |
| 7508 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7509 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7510 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7511 | * |
| 7512 | * The 4.1 client currently uses the same TCP connection for the |
| 7513 | * fore and backchannel. |
| 7514 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7515 | static |
| 7516 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7517 | struct rpc_xprt *xprt, |
| 7518 | struct nfs_client *clp, |
| 7519 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7520 | { |
| 7521 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7522 | struct nfs41_bind_conn_to_session_args args = { |
| 7523 | .client = clp, |
| 7524 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7525 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7526 | struct nfs41_bind_conn_to_session_res res; |
| 7527 | struct rpc_message msg = { |
| 7528 | .rpc_proc = |
| 7529 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7530 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7531 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7532 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7533 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7534 | struct rpc_task_setup task_setup_data = { |
| 7535 | .rpc_client = clnt, |
| 7536 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7537 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7538 | .rpc_message = &msg, |
| 7539 | .flags = RPC_TASK_TIMEOUT, |
| 7540 | }; |
| 7541 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7542 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7543 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7544 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7545 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7546 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7547 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7548 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7549 | args.dir = NFS4_CDFC4_FORE; |
| 7550 | |
| 7551 | task = rpc_run_task(&task_setup_data); |
| 7552 | if (!IS_ERR(task)) { |
| 7553 | status = task->tk_status; |
| 7554 | rpc_put_task(task); |
| 7555 | } else |
| 7556 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7557 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7558 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7559 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7560 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7561 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7562 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7563 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7564 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7565 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7566 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7567 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7568 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7569 | 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] | 7570 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7571 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7572 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7573 | } |
| 7574 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7575 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7576 | return status; |
| 7577 | } |
| 7578 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7579 | struct rpc_bind_conn_calldata { |
| 7580 | struct nfs_client *clp; |
| 7581 | struct rpc_cred *cred; |
| 7582 | }; |
| 7583 | |
| 7584 | static int |
| 7585 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7586 | struct rpc_xprt *xprt, |
| 7587 | void *calldata) |
| 7588 | { |
| 7589 | struct rpc_bind_conn_calldata *p = calldata; |
| 7590 | |
| 7591 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7592 | } |
| 7593 | |
| 7594 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7595 | { |
| 7596 | struct rpc_bind_conn_calldata data = { |
| 7597 | .clp = clp, |
| 7598 | .cred = cred, |
| 7599 | }; |
| 7600 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7601 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7602 | } |
| 7603 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7604 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7605 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7606 | * 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] | 7607 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7608 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7609 | .how = SP4_MACH_CRED, |
| 7610 | .enforce.u.words = { |
| 7611 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7612 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7613 | 1 << (OP_CREATE_SESSION - 32) | |
| 7614 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7615 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7616 | }, |
| 7617 | .allow.u.words = { |
| 7618 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7619 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7620 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7621 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7622 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7623 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7624 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7625 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7626 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7627 | 1 << (OP_FREE_STATEID - 32) | |
| 7628 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7629 | } |
| 7630 | }; |
| 7631 | |
| 7632 | /* |
| 7633 | * Select the state protection mode for client `clp' given the server results |
| 7634 | * from exchange_id in `sp'. |
| 7635 | * |
| 7636 | * Returns 0 on success, negative errno otherwise. |
| 7637 | */ |
| 7638 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7639 | struct nfs41_state_protection *sp) |
| 7640 | { |
| 7641 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7642 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7643 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7644 | 1 << (OP_CREATE_SESSION - 32) | |
| 7645 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7646 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7647 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7648 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7649 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7650 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7651 | |
| 7652 | if (sp->how == SP4_MACH_CRED) { |
| 7653 | /* Print state protect result */ |
| 7654 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7655 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7656 | if (test_bit(i, sp->enforce.u.longs)) |
| 7657 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7658 | if (test_bit(i, sp->allow.u.longs)) |
| 7659 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7660 | } |
| 7661 | |
| 7662 | /* make sure nothing is on enforce list that isn't supported */ |
| 7663 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7664 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7665 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7666 | ret = -EINVAL; |
| 7667 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7668 | } |
| 7669 | } |
| 7670 | |
| 7671 | /* |
| 7672 | * Minimal mode - state operations are allowed to use machine |
| 7673 | * credential. Note this already happens by default, so the |
| 7674 | * client doesn't have to do anything more than the negotiation. |
| 7675 | * |
| 7676 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7677 | * we're already using the machine cred for exchange_id |
| 7678 | * and will never use a different cred. |
| 7679 | */ |
| 7680 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7681 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7682 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7683 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7684 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7685 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7686 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7687 | } else { |
| 7688 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7689 | ret = -EINVAL; |
| 7690 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7691 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7692 | |
| 7693 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7694 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7695 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7696 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7697 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7698 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7699 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7700 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7701 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7702 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7703 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7704 | } |
| 7705 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7706 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7707 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7708 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7709 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7710 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7711 | |
| 7712 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7713 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7714 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7715 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7716 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7717 | |
| 7718 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7719 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7720 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7721 | } |
| 7722 | |
| 7723 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7724 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7725 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7726 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7727 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7728 | out: |
| 7729 | clp->cl_sp4_flags = flags; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7730 | return 0; |
| 7731 | } |
| 7732 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7733 | struct nfs41_exchange_id_data { |
| 7734 | struct nfs41_exchange_id_res res; |
| 7735 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7736 | }; |
| 7737 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7738 | static void nfs4_exchange_id_release(void *data) |
| 7739 | { |
| 7740 | struct nfs41_exchange_id_data *cdata = |
| 7741 | (struct nfs41_exchange_id_data *)data; |
| 7742 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7743 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7744 | kfree(cdata->res.impl_id); |
| 7745 | kfree(cdata->res.server_scope); |
| 7746 | kfree(cdata->res.server_owner); |
| 7747 | kfree(cdata); |
| 7748 | } |
| 7749 | |
| 7750 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7751 | .rpc_release = nfs4_exchange_id_release, |
| 7752 | }; |
| 7753 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7754 | /* |
| 7755 | * _nfs4_proc_exchange_id() |
| 7756 | * |
| 7757 | * Wrapper for EXCHANGE_ID operation. |
| 7758 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7759 | static struct rpc_task * |
| 7760 | nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7761 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7762 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7763 | struct rpc_message msg = { |
| 7764 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7765 | .rpc_cred = cred, |
| 7766 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7767 | struct rpc_task_setup task_setup_data = { |
| 7768 | .rpc_client = clp->cl_rpcclient, |
| 7769 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7770 | .rpc_message = &msg, |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7771 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7772 | }; |
| 7773 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7774 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7775 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 7776 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7777 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7778 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7779 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7780 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7781 | if (!calldata) |
| 7782 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7783 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7784 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7785 | |
| 7786 | status = nfs4_init_uniform_client_string(clp); |
| 7787 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7788 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7789 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7790 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7791 | GFP_NOFS); |
| 7792 | status = -ENOMEM; |
| 7793 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7794 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7795 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7796 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7797 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7798 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7799 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7800 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7801 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7802 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7803 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7804 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7805 | switch (sp4_how) { |
| 7806 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7807 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7808 | break; |
| 7809 | |
| 7810 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7811 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7812 | break; |
| 7813 | |
| 7814 | default: |
| 7815 | /* unsupported! */ |
| 7816 | WARN_ON_ONCE(1); |
| 7817 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7818 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7819 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7820 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7821 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7822 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7823 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7824 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7825 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7826 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7827 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7828 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7829 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7830 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7831 | #endif |
| 7832 | msg.rpc_argp = &calldata->args; |
| 7833 | msg.rpc_resp = &calldata->res; |
| 7834 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7835 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7836 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7837 | |
| 7838 | out_impl_id: |
| 7839 | kfree(calldata->res.impl_id); |
| 7840 | out_server_scope: |
| 7841 | kfree(calldata->res.server_scope); |
| 7842 | out_server_owner: |
| 7843 | kfree(calldata->res.server_owner); |
| 7844 | out_calldata: |
| 7845 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7846 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7847 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7848 | return ERR_PTR(status); |
| 7849 | } |
| 7850 | |
| 7851 | /* |
| 7852 | * _nfs4_proc_exchange_id() |
| 7853 | * |
| 7854 | * Wrapper for EXCHANGE_ID operation. |
| 7855 | */ |
| 7856 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7857 | u32 sp4_how) |
| 7858 | { |
| 7859 | struct rpc_task *task; |
| 7860 | struct nfs41_exchange_id_args *argp; |
| 7861 | struct nfs41_exchange_id_res *resp; |
| 7862 | int status; |
| 7863 | |
| 7864 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 7865 | if (IS_ERR(task)) |
| 7866 | return PTR_ERR(task); |
| 7867 | |
| 7868 | argp = task->tk_msg.rpc_argp; |
| 7869 | resp = task->tk_msg.rpc_resp; |
| 7870 | status = task->tk_status; |
| 7871 | if (status != 0) |
| 7872 | goto out; |
| 7873 | |
| 7874 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 7875 | if (status != 0) |
| 7876 | goto out; |
| 7877 | |
| 7878 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 7879 | if (status != 0) |
| 7880 | goto out; |
| 7881 | |
| 7882 | clp->cl_clientid = resp->clientid; |
| 7883 | clp->cl_exchange_flags = resp->flags; |
| 7884 | clp->cl_seqid = resp->seqid; |
| 7885 | /* Client ID is not confirmed */ |
| 7886 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 7887 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7888 | &clp->cl_session->session_state); |
| 7889 | |
| 7890 | if (clp->cl_serverscope != NULL && |
| 7891 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7892 | resp->server_scope)) { |
| 7893 | dprintk("%s: server_scope mismatch detected\n", |
| 7894 | __func__); |
| 7895 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7896 | } |
| 7897 | |
| 7898 | swap(clp->cl_serverowner, resp->server_owner); |
| 7899 | swap(clp->cl_serverscope, resp->server_scope); |
| 7900 | swap(clp->cl_implid, resp->impl_id); |
| 7901 | |
| 7902 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7903 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 7904 | sizeof(clp->cl_confirm.data)); |
| 7905 | out: |
| 7906 | trace_nfs4_exchange_id(clp, status); |
| 7907 | rpc_put_task(task); |
| 7908 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7909 | } |
| 7910 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7911 | /* |
| 7912 | * nfs4_proc_exchange_id() |
| 7913 | * |
| 7914 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7915 | * |
| 7916 | * Since the clientid has expired, all compounds using sessions |
| 7917 | * associated with the stale clientid will be returning |
| 7918 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7919 | * be in some phase of session reset. |
| 7920 | * |
| 7921 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7922 | */ |
| 7923 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7924 | { |
| 7925 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7926 | int status; |
| 7927 | |
| 7928 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7929 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7930 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7931 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7932 | if (!status) |
| 7933 | return 0; |
| 7934 | } |
| 7935 | |
| 7936 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7937 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7938 | } |
| 7939 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7940 | /** |
| 7941 | * nfs4_test_session_trunk |
| 7942 | * |
| 7943 | * This is an add_xprt_test() test function called from |
| 7944 | * rpc_clnt_setup_test_and_add_xprt. |
| 7945 | * |
| 7946 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7947 | * and is dereferrenced in nfs4_exchange_id_release |
| 7948 | * |
| 7949 | * Upon success, add the new transport to the rpc_clnt |
| 7950 | * |
| 7951 | * @clnt: struct rpc_clnt to get new transport |
| 7952 | * @xprt: the rpc_xprt to test |
| 7953 | * @data: call data for _nfs4_proc_exchange_id. |
| 7954 | */ |
| 7955 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7956 | void *data) |
| 7957 | { |
| 7958 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7959 | struct rpc_task *task; |
| 7960 | int status; |
| 7961 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7962 | u32 sp4_how; |
| 7963 | |
| 7964 | dprintk("--> %s try %s\n", __func__, |
| 7965 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7966 | |
| 7967 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7968 | |
| 7969 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7970 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7971 | if (IS_ERR(task)) |
| 7972 | return PTR_ERR(task); |
| 7973 | |
| 7974 | status = task->tk_status; |
| 7975 | if (status == 0) |
| 7976 | status = nfs4_detect_session_trunking(adata->clp, |
| 7977 | task->tk_msg.rpc_resp, xprt); |
| 7978 | |
| 7979 | rpc_put_task(task); |
| 7980 | return status; |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7981 | } |
| 7982 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7983 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7984 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7985 | struct rpc_cred *cred) |
| 7986 | { |
| 7987 | struct rpc_message msg = { |
| 7988 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7989 | .rpc_argp = clp, |
| 7990 | .rpc_cred = cred, |
| 7991 | }; |
| 7992 | int status; |
| 7993 | |
| 7994 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7995 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7996 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7997 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7998 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7999 | return status; |
| 8000 | } |
| 8001 | |
| 8002 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 8003 | struct rpc_cred *cred) |
| 8004 | { |
| 8005 | unsigned int loop; |
| 8006 | int ret; |
| 8007 | |
| 8008 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8009 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8010 | switch (ret) { |
| 8011 | case -NFS4ERR_DELAY: |
| 8012 | case -NFS4ERR_CLIENTID_BUSY: |
| 8013 | ssleep(1); |
| 8014 | break; |
| 8015 | default: |
| 8016 | return ret; |
| 8017 | } |
| 8018 | } |
| 8019 | return 0; |
| 8020 | } |
| 8021 | |
| 8022 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8023 | { |
| 8024 | struct rpc_cred *cred; |
| 8025 | int ret = 0; |
| 8026 | |
| 8027 | if (clp->cl_mvops->minor_version < 1) |
| 8028 | goto out; |
| 8029 | if (clp->cl_exchange_flags == 0) |
| 8030 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8031 | if (clp->cl_preserve_clid) |
| 8032 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8033 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8034 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 8035 | if (cred) |
| 8036 | put_rpccred(cred); |
| 8037 | switch (ret) { |
| 8038 | case 0: |
| 8039 | case -NFS4ERR_STALE_CLIENTID: |
| 8040 | clp->cl_exchange_flags = 0; |
| 8041 | } |
| 8042 | out: |
| 8043 | return ret; |
| 8044 | } |
| 8045 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8046 | struct nfs4_get_lease_time_data { |
| 8047 | struct nfs4_get_lease_time_args *args; |
| 8048 | struct nfs4_get_lease_time_res *res; |
| 8049 | struct nfs_client *clp; |
| 8050 | }; |
| 8051 | |
| 8052 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8053 | void *calldata) |
| 8054 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8055 | struct nfs4_get_lease_time_data *data = |
| 8056 | (struct nfs4_get_lease_time_data *)calldata; |
| 8057 | |
| 8058 | dprintk("--> %s\n", __func__); |
| 8059 | /* just setup sequence, do not trigger session recovery |
| 8060 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8061 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8062 | &data->args->la_seq_args, |
| 8063 | &data->res->lr_seq_res, |
| 8064 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8065 | dprintk("<-- %s\n", __func__); |
| 8066 | } |
| 8067 | |
| 8068 | /* |
| 8069 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8070 | * from sequence operation or clientid errors. |
| 8071 | */ |
| 8072 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8073 | { |
| 8074 | struct nfs4_get_lease_time_data *data = |
| 8075 | (struct nfs4_get_lease_time_data *)calldata; |
| 8076 | |
| 8077 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8078 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 8079 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8080 | switch (task->tk_status) { |
| 8081 | case -NFS4ERR_DELAY: |
| 8082 | case -NFS4ERR_GRACE: |
| 8083 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8084 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8085 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8086 | /* fall through */ |
| 8087 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8088 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8089 | return; |
| 8090 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8091 | dprintk("<-- %s\n", __func__); |
| 8092 | } |
| 8093 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8094 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8095 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8096 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8097 | }; |
| 8098 | |
| 8099 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8100 | { |
| 8101 | struct rpc_task *task; |
| 8102 | struct nfs4_get_lease_time_args args; |
| 8103 | struct nfs4_get_lease_time_res res = { |
| 8104 | .lr_fsinfo = fsinfo, |
| 8105 | }; |
| 8106 | struct nfs4_get_lease_time_data data = { |
| 8107 | .args = &args, |
| 8108 | .res = &res, |
| 8109 | .clp = clp, |
| 8110 | }; |
| 8111 | struct rpc_message msg = { |
| 8112 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8113 | .rpc_argp = &args, |
| 8114 | .rpc_resp = &res, |
| 8115 | }; |
| 8116 | struct rpc_task_setup task_setup = { |
| 8117 | .rpc_client = clp->cl_rpcclient, |
| 8118 | .rpc_message = &msg, |
| 8119 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8120 | .callback_data = &data, |
| 8121 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8122 | }; |
| 8123 | int status; |
| 8124 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8125 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8126 | task = rpc_run_task(&task_setup); |
| 8127 | |
| 8128 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8129 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8130 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8131 | status = task->tk_status; |
| 8132 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8133 | return status; |
| 8134 | } |
| 8135 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8136 | /* |
| 8137 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8138 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8139 | * use them. |
| 8140 | * |
| 8141 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8142 | * always set csa_cachethis to FALSE because the current implementation |
| 8143 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8144 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8145 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8146 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8147 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8148 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8149 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8150 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8151 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8152 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8153 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8154 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8155 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8156 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8157 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8158 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8159 | |
| 8160 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8161 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8162 | __func__, |
| 8163 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8164 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8165 | |
| 8166 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8167 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8168 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8169 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8170 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8171 | args->bc_attrs.max_reqs = min_t(unsigned short, max_session_cb_slots, 1); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8172 | |
| 8173 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8174 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8175 | __func__, |
| 8176 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8177 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8178 | args->bc_attrs.max_reqs); |
| 8179 | } |
| 8180 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8181 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8182 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8183 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8184 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8185 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8186 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8187 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8188 | return -EINVAL; |
| 8189 | /* |
| 8190 | * Our requested max_ops is the minimum we need; we're not |
| 8191 | * prepared to break up compounds into smaller pieces than that. |
| 8192 | * So, no point even trying to continue if the server won't |
| 8193 | * cooperate: |
| 8194 | */ |
| 8195 | if (rcvd->max_ops < sent->max_ops) |
| 8196 | return -EINVAL; |
| 8197 | if (rcvd->max_reqs == 0) |
| 8198 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8199 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8200 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8201 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8202 | } |
| 8203 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8204 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8205 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8206 | { |
| 8207 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8208 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8209 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8210 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8211 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8212 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8213 | return -EINVAL; |
| 8214 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8215 | return -EINVAL; |
| 8216 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8217 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8218 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8219 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8220 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8221 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8222 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8223 | return 0; |
| 8224 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8225 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8226 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8227 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8228 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8229 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8230 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8231 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8232 | if (ret) |
| 8233 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8234 | return nfs4_verify_back_channel_attrs(args, res); |
| 8235 | } |
| 8236 | |
| 8237 | static void nfs4_update_session(struct nfs4_session *session, |
| 8238 | struct nfs41_create_session_res *res) |
| 8239 | { |
| 8240 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8241 | /* Mark client id and session as being confirmed */ |
| 8242 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8243 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8244 | session->flags = res->flags; |
| 8245 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8246 | if (res->flags & SESSION4_BACK_CHAN) |
| 8247 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8248 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8249 | } |
| 8250 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8251 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8252 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8253 | { |
| 8254 | struct nfs4_session *session = clp->cl_session; |
| 8255 | struct nfs41_create_session_args args = { |
| 8256 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8257 | .clientid = clp->cl_clientid, |
| 8258 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8259 | .cb_program = NFS4_CALLBACK, |
| 8260 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8261 | struct nfs41_create_session_res res; |
| 8262 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8263 | struct rpc_message msg = { |
| 8264 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8265 | .rpc_argp = &args, |
| 8266 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8267 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8268 | }; |
| 8269 | int status; |
| 8270 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8271 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8272 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8273 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8274 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8275 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8276 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8277 | switch (status) { |
| 8278 | case -NFS4ERR_STALE_CLIENTID: |
| 8279 | case -NFS4ERR_DELAY: |
| 8280 | case -ETIMEDOUT: |
| 8281 | case -EACCES: |
| 8282 | case -EAGAIN: |
| 8283 | goto out; |
| 8284 | }; |
| 8285 | |
| 8286 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8287 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8288 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8289 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8290 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8291 | if (status) |
| 8292 | goto out; |
| 8293 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8294 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8295 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8296 | return status; |
| 8297 | } |
| 8298 | |
| 8299 | /* |
| 8300 | * Issues a CREATE_SESSION operation to the server. |
| 8301 | * It is the responsibility of the caller to verify the session is |
| 8302 | * expired before calling this routine. |
| 8303 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8304 | int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8305 | { |
| 8306 | int status; |
| 8307 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8308 | struct nfs4_session *session = clp->cl_session; |
| 8309 | |
| 8310 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8311 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8312 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8313 | if (status) |
| 8314 | goto out; |
| 8315 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8316 | /* Init or reset the session slot tables */ |
| 8317 | status = nfs4_setup_session_slot_tables(session); |
| 8318 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8319 | if (status) |
| 8320 | goto out; |
| 8321 | |
| 8322 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8323 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8324 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8325 | out: |
| 8326 | dprintk("<-- %s\n", __func__); |
| 8327 | return status; |
| 8328 | } |
| 8329 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8330 | /* |
| 8331 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8332 | * The caller must serialize access to this routine. |
| 8333 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8334 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8335 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8336 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8337 | struct rpc_message msg = { |
| 8338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8339 | .rpc_argp = session, |
| 8340 | .rpc_cred = cred, |
| 8341 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8342 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8343 | |
| 8344 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8345 | |
| 8346 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8347 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8348 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8349 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8350 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8351 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8352 | |
| 8353 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8354 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8355 | "Session has been destroyed regardless...\n", status); |
| 8356 | |
| 8357 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8358 | return status; |
| 8359 | } |
| 8360 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8361 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8362 | * Renew the cl_session lease. |
| 8363 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8364 | struct nfs4_sequence_data { |
| 8365 | struct nfs_client *clp; |
| 8366 | struct nfs4_sequence_args args; |
| 8367 | struct nfs4_sequence_res res; |
| 8368 | }; |
| 8369 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8370 | static void nfs41_sequence_release(void *data) |
| 8371 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8372 | struct nfs4_sequence_data *calldata = data; |
| 8373 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8374 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8375 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8376 | nfs4_schedule_state_renewal(clp); |
| 8377 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8378 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8379 | } |
| 8380 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8381 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8382 | { |
| 8383 | switch(task->tk_status) { |
| 8384 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8385 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8386 | return -EAGAIN; |
| 8387 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8388 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8389 | } |
| 8390 | return 0; |
| 8391 | } |
| 8392 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8393 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8394 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8395 | struct nfs4_sequence_data *calldata = data; |
| 8396 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8397 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8398 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8399 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8400 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8401 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8402 | if (task->tk_status < 0) { |
| 8403 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8404 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8405 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8406 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8407 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8408 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8409 | return; |
| 8410 | } |
| 8411 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8412 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8413 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8414 | dprintk("<-- %s\n", __func__); |
| 8415 | } |
| 8416 | |
| 8417 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8418 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8419 | struct nfs4_sequence_data *calldata = data; |
| 8420 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8421 | struct nfs4_sequence_args *args; |
| 8422 | struct nfs4_sequence_res *res; |
| 8423 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8424 | args = task->tk_msg.rpc_argp; |
| 8425 | res = task->tk_msg.rpc_resp; |
| 8426 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8427 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8428 | } |
| 8429 | |
| 8430 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8431 | .rpc_call_done = nfs41_sequence_call_done, |
| 8432 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8433 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8434 | }; |
| 8435 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8436 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8437 | struct rpc_cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8438 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8439 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8440 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8441 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8442 | struct rpc_message msg = { |
| 8443 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8444 | .rpc_cred = cred, |
| 8445 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8446 | struct rpc_task_setup task_setup_data = { |
| 8447 | .rpc_client = clp->cl_rpcclient, |
| 8448 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8449 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8450 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8451 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8452 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8453 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8454 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8455 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8456 | goto out_err; |
| 8457 | |
| 8458 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8459 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8460 | if (calldata == NULL) |
| 8461 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8462 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8463 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8464 | msg.rpc_argp = &calldata->args; |
| 8465 | msg.rpc_resp = &calldata->res; |
| 8466 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8467 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8468 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8469 | ret = rpc_run_task(&task_setup_data); |
| 8470 | if (IS_ERR(ret)) |
| 8471 | goto out_err; |
| 8472 | return ret; |
| 8473 | out_put_clp: |
| 8474 | nfs_put_client(clp); |
| 8475 | out_err: |
| 8476 | nfs41_release_slot(slot); |
| 8477 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8478 | } |
| 8479 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8480 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8481 | { |
| 8482 | struct rpc_task *task; |
| 8483 | int ret = 0; |
| 8484 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8485 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8486 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8487 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8488 | if (IS_ERR(task)) |
| 8489 | ret = PTR_ERR(task); |
| 8490 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8491 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8492 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8493 | return ret; |
| 8494 | } |
| 8495 | |
| 8496 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8497 | { |
| 8498 | struct rpc_task *task; |
| 8499 | int ret; |
| 8500 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8501 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8502 | if (IS_ERR(task)) { |
| 8503 | ret = PTR_ERR(task); |
| 8504 | goto out; |
| 8505 | } |
| 8506 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8507 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8508 | ret = task->tk_status; |
| 8509 | rpc_put_task(task); |
| 8510 | out: |
| 8511 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8512 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8513 | } |
| 8514 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8515 | struct nfs4_reclaim_complete_data { |
| 8516 | struct nfs_client *clp; |
| 8517 | struct nfs41_reclaim_complete_args arg; |
| 8518 | struct nfs41_reclaim_complete_res res; |
| 8519 | }; |
| 8520 | |
| 8521 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8522 | { |
| 8523 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8524 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8525 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8526 | &calldata->arg.seq_args, |
| 8527 | &calldata->res.seq_res, |
| 8528 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8529 | } |
| 8530 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8531 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8532 | { |
| 8533 | switch(task->tk_status) { |
| 8534 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8535 | wake_up_all(&clp->cl_lock_waitq); |
| 8536 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8537 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8538 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8539 | break; |
| 8540 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8541 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8542 | /* fall through */ |
| 8543 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8544 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8545 | case -NFS4ERR_BADSESSION: |
| 8546 | case -NFS4ERR_DEADSESSION: |
| 8547 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8548 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8549 | task->tk_status); |
| 8550 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8551 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8552 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8553 | } |
| 8554 | return 0; |
| 8555 | } |
| 8556 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8557 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8558 | { |
| 8559 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8560 | struct nfs_client *clp = calldata->clp; |
| 8561 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8562 | |
| 8563 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8564 | if (!nfs41_sequence_done(task, res)) |
| 8565 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8566 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8567 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8568 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8569 | rpc_restart_call_prepare(task); |
| 8570 | return; |
| 8571 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8572 | dprintk("<-- %s\n", __func__); |
| 8573 | } |
| 8574 | |
| 8575 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8576 | { |
| 8577 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8578 | |
| 8579 | kfree(calldata); |
| 8580 | } |
| 8581 | |
| 8582 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8583 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8584 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8585 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8586 | }; |
| 8587 | |
| 8588 | /* |
| 8589 | * Issue a global reclaim complete. |
| 8590 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8591 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8592 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8593 | { |
| 8594 | struct nfs4_reclaim_complete_data *calldata; |
| 8595 | struct rpc_task *task; |
| 8596 | struct rpc_message msg = { |
| 8597 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8598 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8599 | }; |
| 8600 | struct rpc_task_setup task_setup_data = { |
| 8601 | .rpc_client = clp->cl_rpcclient, |
| 8602 | .rpc_message = &msg, |
| 8603 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8604 | .flags = RPC_TASK_ASYNC, |
| 8605 | }; |
| 8606 | int status = -ENOMEM; |
| 8607 | |
| 8608 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8609 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8610 | if (calldata == NULL) |
| 8611 | goto out; |
| 8612 | calldata->clp = clp; |
| 8613 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8614 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8615 | 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] | 8616 | msg.rpc_argp = &calldata->arg; |
| 8617 | msg.rpc_resp = &calldata->res; |
| 8618 | task_setup_data.callback_data = calldata; |
| 8619 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8620 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8621 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8622 | goto out; |
| 8623 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8624 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8625 | if (status == 0) |
| 8626 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8627 | rpc_put_task(task); |
| 8628 | out: |
| 8629 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8630 | return status; |
| 8631 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8632 | |
| 8633 | static void |
| 8634 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8635 | { |
| 8636 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8637 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8638 | |
| 8639 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8640 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8641 | &lgp->res.seq_res, task); |
| 8642 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8643 | } |
| 8644 | |
| 8645 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8646 | { |
| 8647 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8648 | |
| 8649 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8650 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8651 | dprintk("<-- %s\n", __func__); |
| 8652 | } |
| 8653 | |
| 8654 | static int |
| 8655 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8656 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8657 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8658 | struct inode *inode = lgp->args.inode; |
| 8659 | struct nfs_server *server = NFS_SERVER(inode); |
| 8660 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8661 | int nfs4err = task->tk_status; |
| 8662 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8663 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8664 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8665 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8666 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8667 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 8668 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8669 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8670 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8671 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8672 | |
| 8673 | /* |
| 8674 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8675 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8676 | * retry go inband. |
| 8677 | */ |
| 8678 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8679 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8680 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8681 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8682 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8683 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8684 | */ |
| 8685 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8686 | status = -EOVERFLOW; |
| 8687 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8688 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8689 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8690 | * (or clients) writing to the same RAID stripe except when |
| 8691 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8692 | * |
| 8693 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8694 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8695 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8696 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8697 | if (lgp->args.minlength == 0) { |
| 8698 | status = -EOVERFLOW; |
| 8699 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8700 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8701 | status = -EBUSY; |
| 8702 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8703 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8704 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8705 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8706 | case -NFS4ERR_DELEG_REVOKED: |
| 8707 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8708 | case -NFS4ERR_EXPIRED: |
| 8709 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8710 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8711 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8712 | lo = NFS_I(inode)->layout; |
| 8713 | /* If the open stateid was bad, then recover it. */ |
| 8714 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8715 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8716 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8717 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8718 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8719 | break; |
| 8720 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8721 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8722 | /* |
| 8723 | * Mark the bad layout state as invalid, then retry |
| 8724 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8725 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8726 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8727 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8728 | pnfs_free_lseg_list(&head); |
| 8729 | status = -EAGAIN; |
| 8730 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8731 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8732 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8733 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8734 | if (!status) { |
| 8735 | if (exception->retry) |
| 8736 | status = -EAGAIN; |
| 8737 | else |
| 8738 | status = err; |
| 8739 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8740 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8741 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8742 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8743 | } |
| 8744 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8745 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8746 | { |
| 8747 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8748 | return nfs_page_array_len(0, max_resp_sz); |
| 8749 | } |
| 8750 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8751 | static void nfs4_layoutget_release(void *calldata) |
| 8752 | { |
| 8753 | struct nfs4_layoutget *lgp = calldata; |
| 8754 | |
| 8755 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8756 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 8757 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8758 | dprintk("<-- %s\n", __func__); |
| 8759 | } |
| 8760 | |
| 8761 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8762 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8763 | .rpc_call_done = nfs4_layoutget_done, |
| 8764 | .rpc_release = nfs4_layoutget_release, |
| 8765 | }; |
| 8766 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8767 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8768 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8769 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8770 | struct inode *inode = lgp->args.inode; |
| 8771 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8772 | struct rpc_task *task; |
| 8773 | struct rpc_message msg = { |
| 8774 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8775 | .rpc_argp = &lgp->args, |
| 8776 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8777 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8778 | }; |
| 8779 | struct rpc_task_setup task_setup_data = { |
| 8780 | .rpc_client = server->client, |
| 8781 | .rpc_message = &msg, |
| 8782 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8783 | .callback_data = lgp, |
| 8784 | .flags = RPC_TASK_ASYNC, |
| 8785 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8786 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8787 | struct nfs4_exception exception = { |
| 8788 | .inode = inode, |
| 8789 | .timeout = *timeout, |
| 8790 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8791 | int status = 0; |
| 8792 | |
| 8793 | dprintk("--> %s\n", __func__); |
| 8794 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8795 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8796 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8797 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8798 | 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] | 8799 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8800 | task = rpc_run_task(&task_setup_data); |
| 8801 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8802 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8803 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8804 | if (status != 0) |
| 8805 | goto out; |
| 8806 | |
| 8807 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8808 | if (task->tk_status < 0 || lgp->res.layoutp->len == 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8809 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8810 | *timeout = exception.timeout; |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8811 | } else |
| 8812 | lseg = pnfs_layout_process(lgp); |
| 8813 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8814 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8815 | &lgp->args.range, |
| 8816 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8817 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8818 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8819 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8820 | rpc_put_task(task); |
| 8821 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8822 | if (status) |
| 8823 | return ERR_PTR(status); |
| 8824 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8825 | } |
| 8826 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8827 | static void |
| 8828 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8829 | { |
| 8830 | struct nfs4_layoutreturn *lrp = calldata; |
| 8831 | |
| 8832 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8833 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8834 | &lrp->args.seq_args, |
| 8835 | &lrp->res.seq_res, |
| 8836 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame^] | 8837 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 8838 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8839 | } |
| 8840 | |
| 8841 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8842 | { |
| 8843 | struct nfs4_layoutreturn *lrp = calldata; |
| 8844 | struct nfs_server *server; |
| 8845 | |
| 8846 | dprintk("--> %s\n", __func__); |
| 8847 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8848 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8849 | return; |
| 8850 | |
| 8851 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8852 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8853 | case -NFS4ERR_OLD_STATEID: |
| 8854 | if (nfs4_refresh_layout_stateid(&lrp->args.stateid, |
| 8855 | lrp->args.inode)) |
| 8856 | goto out_restart; |
| 8857 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8858 | default: |
| 8859 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8860 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8861 | case 0: |
| 8862 | break; |
| 8863 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8864 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8865 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8866 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8867 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8868 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8869 | return; |
| 8870 | out_restart: |
| 8871 | task->tk_status = 0; |
| 8872 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 8873 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8874 | } |
| 8875 | |
| 8876 | static void nfs4_layoutreturn_release(void *calldata) |
| 8877 | { |
| 8878 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8879 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8880 | |
| 8881 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8882 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8883 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8884 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8885 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8886 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8887 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8888 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8889 | kfree(calldata); |
| 8890 | dprintk("<-- %s\n", __func__); |
| 8891 | } |
| 8892 | |
| 8893 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8894 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8895 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8896 | .rpc_release = nfs4_layoutreturn_release, |
| 8897 | }; |
| 8898 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8899 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8900 | { |
| 8901 | struct rpc_task *task; |
| 8902 | struct rpc_message msg = { |
| 8903 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8904 | .rpc_argp = &lrp->args, |
| 8905 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8906 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8907 | }; |
| 8908 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8909 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8910 | .rpc_message = &msg, |
| 8911 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8912 | .callback_data = lrp, |
| 8913 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8914 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8915 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8916 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8917 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8918 | &task_setup_data.rpc_client, &msg); |
| 8919 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8920 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8921 | if (!sync) { |
| 8922 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8923 | if (!lrp->inode) { |
| 8924 | nfs4_layoutreturn_release(lrp); |
| 8925 | return -EAGAIN; |
| 8926 | } |
| 8927 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8928 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8929 | 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] | 8930 | task = rpc_run_task(&task_setup_data); |
| 8931 | if (IS_ERR(task)) |
| 8932 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8933 | if (sync) |
| 8934 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8935 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8936 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8937 | rpc_put_task(task); |
| 8938 | return status; |
| 8939 | } |
| 8940 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8941 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8942 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8943 | struct pnfs_device *pdev, |
| 8944 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8945 | { |
| 8946 | struct nfs4_getdeviceinfo_args args = { |
| 8947 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8948 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8949 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8950 | }; |
| 8951 | struct nfs4_getdeviceinfo_res res = { |
| 8952 | .pdev = pdev, |
| 8953 | }; |
| 8954 | struct rpc_message msg = { |
| 8955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8956 | .rpc_argp = &args, |
| 8957 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8958 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8959 | }; |
| 8960 | int status; |
| 8961 | |
| 8962 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8963 | 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] | 8964 | if (res.notification & ~args.notify_types) |
| 8965 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8966 | if (res.notification != args.notify_types) |
| 8967 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8968 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8969 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8970 | |
| 8971 | return status; |
| 8972 | } |
| 8973 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8974 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8975 | struct pnfs_device *pdev, |
| 8976 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8977 | { |
| 8978 | struct nfs4_exception exception = { }; |
| 8979 | int err; |
| 8980 | |
| 8981 | do { |
| 8982 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8983 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8984 | &exception); |
| 8985 | } while (exception.retry); |
| 8986 | return err; |
| 8987 | } |
| 8988 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8989 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8990 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8991 | { |
| 8992 | struct nfs4_layoutcommit_data *data = calldata; |
| 8993 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8994 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8995 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8996 | &data->args.seq_args, |
| 8997 | &data->res.seq_res, |
| 8998 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8999 | } |
| 9000 | |
| 9001 | static void |
| 9002 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9003 | { |
| 9004 | struct nfs4_layoutcommit_data *data = calldata; |
| 9005 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9006 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9007 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9008 | return; |
| 9009 | |
| 9010 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9011 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9012 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9013 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9014 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9015 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9016 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9017 | break; |
| 9018 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9019 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9020 | rpc_restart_call_prepare(task); |
| 9021 | return; |
| 9022 | } |
| 9023 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9024 | } |
| 9025 | |
| 9026 | static void nfs4_layoutcommit_release(void *calldata) |
| 9027 | { |
| 9028 | struct nfs4_layoutcommit_data *data = calldata; |
| 9029 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9030 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9031 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9032 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9033 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9034 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9035 | kfree(data); |
| 9036 | } |
| 9037 | |
| 9038 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9039 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9040 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9041 | .rpc_release = nfs4_layoutcommit_release, |
| 9042 | }; |
| 9043 | |
| 9044 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9045 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9046 | { |
| 9047 | struct rpc_message msg = { |
| 9048 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9049 | .rpc_argp = &data->args, |
| 9050 | .rpc_resp = &data->res, |
| 9051 | .rpc_cred = data->cred, |
| 9052 | }; |
| 9053 | struct rpc_task_setup task_setup_data = { |
| 9054 | .task = &data->task, |
| 9055 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9056 | .rpc_message = &msg, |
| 9057 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9058 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9059 | }; |
| 9060 | struct rpc_task *task; |
| 9061 | int status = 0; |
| 9062 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9063 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9064 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9065 | data->args.lastbytewritten, |
| 9066 | data->args.inode->i_ino); |
| 9067 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9068 | if (!sync) { |
| 9069 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9070 | if (data->inode == NULL) { |
| 9071 | nfs4_layoutcommit_release(data); |
| 9072 | return -EAGAIN; |
| 9073 | } |
| 9074 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9075 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9076 | 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] | 9077 | task = rpc_run_task(&task_setup_data); |
| 9078 | if (IS_ERR(task)) |
| 9079 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9080 | if (sync) |
| 9081 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9082 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9083 | dprintk("%s: status %d\n", __func__, status); |
| 9084 | rpc_put_task(task); |
| 9085 | return status; |
| 9086 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9087 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9088 | /** |
| 9089 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9090 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9091 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9092 | static int |
| 9093 | _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] | 9094 | struct nfs_fsinfo *info, |
| 9095 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9096 | { |
| 9097 | struct nfs41_secinfo_no_name_args args = { |
| 9098 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9099 | }; |
| 9100 | struct nfs4_secinfo_res res = { |
| 9101 | .flavors = flavors, |
| 9102 | }; |
| 9103 | struct rpc_message msg = { |
| 9104 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9105 | .rpc_argp = &args, |
| 9106 | .rpc_resp = &res, |
| 9107 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9108 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9109 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9110 | int status; |
| 9111 | |
| 9112 | if (use_integrity) { |
| 9113 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9114 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9115 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9116 | } |
| 9117 | |
| 9118 | dprintk("--> %s\n", __func__); |
| 9119 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 9120 | &res.seq_res, 0); |
| 9121 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9122 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9123 | if (cred) |
| 9124 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9125 | |
| 9126 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9127 | } |
| 9128 | |
| 9129 | static int |
| 9130 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9131 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9132 | { |
| 9133 | struct nfs4_exception exception = { }; |
| 9134 | int err; |
| 9135 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9136 | /* first try using integrity protection */ |
| 9137 | err = -NFS4ERR_WRONGSEC; |
| 9138 | |
| 9139 | /* try to use integrity protection with machine cred */ |
| 9140 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9141 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9142 | flavors, true); |
| 9143 | |
| 9144 | /* |
| 9145 | * if unable to use integrity protection, or SECINFO with |
| 9146 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9147 | * disallowed by spec, but exists in deployed servers) use |
| 9148 | * the current filesystem's rpc_client and the user cred. |
| 9149 | */ |
| 9150 | if (err == -NFS4ERR_WRONGSEC) |
| 9151 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9152 | flavors, false); |
| 9153 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9154 | switch (err) { |
| 9155 | case 0: |
| 9156 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9157 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9158 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9159 | default: |
| 9160 | err = nfs4_handle_exception(server, err, &exception); |
| 9161 | } |
| 9162 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9163 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9164 | return err; |
| 9165 | } |
| 9166 | |
| 9167 | static int |
| 9168 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9169 | struct nfs_fsinfo *info) |
| 9170 | { |
| 9171 | int err; |
| 9172 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9173 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9174 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9175 | struct nfs4_secinfo4 *secinfo; |
| 9176 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9177 | |
| 9178 | page = alloc_page(GFP_KERNEL); |
| 9179 | if (!page) { |
| 9180 | err = -ENOMEM; |
| 9181 | goto out; |
| 9182 | } |
| 9183 | |
| 9184 | flavors = page_address(page); |
| 9185 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9186 | |
| 9187 | /* |
| 9188 | * Fall back on "guess and check" method if |
| 9189 | * the server doesn't support SECINFO_NO_NAME |
| 9190 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9191 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9192 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9193 | goto out_freepage; |
| 9194 | } |
| 9195 | if (err) |
| 9196 | goto out_freepage; |
| 9197 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9198 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9199 | secinfo = &flavors->flavors[i]; |
| 9200 | |
| 9201 | switch (secinfo->flavor) { |
| 9202 | case RPC_AUTH_NULL: |
| 9203 | case RPC_AUTH_UNIX: |
| 9204 | case RPC_AUTH_GSS: |
| 9205 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9206 | &secinfo->flavor_info); |
| 9207 | break; |
| 9208 | default: |
| 9209 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9210 | break; |
| 9211 | } |
| 9212 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9213 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9214 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9215 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9216 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9217 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9218 | info, flavor); |
| 9219 | if (!err) |
| 9220 | break; |
| 9221 | } |
| 9222 | } |
| 9223 | |
| 9224 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9225 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9226 | |
| 9227 | out_freepage: |
| 9228 | put_page(page); |
| 9229 | if (err == -EACCES) |
| 9230 | return -EPERM; |
| 9231 | out: |
| 9232 | return err; |
| 9233 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9234 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9235 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9236 | nfs4_stateid *stateid, |
| 9237 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9238 | { |
| 9239 | int status; |
| 9240 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9241 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9242 | }; |
| 9243 | struct nfs41_test_stateid_res res; |
| 9244 | struct rpc_message msg = { |
| 9245 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9246 | .rpc_argp = &args, |
| 9247 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9248 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9249 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9250 | struct rpc_clnt *rpc_client = server->client; |
| 9251 | |
| 9252 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9253 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9254 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9255 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9256 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9257 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9258 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9259 | if (status != NFS_OK) { |
| 9260 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9261 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9262 | } |
| 9263 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9264 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9265 | } |
| 9266 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9267 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9268 | int err, struct nfs4_exception *exception) |
| 9269 | { |
| 9270 | exception->retry = 0; |
| 9271 | switch(err) { |
| 9272 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9273 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9274 | nfs4_handle_exception(server, err, exception); |
| 9275 | break; |
| 9276 | case -NFS4ERR_BADSESSION: |
| 9277 | case -NFS4ERR_BADSLOT: |
| 9278 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9279 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9280 | case -NFS4ERR_DEADSESSION: |
| 9281 | nfs4_do_handle_exception(server, err, exception); |
| 9282 | } |
| 9283 | } |
| 9284 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9285 | /** |
| 9286 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9287 | * |
| 9288 | * @server: server / transport on which to perform the operation |
| 9289 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9290 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9291 | * |
| 9292 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9293 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9294 | * failed or the state ID is not currently valid. |
| 9295 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9296 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9297 | nfs4_stateid *stateid, |
| 9298 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9299 | { |
| 9300 | struct nfs4_exception exception = { }; |
| 9301 | int err; |
| 9302 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9303 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9304 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9305 | } while (exception.retry); |
| 9306 | return err; |
| 9307 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9308 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9309 | struct nfs_free_stateid_data { |
| 9310 | struct nfs_server *server; |
| 9311 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9312 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9313 | }; |
| 9314 | |
| 9315 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9316 | { |
| 9317 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9318 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9319 | &data->args.seq_args, |
| 9320 | &data->res.seq_res, |
| 9321 | task); |
| 9322 | } |
| 9323 | |
| 9324 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9325 | { |
| 9326 | struct nfs_free_stateid_data *data = calldata; |
| 9327 | |
| 9328 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9329 | |
| 9330 | switch (task->tk_status) { |
| 9331 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9332 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9333 | rpc_restart_call_prepare(task); |
| 9334 | } |
| 9335 | } |
| 9336 | |
| 9337 | static void nfs41_free_stateid_release(void *calldata) |
| 9338 | { |
| 9339 | kfree(calldata); |
| 9340 | } |
| 9341 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9342 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9343 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9344 | .rpc_call_done = nfs41_free_stateid_done, |
| 9345 | .rpc_release = nfs41_free_stateid_release, |
| 9346 | }; |
| 9347 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9348 | /** |
| 9349 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9350 | * |
| 9351 | * @server: server / transport on which to perform the operation |
| 9352 | * @stateid: state ID to release |
| 9353 | * @cred: credential |
| 9354 | * @is_recovery: set to true if this call needs to be privileged |
| 9355 | * |
| 9356 | * Note: this function is always asynchronous. |
| 9357 | */ |
| 9358 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9359 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9360 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9361 | bool privileged) |
| 9362 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9363 | struct rpc_message msg = { |
| 9364 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9365 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9366 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9367 | struct rpc_task_setup task_setup = { |
| 9368 | .rpc_client = server->client, |
| 9369 | .rpc_message = &msg, |
| 9370 | .callback_ops = &nfs41_free_stateid_ops, |
| 9371 | .flags = RPC_TASK_ASYNC, |
| 9372 | }; |
| 9373 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9374 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9375 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9376 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9377 | &task_setup.rpc_client, &msg); |
| 9378 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9379 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9380 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9381 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9382 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9383 | data->server = server; |
| 9384 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9385 | |
| 9386 | task_setup.callback_data = data; |
| 9387 | |
| 9388 | msg.rpc_argp = &data->args; |
| 9389 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9390 | 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] | 9391 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9392 | if (IS_ERR(task)) |
| 9393 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9394 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9395 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9396 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9397 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9398 | static void |
| 9399 | 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] | 9400 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9401 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9402 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9403 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9404 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9405 | } |
| 9406 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9407 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9408 | const nfs4_stateid *s2) |
| 9409 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9410 | if (s1->type != s2->type) |
| 9411 | return false; |
| 9412 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9413 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9414 | return false; |
| 9415 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9416 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9417 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9418 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9419 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9420 | } |
| 9421 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9422 | #endif /* CONFIG_NFS_V4_1 */ |
| 9423 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9424 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9425 | const nfs4_stateid *s2) |
| 9426 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9427 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9428 | } |
| 9429 | |
| 9430 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9431 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9432 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9433 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9434 | .recover_open = nfs4_open_reclaim, |
| 9435 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9436 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9437 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9438 | }; |
| 9439 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9440 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9441 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9442 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9443 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9444 | .recover_open = nfs4_open_reclaim, |
| 9445 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9446 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9447 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9448 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9449 | }; |
| 9450 | #endif /* CONFIG_NFS_V4_1 */ |
| 9451 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9452 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9453 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9454 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9455 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9456 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9457 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9458 | }; |
| 9459 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9460 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9461 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9462 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9463 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9464 | .recover_open = nfs41_open_expired, |
| 9465 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9466 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9467 | }; |
| 9468 | #endif /* CONFIG_NFS_V4_1 */ |
| 9469 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9470 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9471 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9472 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9473 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9474 | }; |
| 9475 | |
| 9476 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9477 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9478 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9479 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9480 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9481 | }; |
| 9482 | #endif |
| 9483 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9484 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9485 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9486 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9487 | }; |
| 9488 | |
| 9489 | #if defined(CONFIG_NFS_V4_1) |
| 9490 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9491 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9492 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9493 | }; |
| 9494 | #endif /* CONFIG_NFS_V4_1 */ |
| 9495 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9496 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9497 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9498 | .init_caps = NFS_CAP_READDIRPLUS |
| 9499 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9500 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9501 | .init_client = nfs40_init_client, |
| 9502 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9503 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9504 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9505 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9506 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9507 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9508 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9509 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9510 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9511 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9512 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9513 | }; |
| 9514 | |
| 9515 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9516 | static struct nfs_seqid * |
| 9517 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9518 | { |
| 9519 | return NULL; |
| 9520 | } |
| 9521 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9522 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9523 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9524 | .init_caps = NFS_CAP_READDIRPLUS |
| 9525 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9526 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9527 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9528 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9529 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9530 | .init_client = nfs41_init_client, |
| 9531 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9532 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9533 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9534 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9535 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9536 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9537 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9538 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9539 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9540 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9541 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9542 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9543 | }; |
| 9544 | #endif |
| 9545 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9546 | #if defined(CONFIG_NFS_V4_2) |
| 9547 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9548 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9549 | .init_caps = NFS_CAP_READDIRPLUS |
| 9550 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9551 | | NFS_CAP_POSIX_LOCK |
| 9552 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9553 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9554 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9555 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9556 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9557 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9558 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9559 | | NFS_CAP_LAYOUTSTATS |
| 9560 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9561 | .init_client = nfs41_init_client, |
| 9562 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9563 | .match_stateid = nfs41_match_stateid, |
| 9564 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9565 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9566 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9567 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9568 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9569 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9570 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9571 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9572 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9573 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9574 | }; |
| 9575 | #endif |
| 9576 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9577 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9578 | [0] = &nfs_v4_0_minor_ops, |
| 9579 | #if defined(CONFIG_NFS_V4_1) |
| 9580 | [1] = &nfs_v4_1_minor_ops, |
| 9581 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9582 | #if defined(CONFIG_NFS_V4_2) |
| 9583 | [2] = &nfs_v4_2_minor_ops, |
| 9584 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9585 | }; |
| 9586 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9587 | 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] | 9588 | { |
| 9589 | ssize_t error, error2; |
| 9590 | |
| 9591 | error = generic_listxattr(dentry, list, size); |
| 9592 | if (error < 0) |
| 9593 | return error; |
| 9594 | if (list) { |
| 9595 | list += error; |
| 9596 | size -= error; |
| 9597 | } |
| 9598 | |
| 9599 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9600 | if (error2 < 0) |
| 9601 | return error2; |
| 9602 | return error + error2; |
| 9603 | } |
| 9604 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9605 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9606 | .create = nfs_create, |
| 9607 | .lookup = nfs_lookup, |
| 9608 | .atomic_open = nfs_atomic_open, |
| 9609 | .link = nfs_link, |
| 9610 | .unlink = nfs_unlink, |
| 9611 | .symlink = nfs_symlink, |
| 9612 | .mkdir = nfs_mkdir, |
| 9613 | .rmdir = nfs_rmdir, |
| 9614 | .mknod = nfs_mknod, |
| 9615 | .rename = nfs_rename, |
| 9616 | .permission = nfs_permission, |
| 9617 | .getattr = nfs_getattr, |
| 9618 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9619 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9620 | }; |
| 9621 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9622 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9623 | .permission = nfs_permission, |
| 9624 | .getattr = nfs_getattr, |
| 9625 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9626 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9627 | }; |
| 9628 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9629 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9630 | .version = 4, /* protocol version */ |
| 9631 | .dentry_ops = &nfs4_dentry_operations, |
| 9632 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9633 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9634 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9635 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9636 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9637 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9638 | .getattr = nfs4_proc_getattr, |
| 9639 | .setattr = nfs4_proc_setattr, |
| 9640 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9641 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9642 | .access = nfs4_proc_access, |
| 9643 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9644 | .create = nfs4_proc_create, |
| 9645 | .remove = nfs4_proc_remove, |
| 9646 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9647 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9648 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9649 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9650 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9651 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9652 | .link = nfs4_proc_link, |
| 9653 | .symlink = nfs4_proc_symlink, |
| 9654 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 9655 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9656 | .readdir = nfs4_proc_readdir, |
| 9657 | .mknod = nfs4_proc_mknod, |
| 9658 | .statfs = nfs4_proc_statfs, |
| 9659 | .fsinfo = nfs4_proc_fsinfo, |
| 9660 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9661 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9662 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9663 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9664 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9665 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9666 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9667 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9668 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9669 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9670 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9671 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9672 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9673 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9674 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9675 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9676 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9677 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9678 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9679 | .create_server = nfs4_create_server, |
| 9680 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9681 | }; |
| 9682 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9683 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9684 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9685 | .list = nfs4_xattr_list_nfs4_acl, |
| 9686 | .get = nfs4_xattr_get_nfs4_acl, |
| 9687 | .set = nfs4_xattr_set_nfs4_acl, |
| 9688 | }; |
| 9689 | |
| 9690 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9691 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9692 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9693 | &nfs4_xattr_nfs4_label_handler, |
| 9694 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9695 | NULL |
| 9696 | }; |
| 9697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9698 | /* |
| 9699 | * Local variables: |
| 9700 | * c-basic-offset: 8 |
| 9701 | * End: |
| 9702 | */ |