| 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> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 |  | 
| Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 58 | #include "nfs4_fs.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "delegation.h" | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 60 | #include "internal.h" | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 61 | #include "iostat.h" | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 62 | #include "callback.h" | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 63 | #include "pnfs.h" | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 64 | #include "netns.h" | 
| Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 65 | #include "nfs4idmap.h" | 
| Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" | 
| David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" | 
|  | 70 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY		NFSDBG_PROC | 
|  | 72 |  | 
| Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN	(HZ/10) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX	(15*HZ) | 
|  | 75 |  | 
| Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 76 | /* file attributes which can be mapped to nfs attributes */ | 
|  | 77 | #define NFS4_VALID_ATTRS (ATTR_MODE \ | 
|  | 78 | | ATTR_UID \ | 
|  | 79 | | ATTR_GID \ | 
|  | 80 | | ATTR_SIZE \ | 
|  | 81 | | ATTR_ATIME \ | 
|  | 82 | | ATTR_MTIME \ | 
|  | 83 | | ATTR_CTIME \ | 
|  | 84 | | ATTR_ATIME_SET \ | 
|  | 85 | | ATTR_MTIME_SET) | 
|  | 86 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 87 | struct nfs4_opendata; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 88 | static int _nfs4_proc_open(struct nfs4_opendata *data); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 89 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | 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] | 91 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 92 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); | 
|  | 93 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); | 
| Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 94 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
|  | 95 | struct nfs_fattr *fattr, struct iattr *sattr, | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 96 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_label *olabel); | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 98 | #ifdef CONFIG_NFS_V4_1 | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 99 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, | 
|  | 100 | struct rpc_cred *cred, | 
|  | 101 | struct nfs4_slot *slot, | 
|  | 102 | bool is_privileged); | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 103 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, | 
|  | 104 | struct rpc_cred *); | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 105 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, | 
|  | 106 | struct rpc_cred *, bool); | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 107 | #endif | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 108 |  | 
|  | 109 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 110 | static inline struct nfs4_label * | 
|  | 111 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, | 
|  | 112 | struct iattr *sattr, struct nfs4_label *label) | 
|  | 113 | { | 
|  | 114 | int err; | 
|  | 115 |  | 
|  | 116 | if (label == NULL) | 
|  | 117 | return NULL; | 
|  | 118 |  | 
|  | 119 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) | 
|  | 120 | return NULL; | 
|  | 121 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 122 | err = security_dentry_init_security(dentry, sattr->ia_mode, | 
|  | 123 | &dentry->d_name, (void **)&label->label, &label->len); | 
|  | 124 | if (err == 0) | 
|  | 125 | return label; | 
|  | 126 |  | 
|  | 127 | return NULL; | 
|  | 128 | } | 
|  | 129 | static inline void | 
|  | 130 | nfs4_label_release_security(struct nfs4_label *label) | 
|  | 131 | { | 
|  | 132 | if (label) | 
|  | 133 | security_release_secctx(label->label, label->len); | 
|  | 134 | } | 
|  | 135 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) | 
|  | 136 | { | 
|  | 137 | if (label) | 
|  | 138 | return server->attr_bitmask; | 
|  | 139 |  | 
|  | 140 | return server->attr_bitmask_nl; | 
|  | 141 | } | 
|  | 142 | #else | 
|  | 143 | static inline struct nfs4_label * | 
|  | 144 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, | 
|  | 145 | struct iattr *sattr, struct nfs4_label *l) | 
|  | 146 | { return NULL; } | 
|  | 147 | static inline void | 
|  | 148 | nfs4_label_release_security(struct nfs4_label *label) | 
|  | 149 | { return; } | 
|  | 150 | static inline u32 * | 
|  | 151 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) | 
|  | 152 | { return server->attr_bitmask; } | 
|  | 153 | #endif | 
|  | 154 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* Prevent leaks of NFSv4 errors into userland */ | 
| WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 156 | static int nfs4_map_errors(int err) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 158 | if (err >= -1000) | 
|  | 159 | return err; | 
|  | 160 | switch (err) { | 
|  | 161 | case -NFS4ERR_RESOURCE: | 
| Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 162 | case -NFS4ERR_LAYOUTTRYLATER: | 
|  | 163 | case -NFS4ERR_RECALLCONFLICT: | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 164 | return -EREMOTEIO; | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 165 | case -NFS4ERR_WRONGSEC: | 
| Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 166 | case -NFS4ERR_WRONG_CRED: | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 167 | return -EPERM; | 
| Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 168 | case -NFS4ERR_BADOWNER: | 
|  | 169 | case -NFS4ERR_BADNAME: | 
|  | 170 | return -EINVAL; | 
| Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 171 | case -NFS4ERR_SHARE_DENIED: | 
|  | 172 | return -EACCES; | 
| Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 173 | case -NFS4ERR_MINOR_VERS_MISMATCH: | 
|  | 174 | return -EPROTONOSUPPORT; | 
| Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 175 | case -NFS4ERR_FILE_OPEN: | 
|  | 176 | return -EBUSY; | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | default: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | dprintk("%s could not handle NFSv4 error %d\n", | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 179 | __func__, -err); | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 180 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 182 | return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } | 
|  | 184 |  | 
|  | 185 | /* | 
|  | 186 | * This is our standard bitmap for GETATTR requests. | 
|  | 187 | */ | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 188 | const u32 nfs4_fattr_bitmap[3] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | FATTR4_WORD0_TYPE | 
|  | 190 | | FATTR4_WORD0_CHANGE | 
|  | 191 | | FATTR4_WORD0_SIZE | 
|  | 192 | | FATTR4_WORD0_FSID | 
|  | 193 | | FATTR4_WORD0_FILEID, | 
|  | 194 | FATTR4_WORD1_MODE | 
|  | 195 | | FATTR4_WORD1_NUMLINKS | 
|  | 196 | | FATTR4_WORD1_OWNER | 
|  | 197 | | FATTR4_WORD1_OWNER_GROUP | 
|  | 198 | | FATTR4_WORD1_RAWDEV | 
|  | 199 | | FATTR4_WORD1_SPACE_USED | 
|  | 200 | | FATTR4_WORD1_TIME_ACCESS | 
|  | 201 | | FATTR4_WORD1_TIME_METADATA | 
| Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 202 | | FATTR4_WORD1_TIME_MODIFY | 
|  | 203 | | FATTR4_WORD1_MOUNTED_ON_FILEID, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 204 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 205 | FATTR4_WORD2_SECURITY_LABEL | 
|  | 206 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | }; | 
|  | 208 |  | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 209 | static const u32 nfs4_pnfs_open_bitmap[3] = { | 
|  | 210 | FATTR4_WORD0_TYPE | 
|  | 211 | | FATTR4_WORD0_CHANGE | 
|  | 212 | | FATTR4_WORD0_SIZE | 
|  | 213 | | FATTR4_WORD0_FSID | 
|  | 214 | | FATTR4_WORD0_FILEID, | 
|  | 215 | FATTR4_WORD1_MODE | 
|  | 216 | | FATTR4_WORD1_NUMLINKS | 
|  | 217 | | FATTR4_WORD1_OWNER | 
|  | 218 | | FATTR4_WORD1_OWNER_GROUP | 
|  | 219 | | FATTR4_WORD1_RAWDEV | 
|  | 220 | | FATTR4_WORD1_SPACE_USED | 
|  | 221 | | FATTR4_WORD1_TIME_ACCESS | 
|  | 222 | | FATTR4_WORD1_TIME_METADATA | 
|  | 223 | | FATTR4_WORD1_TIME_MODIFY, | 
|  | 224 | FATTR4_WORD2_MDSTHRESHOLD | 
| Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 225 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 226 | | FATTR4_WORD2_SECURITY_LABEL | 
|  | 227 | #endif | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 228 | }; | 
|  | 229 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 230 | static const u32 nfs4_open_noattr_bitmap[3] = { | 
|  | 231 | FATTR4_WORD0_TYPE | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 232 | | FATTR4_WORD0_FILEID, | 
|  | 233 | }; | 
|  | 234 |  | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 235 | const u32 nfs4_statfs_bitmap[3] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | FATTR4_WORD0_FILES_AVAIL | 
|  | 237 | | FATTR4_WORD0_FILES_FREE | 
|  | 238 | | FATTR4_WORD0_FILES_TOTAL, | 
|  | 239 | FATTR4_WORD1_SPACE_AVAIL | 
|  | 240 | | FATTR4_WORD1_SPACE_FREE | 
|  | 241 | | FATTR4_WORD1_SPACE_TOTAL | 
|  | 242 | }; | 
|  | 243 |  | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 244 | const u32 nfs4_pathconf_bitmap[3] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | FATTR4_WORD0_MAXLINK | 
|  | 246 | | FATTR4_WORD0_MAXNAME, | 
|  | 247 | 0 | 
|  | 248 | }; | 
|  | 249 |  | 
| Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 250 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | | FATTR4_WORD0_MAXREAD | 
|  | 252 | | FATTR4_WORD0_MAXWRITE | 
|  | 253 | | FATTR4_WORD0_LEASE_TIME, | 
| Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 254 | FATTR4_WORD1_TIME_DELTA | 
| Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 255 | | FATTR4_WORD1_FS_LAYOUT_TYPES, | 
|  | 256 | FATTR4_WORD2_LAYOUT_BLKSIZE | 
| Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 257 | | FATTR4_WORD2_CLONE_BLKSIZE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | }; | 
|  | 259 |  | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 260 | const u32 nfs4_fs_locations_bitmap[3] = { | 
| Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 261 | FATTR4_WORD0_CHANGE | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 262 | | FATTR4_WORD0_SIZE | 
|  | 263 | | FATTR4_WORD0_FSID | 
|  | 264 | | FATTR4_WORD0_FILEID | 
|  | 265 | | FATTR4_WORD0_FS_LOCATIONS, | 
| Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 266 | FATTR4_WORD1_OWNER | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 267 | | FATTR4_WORD1_OWNER_GROUP | 
|  | 268 | | FATTR4_WORD1_RAWDEV | 
|  | 269 | | FATTR4_WORD1_SPACE_USED | 
|  | 270 | | FATTR4_WORD1_TIME_ACCESS | 
|  | 271 | | FATTR4_WORD1_TIME_METADATA | 
|  | 272 | | FATTR4_WORD1_TIME_MODIFY | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 273 | | FATTR4_WORD1_MOUNTED_ON_FILEID, | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 274 | }; | 
|  | 275 |  | 
| Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 276 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | struct nfs4_readdir_arg *readdir) | 
|  | 278 | { | 
| Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 279 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; | 
| Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 280 | __be32 *start, *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (cookie > 2) { | 
| Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 283 | readdir->cookie = cookie; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); | 
|  | 285 | return; | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | readdir->cookie = 0; | 
|  | 289 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); | 
|  | 290 | if (cookie == 2) | 
|  | 291 | return; | 
|  | 292 |  | 
|  | 293 | /* | 
|  | 294 | * NFSv4 servers do not return entries for '.' and '..' | 
|  | 295 | * Therefore, we fake these entries here.  We let '.' | 
|  | 296 | * have cookie 0 and '..' have cookie 1.  Note that | 
|  | 297 | * when talking to the server, we always send cookie 0 | 
|  | 298 | * instead of 1 or 2. | 
|  | 299 | */ | 
| Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 300 | start = p = kmap_atomic(*readdir->pages); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 |  | 
|  | 302 | if (cookie == 0) { | 
|  | 303 | *p++ = xdr_one;                                  /* next */ | 
|  | 304 | *p++ = xdr_zero;                   /* cookie, first word */ | 
|  | 305 | *p++ = xdr_one;                   /* cookie, second word */ | 
|  | 306 | *p++ = xdr_one;                             /* entry len */ | 
|  | 307 | memcpy(p, ".\0\0\0", 4);                        /* entry */ | 
|  | 308 | p++; | 
|  | 309 | *p++ = xdr_one;                         /* bitmap length */ | 
| Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 310 | *p++ = htonl(attrs);                           /* bitmap */ | 
|  | 311 | *p++ = htonl(12);             /* attribute buffer length */ | 
|  | 312 | *p++ = htonl(NF4DIR); | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 313 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } | 
|  | 315 |  | 
|  | 316 | *p++ = xdr_one;                                  /* next */ | 
|  | 317 | *p++ = xdr_zero;                   /* cookie, first word */ | 
|  | 318 | *p++ = xdr_two;                   /* cookie, second word */ | 
|  | 319 | *p++ = xdr_two;                             /* entry len */ | 
|  | 320 | memcpy(p, "..\0\0", 4);                         /* entry */ | 
|  | 321 | p++; | 
|  | 322 | *p++ = xdr_one;                         /* bitmap length */ | 
| Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 323 | *p++ = htonl(attrs);                           /* bitmap */ | 
|  | 324 | *p++ = htonl(12);             /* attribute buffer length */ | 
|  | 325 | *p++ = htonl(NF4DIR); | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 326 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 |  | 
|  | 328 | readdir->pgbase = (char *)p - (char *)start; | 
|  | 329 | readdir->count -= readdir->pgbase; | 
| Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 330 | kunmap_atomic(start); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } | 
|  | 332 |  | 
| Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 333 | static void nfs4_test_and_free_stateid(struct nfs_server *server, | 
|  | 334 | nfs4_stateid *stateid, | 
|  | 335 | struct rpc_cred *cred) | 
|  | 336 | { | 
|  | 337 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; | 
|  | 338 |  | 
|  | 339 | ops->test_and_free_expired(server, stateid, cred); | 
|  | 340 | } | 
|  | 341 |  | 
|  | 342 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, | 
|  | 343 | nfs4_stateid *stateid, | 
|  | 344 | struct rpc_cred *cred) | 
|  | 345 | { | 
|  | 346 | stateid->type = NFS4_REVOKED_STATEID_TYPE; | 
|  | 347 | nfs4_test_and_free_stateid(server, stateid, cred); | 
|  | 348 | } | 
|  | 349 |  | 
|  | 350 | static void nfs4_free_revoked_stateid(struct nfs_server *server, | 
|  | 351 | const nfs4_stateid *stateid, | 
|  | 352 | struct rpc_cred *cred) | 
|  | 353 | { | 
|  | 354 | nfs4_stateid tmp; | 
|  | 355 |  | 
|  | 356 | nfs4_stateid_copy(&tmp, stateid); | 
|  | 357 | __nfs4_free_revoked_stateid(server, &tmp, cred); | 
|  | 358 | } | 
|  | 359 |  | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 360 | static long nfs4_update_delay(long *timeout) | 
|  | 361 | { | 
|  | 362 | long ret; | 
|  | 363 | if (!timeout) | 
|  | 364 | return NFS4_POLL_RETRY_MAX; | 
|  | 365 | if (*timeout <= 0) | 
|  | 366 | *timeout = NFS4_POLL_RETRY_MIN; | 
|  | 367 | if (*timeout > NFS4_POLL_RETRY_MAX) | 
|  | 368 | *timeout = NFS4_POLL_RETRY_MAX; | 
|  | 369 | ret = *timeout; | 
|  | 370 | *timeout <<= 1; | 
|  | 371 | return ret; | 
|  | 372 | } | 
|  | 373 |  | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 374 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) | 
|  | 375 | { | 
|  | 376 | int res = 0; | 
|  | 377 |  | 
|  | 378 | might_sleep(); | 
|  | 379 |  | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 380 | freezable_schedule_timeout_killable_unsafe( | 
|  | 381 | nfs4_update_delay(timeout)); | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 382 | if (fatal_signal_pending(current)) | 
|  | 383 | res = -ERESTARTSYS; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 384 | return res; | 
|  | 385 | } | 
|  | 386 |  | 
|  | 387 | /* This is the error handling routine for processes that are allowed | 
|  | 388 | * to sleep. | 
|  | 389 | */ | 
| Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 390 | static int nfs4_do_handle_exception(struct nfs_server *server, | 
|  | 391 | int errorcode, struct nfs4_exception *exception) | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 392 | { | 
|  | 393 | struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 394 | struct nfs4_state *state = exception->state; | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 395 | const nfs4_stateid *stateid = exception->stateid; | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 396 | struct inode *inode = exception->inode; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 397 | int ret = errorcode; | 
|  | 398 |  | 
| Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 399 | exception->delay = 0; | 
|  | 400 | exception->recovering = 0; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 401 | exception->retry = 0; | 
| Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 402 |  | 
|  | 403 | if (stateid == NULL && state != NULL) | 
|  | 404 | stateid = &state->stateid; | 
|  | 405 |  | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 406 | switch(errorcode) { | 
|  | 407 | case 0: | 
|  | 408 | return 0; | 
| Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 409 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 410 | case -NFS4ERR_ADMIN_REVOKED: | 
| Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 411 | case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 412 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 413 | if (inode != NULL && stateid != NULL) { | 
|  | 414 | nfs_inode_find_state_and_recover(inode, | 
|  | 415 | stateid); | 
|  | 416 | goto wait_on_recovery; | 
|  | 417 | } | 
|  | 418 | case -NFS4ERR_OPENMODE: | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 419 | if (inode) { | 
|  | 420 | int err; | 
|  | 421 |  | 
|  | 422 | err = nfs_async_inode_return_delegation(inode, | 
|  | 423 | stateid); | 
|  | 424 | if (err == 0) | 
|  | 425 | goto wait_on_recovery; | 
|  | 426 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { | 
|  | 427 | exception->retry = 1; | 
|  | 428 | break; | 
|  | 429 | } | 
|  | 430 | } | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 431 | if (state == NULL) | 
|  | 432 | break; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 433 | ret = nfs4_schedule_stateid_recovery(server, state); | 
|  | 434 | if (ret < 0) | 
|  | 435 | break; | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 436 | goto wait_on_recovery; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 438 | case -NFS4ERR_STALE_CLIENTID: | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 439 | nfs4_schedule_lease_recovery(clp); | 
|  | 440 | goto wait_on_recovery; | 
| Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 441 | case -NFS4ERR_MOVED: | 
|  | 442 | ret = nfs4_schedule_migration_recovery(server); | 
|  | 443 | if (ret < 0) | 
|  | 444 | break; | 
|  | 445 | goto wait_on_recovery; | 
| Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 446 | case -NFS4ERR_LEASE_MOVED: | 
|  | 447 | nfs4_schedule_lease_moved_recovery(clp); | 
|  | 448 | goto wait_on_recovery; | 
| Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 449 | #if defined(CONFIG_NFS_V4_1) | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 450 | case -NFS4ERR_BADSESSION: | 
|  | 451 | case -NFS4ERR_BADSLOT: | 
|  | 452 | case -NFS4ERR_BAD_HIGH_SLOT: | 
|  | 453 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|  | 454 | case -NFS4ERR_DEADSESSION: | 
|  | 455 | case -NFS4ERR_SEQ_FALSE_RETRY: | 
|  | 456 | case -NFS4ERR_SEQ_MISORDERED: | 
|  | 457 | dprintk("%s ERROR: %d Reset session\n", __func__, | 
|  | 458 | errorcode); | 
| Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 459 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); | 
| Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 460 | goto wait_on_recovery; | 
| Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 461 | #endif /* defined(CONFIG_NFS_V4_1) */ | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 462 | case -NFS4ERR_FILE_OPEN: | 
| NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 463 | if (exception->timeout > HZ) { | 
|  | 464 | /* We have retried a decent amount, time to | 
|  | 465 | * fail | 
|  | 466 | */ | 
|  | 467 | ret = -EBUSY; | 
|  | 468 | break; | 
|  | 469 | } | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 470 | case -NFS4ERR_DELAY: | 
| Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 471 | nfs_inc_server_stats(server, NFSIOS_DELAY); | 
|  | 472 | case -NFS4ERR_GRACE: | 
| Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 473 | case -NFS4ERR_LAYOUTTRYLATER: | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 474 | case -NFS4ERR_RECALLCONFLICT: | 
| Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 475 | exception->delay = 1; | 
|  | 476 | return 0; | 
|  | 477 |  | 
| Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 478 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 479 | case -NFS4ERR_OLD_STATEID: | 
|  | 480 | exception->retry = 1; | 
| Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 481 | break; | 
|  | 482 | case -NFS4ERR_BADOWNER: | 
|  | 483 | /* The following works around a Linux server bug! */ | 
|  | 484 | case -NFS4ERR_BADNAME: | 
|  | 485 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { | 
|  | 486 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; | 
|  | 487 | exception->retry = 1; | 
|  | 488 | printk(KERN_WARNING "NFS: v4 server %s " | 
|  | 489 | "does not accept raw " | 
|  | 490 | "uid/gids. " | 
|  | 491 | "Reenabling the idmapper.\n", | 
|  | 492 | server->nfs_client->cl_hostname); | 
|  | 493 | } | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 494 | } | 
|  | 495 | /* We failed to handle the error */ | 
|  | 496 | return nfs4_map_errors(ret); | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 497 | wait_on_recovery: | 
| Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 498 | exception->recovering = 1; | 
|  | 499 | return 0; | 
|  | 500 | } | 
|  | 501 |  | 
|  | 502 | /* This is the error handling routine for processes that are allowed | 
|  | 503 | * to sleep. | 
|  | 504 | */ | 
|  | 505 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) | 
|  | 506 | { | 
|  | 507 | struct nfs_client *clp = server->nfs_client; | 
|  | 508 | int ret; | 
|  | 509 |  | 
|  | 510 | ret = nfs4_do_handle_exception(server, errorcode, exception); | 
|  | 511 | if (exception->delay) { | 
|  | 512 | ret = nfs4_delay(server->client, &exception->timeout); | 
|  | 513 | goto out_retry; | 
|  | 514 | } | 
|  | 515 | if (exception->recovering) { | 
|  | 516 | ret = nfs4_wait_clnt_recover(clp); | 
|  | 517 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) | 
|  | 518 | return -EIO; | 
|  | 519 | goto out_retry; | 
|  | 520 | } | 
|  | 521 | return ret; | 
|  | 522 | out_retry: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 523 | if (ret == 0) | 
|  | 524 | exception->retry = 1; | 
|  | 525 | return ret; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 526 | } | 
|  | 527 |  | 
| Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 528 | static int | 
|  | 529 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, | 
|  | 530 | int errorcode, struct nfs4_exception *exception) | 
|  | 531 | { | 
|  | 532 | struct nfs_client *clp = server->nfs_client; | 
|  | 533 | int ret; | 
|  | 534 |  | 
|  | 535 | ret = nfs4_do_handle_exception(server, errorcode, exception); | 
|  | 536 | if (exception->delay) { | 
|  | 537 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); | 
|  | 538 | goto out_retry; | 
|  | 539 | } | 
|  | 540 | if (exception->recovering) { | 
|  | 541 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); | 
|  | 542 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) | 
|  | 543 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); | 
|  | 544 | goto out_retry; | 
|  | 545 | } | 
|  | 546 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) | 
|  | 547 | ret = -EIO; | 
|  | 548 | return ret; | 
|  | 549 | out_retry: | 
|  | 550 | if (ret == 0) | 
|  | 551 | exception->retry = 1; | 
|  | 552 | return ret; | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | static int | 
|  | 556 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, | 
|  | 557 | struct nfs4_state *state, long *timeout) | 
|  | 558 | { | 
|  | 559 | struct nfs4_exception exception = { | 
|  | 560 | .state = state, | 
|  | 561 | }; | 
|  | 562 |  | 
|  | 563 | if (task->tk_status >= 0) | 
|  | 564 | return 0; | 
|  | 565 | if (timeout) | 
|  | 566 | exception.timeout = *timeout; | 
|  | 567 | task->tk_status = nfs4_async_handle_exception(task, server, | 
|  | 568 | task->tk_status, | 
|  | 569 | &exception); | 
|  | 570 | if (exception.delay && timeout) | 
|  | 571 | *timeout = exception.timeout; | 
|  | 572 | if (exception.retry) | 
|  | 573 | return -EAGAIN; | 
|  | 574 | return 0; | 
|  | 575 | } | 
|  | 576 |  | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 577 | /* | 
|  | 578 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected | 
|  | 579 | * or 'false' otherwise. | 
|  | 580 | */ | 
|  | 581 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) | 
|  | 582 | { | 
|  | 583 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; | 
| Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 584 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 585 | } | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 586 |  | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 587 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | spin_lock(&clp->cl_lock); | 
|  | 590 | if (time_before(clp->cl_last_renewal,timestamp)) | 
|  | 591 | clp->cl_last_renewal = timestamp; | 
|  | 592 | spin_unlock(&clp->cl_lock); | 
|  | 593 | } | 
|  | 594 |  | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 595 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) | 
|  | 596 | { | 
| Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 597 | struct nfs_client *clp = server->nfs_client; | 
|  | 598 |  | 
|  | 599 | if (!nfs4_has_session(clp)) | 
|  | 600 | do_renew_lease(clp, timestamp); | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 601 | } | 
|  | 602 |  | 
| Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 603 | struct nfs4_call_sync_data { | 
|  | 604 | const struct nfs_server *seq_server; | 
|  | 605 | struct nfs4_sequence_args *seq_args; | 
|  | 606 | struct nfs4_sequence_res *seq_res; | 
|  | 607 | }; | 
|  | 608 |  | 
| Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 609 | void nfs4_init_sequence(struct nfs4_sequence_args *args, | 
|  | 610 | struct nfs4_sequence_res *res, int cache_reply) | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 611 | { | 
|  | 612 | args->sa_slot = NULL; | 
|  | 613 | args->sa_cache_this = cache_reply; | 
|  | 614 | args->sa_privileged = 0; | 
|  | 615 |  | 
|  | 616 | res->sr_slot = NULL; | 
|  | 617 | } | 
|  | 618 |  | 
|  | 619 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) | 
|  | 620 | { | 
|  | 621 | args->sa_privileged = 1; | 
|  | 622 | } | 
|  | 623 |  | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 624 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 625 | { | 
|  | 626 | struct nfs4_slot *slot = res->sr_slot; | 
|  | 627 | struct nfs4_slot_table *tbl; | 
|  | 628 |  | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 629 | tbl = slot->table; | 
|  | 630 | spin_lock(&tbl->slot_tbl_lock); | 
|  | 631 | if (!nfs41_wake_and_assign_slot(tbl, slot)) | 
|  | 632 | nfs4_free_slot(tbl, slot); | 
|  | 633 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 634 |  | 
|  | 635 | res->sr_slot = NULL; | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 636 | } | 
|  | 637 |  | 
|  | 638 | static int nfs40_sequence_done(struct rpc_task *task, | 
|  | 639 | struct nfs4_sequence_res *res) | 
|  | 640 | { | 
|  | 641 | if (res->sr_slot != NULL) | 
|  | 642 | nfs40_sequence_free_slot(res); | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 643 | return 1; | 
|  | 644 | } | 
|  | 645 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 646 | #if defined(CONFIG_NFS_V4_1) | 
|  | 647 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 648 | static void nfs41_release_slot(struct nfs4_slot *slot) | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 649 | { | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 650 | struct nfs4_session *session; | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 651 | struct nfs4_slot_table *tbl; | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 652 | bool send_new_highest_used_slotid = false; | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 653 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 654 | if (!slot) | 
|  | 655 | return; | 
| Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 656 | tbl = slot->table; | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 657 | session = tbl->session; | 
| Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 658 |  | 
| Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 659 | /* Bump the slot sequence number */ | 
|  | 660 | if (slot->seq_done) | 
|  | 661 | slot->seq_nr++; | 
|  | 662 | slot->seq_done = 0; | 
|  | 663 |  | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 664 | spin_lock(&tbl->slot_tbl_lock); | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 665 | /* Be nice to the server: try to ensure that the last transmitted | 
|  | 666 | * value for highest_user_slotid <= target_highest_slotid | 
|  | 667 | */ | 
|  | 668 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) | 
|  | 669 | send_new_highest_used_slotid = true; | 
|  | 670 |  | 
| Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 671 | if (nfs41_wake_and_assign_slot(tbl, slot)) { | 
| Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 672 | send_new_highest_used_slotid = false; | 
|  | 673 | goto out_unlock; | 
|  | 674 | } | 
| Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 675 | nfs4_free_slot(tbl, slot); | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 676 |  | 
|  | 677 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) | 
|  | 678 | send_new_highest_used_slotid = false; | 
| Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 679 | out_unlock: | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 680 | spin_unlock(&tbl->slot_tbl_lock); | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 681 | if (send_new_highest_used_slotid) | 
| Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 682 | nfs41_notify_server(session->clp); | 
| Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 683 | if (waitqueue_active(&tbl->slot_waitq)) | 
|  | 684 | wake_up_all(&tbl->slot_waitq); | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 685 | } | 
|  | 686 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 687 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) | 
|  | 688 | { | 
|  | 689 | nfs41_release_slot(res->sr_slot); | 
|  | 690 | res->sr_slot = NULL; | 
|  | 691 | } | 
|  | 692 |  | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 693 | static int nfs41_sequence_process(struct rpc_task *task, | 
|  | 694 | struct nfs4_sequence_res *res) | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 695 | { | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 696 | struct nfs4_session *session; | 
| Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 697 | struct nfs4_slot *slot = res->sr_slot; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 698 | struct nfs_client *clp; | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 699 | bool interrupted = false; | 
| Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 700 | int ret = 1; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 701 |  | 
| Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 702 | if (slot == NULL) | 
|  | 703 | goto out_noaction; | 
| Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 704 | /* don't increment the sequence number if the task wasn't sent */ | 
|  | 705 | if (!RPC_WAS_SENT(task)) | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 706 | goto out; | 
|  | 707 |  | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 708 | session = slot->table->session; | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 709 |  | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 710 | if (slot->interrupted) { | 
| Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 711 | if (res->sr_status != -NFS4ERR_DELAY) | 
|  | 712 | slot->interrupted = 0; | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 713 | interrupted = true; | 
|  | 714 | } | 
|  | 715 |  | 
| Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 716 | trace_nfs4_sequence_done(session, res); | 
| Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 717 | /* Check the SEQUENCE operation status */ | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 718 | switch (res->sr_status) { | 
|  | 719 | case 0: | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 720 | /* Update the slot's sequence and clientid lease timer */ | 
| Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 721 | slot->seq_done = 1; | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 722 | clp = session->clp; | 
| Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 723 | do_renew_lease(clp, res->sr_timestamp); | 
| Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 724 | /* Check sequence flags */ | 
| Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 725 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, | 
|  | 726 | !!slot->privileged); | 
| Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 727 | nfs41_update_target_slotid(slot->table, slot, res); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 728 | break; | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 729 | case 1: | 
|  | 730 | /* | 
|  | 731 | * sr_status remains 1 if an RPC level error occurred. | 
|  | 732 | * The server may or may not have processed the sequence | 
|  | 733 | * operation.. | 
|  | 734 | * Mark the slot as having hosted an interrupted RPC call. | 
|  | 735 | */ | 
|  | 736 | slot->interrupted = 1; | 
|  | 737 | goto out; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 738 | case -NFS4ERR_DELAY: | 
|  | 739 | /* The server detected a resend of the RPC call and | 
|  | 740 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 | 
|  | 741 | * of RFC5661. | 
|  | 742 | */ | 
| Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 743 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 744 | __func__, | 
| Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 745 | slot->slot_nr, | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 746 | slot->seq_nr); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 747 | goto out_retry; | 
| Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 748 | case -NFS4ERR_BADSLOT: | 
|  | 749 | /* | 
|  | 750 | * The slot id we used was probably retired. Try again | 
|  | 751 | * using a different slot id. | 
|  | 752 | */ | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 753 | if (slot->seq_nr < slot->table->target_highest_slotid) | 
|  | 754 | goto session_recover; | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 755 | goto retry_nowait; | 
|  | 756 | case -NFS4ERR_SEQ_MISORDERED: | 
|  | 757 | /* | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 758 | * Was the last operation on this sequence interrupted? | 
|  | 759 | * If so, retry after bumping the sequence number. | 
|  | 760 | */ | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 761 | if (interrupted) | 
|  | 762 | goto retry_new_seq; | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 763 | /* | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 764 | * Could this slot have been previously retired? | 
|  | 765 | * If so, then the server may be expecting seq_nr = 1! | 
|  | 766 | */ | 
| Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 767 | if (slot->seq_nr != 1) { | 
|  | 768 | slot->seq_nr = 1; | 
|  | 769 | goto retry_nowait; | 
|  | 770 | } | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 771 | goto session_recover; | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 772 | case -NFS4ERR_SEQ_FALSE_RETRY: | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 773 | if (interrupted) | 
|  | 774 | goto retry_new_seq; | 
|  | 775 | goto session_recover; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 776 | default: | 
|  | 777 | /* Just update the slot sequence no. */ | 
| Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 778 | slot->seq_done = 1; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 779 | } | 
|  | 780 | out: | 
|  | 781 | /* The session may be reset by one of the error handlers. */ | 
|  | 782 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); | 
| Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 783 | out_noaction: | 
| Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 784 | return ret; | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 785 | session_recover: | 
|  | 786 | nfs4_schedule_session_recovery(session, res->sr_status); | 
|  | 787 | goto retry_nowait; | 
|  | 788 | retry_new_seq: | 
|  | 789 | ++slot->seq_nr; | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 790 | retry_nowait: | 
|  | 791 | if (rpc_restart_call_prepare(task)) { | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 792 | nfs41_sequence_free_slot(res); | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 793 | task->tk_status = 0; | 
|  | 794 | ret = 0; | 
|  | 795 | } | 
|  | 796 | goto out; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 797 | out_retry: | 
| Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 798 | if (!rpc_restart_call(task)) | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 799 | goto out; | 
|  | 800 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
|  | 801 | return 0; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 802 | } | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 803 |  | 
|  | 804 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) | 
|  | 805 | { | 
|  | 806 | if (!nfs41_sequence_process(task, res)) | 
|  | 807 | return 0; | 
|  | 808 | if (res->sr_slot != NULL) | 
|  | 809 | nfs41_sequence_free_slot(res); | 
|  | 810 | return 1; | 
|  | 811 |  | 
|  | 812 | } | 
| Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 813 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 814 |  | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 815 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) | 
|  | 816 | { | 
|  | 817 | if (res->sr_slot == NULL) | 
|  | 818 | return 1; | 
|  | 819 | if (res->sr_slot->table->session != NULL) | 
|  | 820 | return nfs41_sequence_process(task, res); | 
|  | 821 | return nfs40_sequence_done(task, res); | 
|  | 822 | } | 
|  | 823 |  | 
|  | 824 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) | 
|  | 825 | { | 
|  | 826 | if (res->sr_slot != NULL) { | 
|  | 827 | if (res->sr_slot->table->session != NULL) | 
|  | 828 | nfs41_sequence_free_slot(res); | 
|  | 829 | else | 
|  | 830 | nfs40_sequence_free_slot(res); | 
|  | 831 | } | 
|  | 832 | } | 
|  | 833 |  | 
| Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 834 | 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] | 835 | { | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 836 | if (res->sr_slot == NULL) | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 837 | return 1; | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 838 | if (!res->sr_slot->table->session) | 
|  | 839 | return nfs40_sequence_done(task, res); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 840 | return nfs41_sequence_done(task, res); | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 841 | } | 
| Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 842 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 843 |  | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 844 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) | 
|  | 845 | { | 
| Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 846 | struct nfs4_call_sync_data *data = calldata; | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 847 |  | 
| Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 848 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); | 
|  | 849 |  | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 850 | nfs4_setup_sequence(data->seq_server->nfs_client, | 
|  | 851 | data->seq_args, data->seq_res, task); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 852 | } | 
|  | 853 |  | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 854 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) | 
|  | 855 | { | 
| Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 856 | struct nfs4_call_sync_data *data = calldata; | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 857 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 858 | nfs41_sequence_done(task, data->seq_res); | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 859 | } | 
|  | 860 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 861 | static const struct rpc_call_ops nfs41_call_sync_ops = { | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 862 | .rpc_call_prepare = nfs41_call_sync_prepare, | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 863 | .rpc_call_done = nfs41_call_sync_done, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 864 | }; | 
|  | 865 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 866 | static void | 
|  | 867 | nfs4_sequence_process_interrupted(struct nfs_client *client, | 
|  | 868 | struct nfs4_slot *slot, struct rpc_cred *cred) | 
|  | 869 | { | 
|  | 870 | struct rpc_task *task; | 
|  | 871 |  | 
|  | 872 | task = _nfs41_proc_sequence(client, cred, slot, true); | 
|  | 873 | if (!IS_ERR(task)) | 
|  | 874 | rpc_put_task_async(task); | 
|  | 875 | } | 
|  | 876 |  | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 877 | #else	/* !CONFIG_NFS_V4_1 */ | 
|  | 878 |  | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 879 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) | 
|  | 880 | { | 
|  | 881 | return nfs40_sequence_done(task, res); | 
|  | 882 | } | 
|  | 883 |  | 
|  | 884 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) | 
|  | 885 | { | 
|  | 886 | if (res->sr_slot != NULL) | 
|  | 887 | nfs40_sequence_free_slot(res); | 
|  | 888 | } | 
|  | 889 |  | 
| Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 890 | int nfs4_sequence_done(struct rpc_task *task, | 
|  | 891 | struct nfs4_sequence_res *res) | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 892 | { | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 893 | return nfs40_sequence_done(task, res); | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 894 | } | 
| Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 895 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 896 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 897 | static void | 
|  | 898 | nfs4_sequence_process_interrupted(struct nfs_client *client, | 
|  | 899 | struct nfs4_slot *slot, struct rpc_cred *cred) | 
|  | 900 | { | 
|  | 901 | WARN_ON_ONCE(1); | 
|  | 902 | slot->interrupted = 0; | 
|  | 903 | } | 
|  | 904 |  | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 905 | #endif	/* !CONFIG_NFS_V4_1 */ | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 906 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 907 | static | 
|  | 908 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, | 
|  | 909 | struct nfs4_sequence_res *res, | 
|  | 910 | struct nfs4_slot *slot) | 
|  | 911 | { | 
|  | 912 | if (!slot) | 
|  | 913 | return; | 
|  | 914 | slot->privileged = args->sa_privileged ? 1 : 0; | 
|  | 915 | args->sa_slot = slot; | 
|  | 916 |  | 
|  | 917 | res->sr_slot = slot; | 
|  | 918 | res->sr_timestamp = jiffies; | 
|  | 919 | res->sr_status_flags = 0; | 
|  | 920 | res->sr_status = 1; | 
|  | 921 |  | 
|  | 922 | } | 
|  | 923 |  | 
|  | 924 | int nfs4_setup_sequence(struct nfs_client *client, | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 925 | struct nfs4_sequence_args *args, | 
|  | 926 | struct nfs4_sequence_res *res, | 
|  | 927 | struct rpc_task *task) | 
|  | 928 | { | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 929 | struct nfs4_session *session = nfs4_get_session(client); | 
| Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 930 | struct nfs4_slot_table *tbl  = client->cl_slot_tbl; | 
| Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 931 | struct nfs4_slot *slot; | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 932 |  | 
| Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 933 | /* slot already allocated? */ | 
|  | 934 | if (res->sr_slot != NULL) | 
|  | 935 | goto out_start; | 
|  | 936 |  | 
| Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 937 | if (session) { | 
|  | 938 | tbl = &session->fc_slot_table; | 
|  | 939 | task->tk_timeout = 0; | 
|  | 940 | } | 
|  | 941 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 942 | for (;;) { | 
|  | 943 | spin_lock(&tbl->slot_tbl_lock); | 
|  | 944 | /* The state manager will wait until the slot table is empty */ | 
|  | 945 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) | 
|  | 946 | goto out_sleep; | 
| Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 947 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 948 | slot = nfs4_alloc_slot(tbl); | 
|  | 949 | if (IS_ERR(slot)) { | 
|  | 950 | /* Try again in 1/4 second */ | 
|  | 951 | if (slot == ERR_PTR(-ENOMEM)) | 
|  | 952 | task->tk_timeout = HZ >> 2; | 
|  | 953 | goto out_sleep; | 
|  | 954 | } | 
|  | 955 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 956 |  | 
|  | 957 | if (likely(!slot->interrupted)) | 
|  | 958 | break; | 
|  | 959 | nfs4_sequence_process_interrupted(client, | 
|  | 960 | slot, task->tk_msg.rpc_cred); | 
| Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 961 | } | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 962 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 963 | nfs4_sequence_attach_slot(args, res, slot); | 
| Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 964 |  | 
| Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 965 | trace_nfs4_setup_sequence(session, args); | 
| Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 966 | out_start: | 
|  | 967 | rpc_call_start(task); | 
|  | 968 | return 0; | 
| Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 969 |  | 
|  | 970 | out_sleep: | 
|  | 971 | if (args->sa_privileged) | 
|  | 972 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, | 
|  | 973 | NULL, RPC_PRIORITY_PRIVILEGED); | 
|  | 974 | else | 
|  | 975 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); | 
|  | 976 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 977 | return -EAGAIN; | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 978 | } | 
|  | 979 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); | 
|  | 980 |  | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 981 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) | 
|  | 982 | { | 
|  | 983 | struct nfs4_call_sync_data *data = calldata; | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 984 | nfs4_setup_sequence(data->seq_server->nfs_client, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 985 | data->seq_args, data->seq_res, task); | 
|  | 986 | } | 
|  | 987 |  | 
|  | 988 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) | 
|  | 989 | { | 
|  | 990 | struct nfs4_call_sync_data *data = calldata; | 
|  | 991 | nfs4_sequence_done(task, data->seq_res); | 
|  | 992 | } | 
|  | 993 |  | 
|  | 994 | static const struct rpc_call_ops nfs40_call_sync_ops = { | 
|  | 995 | .rpc_call_prepare = nfs40_call_sync_prepare, | 
|  | 996 | .rpc_call_done = nfs40_call_sync_done, | 
|  | 997 | }; | 
|  | 998 |  | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 999 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1000 | struct nfs_server *server, | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | struct rpc_message *msg, | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1002 | struct nfs4_sequence_args *args, | 
|  | 1003 | struct nfs4_sequence_res *res) | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1004 | { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1005 | int ret; | 
|  | 1006 | struct rpc_task *task; | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1007 | struct nfs_client *clp = server->nfs_client; | 
|  | 1008 | struct nfs4_call_sync_data data = { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1009 | .seq_server = server, | 
|  | 1010 | .seq_args = args, | 
|  | 1011 | .seq_res = res, | 
|  | 1012 | }; | 
|  | 1013 | struct rpc_task_setup task_setup = { | 
|  | 1014 | .rpc_client = clnt, | 
|  | 1015 | .rpc_message = msg, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1016 | .callback_ops = clp->cl_mvops->call_sync_ops, | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1017 | .callback_data = &data | 
|  | 1018 | }; | 
|  | 1019 |  | 
|  | 1020 | task = rpc_run_task(&task_setup); | 
|  | 1021 | if (IS_ERR(task)) | 
|  | 1022 | ret = PTR_ERR(task); | 
|  | 1023 | else { | 
|  | 1024 | ret = task->tk_status; | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1025 | rpc_put_task(task); | 
|  | 1026 | } | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1027 | return ret; | 
|  | 1028 | } | 
|  | 1029 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1030 | int nfs4_call_sync(struct rpc_clnt *clnt, | 
|  | 1031 | struct nfs_server *server, | 
| Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1032 | struct rpc_message *msg, | 
|  | 1033 | struct nfs4_sequence_args *args, | 
|  | 1034 | struct nfs4_sequence_res *res, | 
|  | 1035 | int cache_reply) | 
|  | 1036 | { | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1037 | nfs4_init_sequence(args, res, cache_reply); | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1038 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); | 
| Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1039 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 |  | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1041 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, | 
|  | 1042 | unsigned long timestamp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | { | 
|  | 1044 | struct nfs_inode *nfsi = NFS_I(dir); | 
|  | 1045 |  | 
|  | 1046 | spin_lock(&dir->i_lock); | 
| Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1047 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; | 
| Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1048 | if (cinfo->atomic && cinfo->before == dir->i_version) { | 
|  | 1049 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; | 
|  | 1050 | nfsi->attrtimeo_timestamp = jiffies; | 
|  | 1051 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | nfs_force_lookup_revalidate(dir); | 
| Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1053 | if (cinfo->before != dir->i_version) | 
|  | 1054 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | | 
|  | 1055 | NFS_INO_INVALID_ACL; | 
|  | 1056 | } | 
| Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1057 | dir->i_version = cinfo->after; | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1058 | nfsi->read_cache_jiffies = timestamp; | 
| Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1059 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); | 
| David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1060 | nfs_fscache_invalidate(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | spin_unlock(&dir->i_lock); | 
|  | 1062 | } | 
|  | 1063 |  | 
|  | 1064 | struct nfs4_opendata { | 
|  | 1065 | struct kref kref; | 
|  | 1066 | struct nfs_openargs o_arg; | 
|  | 1067 | struct nfs_openres o_res; | 
|  | 1068 | struct nfs_open_confirmargs c_arg; | 
|  | 1069 | struct nfs_open_confirmres c_res; | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1070 | struct nfs4_string owner_name; | 
|  | 1071 | struct nfs4_string group_name; | 
| Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1072 | struct nfs4_label *a_label; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | struct nfs_fattr f_attr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1074 | struct nfs4_label *f_label; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | struct dentry *dir; | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1076 | struct dentry *dentry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | struct nfs4_state_owner *owner; | 
|  | 1078 | struct nfs4_state *state; | 
|  | 1079 | struct iattr attrs; | 
|  | 1080 | unsigned long timestamp; | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1081 | bool rpc_done; | 
|  | 1082 | bool file_created; | 
|  | 1083 | bool is_recover; | 
|  | 1084 | bool cancelled; | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1085 | int rpc_status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | }; | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1087 |  | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1088 | struct nfs4_open_createattrs { | 
|  | 1089 | struct nfs4_label *label; | 
|  | 1090 | struct iattr *sattr; | 
|  | 1091 | const __u32 verf[2]; | 
|  | 1092 | }; | 
|  | 1093 |  | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1094 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, | 
|  | 1095 | int err, struct nfs4_exception *exception) | 
|  | 1096 | { | 
|  | 1097 | if (err != -EINVAL) | 
|  | 1098 | return false; | 
|  | 1099 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) | 
|  | 1100 | return false; | 
|  | 1101 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; | 
|  | 1102 | exception->retry = 1; | 
|  | 1103 | return true; | 
|  | 1104 | } | 
|  | 1105 |  | 
| Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1106 | static u32 | 
|  | 1107 | nfs4_map_atomic_open_share(struct nfs_server *server, | 
|  | 1108 | fmode_t fmode, int openflags) | 
|  | 1109 | { | 
|  | 1110 | u32 res = 0; | 
|  | 1111 |  | 
|  | 1112 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { | 
|  | 1113 | case FMODE_READ: | 
|  | 1114 | res = NFS4_SHARE_ACCESS_READ; | 
|  | 1115 | break; | 
|  | 1116 | case FMODE_WRITE: | 
|  | 1117 | res = NFS4_SHARE_ACCESS_WRITE; | 
|  | 1118 | break; | 
|  | 1119 | case FMODE_READ|FMODE_WRITE: | 
|  | 1120 | res = NFS4_SHARE_ACCESS_BOTH; | 
|  | 1121 | } | 
|  | 1122 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) | 
|  | 1123 | goto out; | 
|  | 1124 | /* Want no delegation if we're using O_DIRECT */ | 
|  | 1125 | if (openflags & O_DIRECT) | 
|  | 1126 | res |= NFS4_SHARE_WANT_NO_DELEG; | 
|  | 1127 | out: | 
|  | 1128 | return res; | 
|  | 1129 | } | 
|  | 1130 |  | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1131 | static enum open_claim_type4 | 
|  | 1132 | nfs4_map_atomic_open_claim(struct nfs_server *server, | 
|  | 1133 | enum open_claim_type4 claim) | 
|  | 1134 | { | 
|  | 1135 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) | 
|  | 1136 | return claim; | 
|  | 1137 | switch (claim) { | 
|  | 1138 | default: | 
|  | 1139 | return claim; | 
|  | 1140 | case NFS4_OPEN_CLAIM_FH: | 
|  | 1141 | return NFS4_OPEN_CLAIM_NULL; | 
|  | 1142 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | 
|  | 1143 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; | 
|  | 1144 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | 
|  | 1145 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; | 
|  | 1146 | } | 
|  | 1147 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 |  | 
|  | 1149 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1150 | { | 
|  | 1151 | p->o_res.f_attr = &p->f_attr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1152 | p->o_res.f_label = p->f_label; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1153 | p->o_res.seqid = p->o_arg.seqid; | 
|  | 1154 | p->c_res.seqid = p->c_arg.seqid; | 
|  | 1155 | p->o_res.server = p->o_arg.server; | 
| Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1156 | p->o_res.access_request = p->o_arg.access; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1157 | nfs_fattr_init(&p->f_attr); | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1158 | 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] | 1159 | } | 
|  | 1160 |  | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1161 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1162 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1163 | const struct nfs4_open_createattrs *c, | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1164 | enum open_claim_type4 claim, | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1165 | gfp_t gfp_mask) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1166 | { | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1167 | struct dentry *parent = dget_parent(dentry); | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1168 | struct inode *dir = d_inode(parent); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1169 | struct nfs_server *server = NFS_SERVER(dir); | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1170 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1171 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1172 | struct nfs4_opendata *p; | 
|  | 1173 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1174 | p = kzalloc(sizeof(*p), gfp_mask); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1175 | if (p == NULL) | 
|  | 1176 | goto err; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1177 |  | 
|  | 1178 | p->f_label = nfs4_label_alloc(server, gfp_mask); | 
|  | 1179 | if (IS_ERR(p->f_label)) | 
|  | 1180 | goto err_free_p; | 
|  | 1181 |  | 
| Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1182 | p->a_label = nfs4_label_alloc(server, gfp_mask); | 
|  | 1183 | if (IS_ERR(p->a_label)) | 
|  | 1184 | goto err_free_f; | 
|  | 1185 |  | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1186 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; | 
|  | 1187 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); | 
| Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1188 | if (IS_ERR(p->o_arg.seqid)) | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1189 | goto err_free_label; | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1190 | nfs_sb_active(dentry->d_sb); | 
|  | 1191 | p->dentry = dget(dentry); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1192 | p->dir = parent; | 
|  | 1193 | p->owner = sp; | 
|  | 1194 | atomic_inc(&sp->so_count); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1195 | p->o_arg.open_flags = flags; | 
|  | 1196 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1197 | p->o_arg.umask = current_umask(); | 
| Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1198 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); | 
| Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1199 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, | 
|  | 1200 | fmode, flags); | 
| Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1201 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS | 
|  | 1202 | * will return permission denied for all bits until close */ | 
|  | 1203 | if (!(flags & O_EXCL)) { | 
|  | 1204 | /* ask server to check for all possible rights as results | 
|  | 1205 | * are cached */ | 
| Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1206 | switch (p->o_arg.claim) { | 
|  | 1207 | default: | 
|  | 1208 | break; | 
|  | 1209 | case NFS4_OPEN_CLAIM_NULL: | 
|  | 1210 | case NFS4_OPEN_CLAIM_FH: | 
|  | 1211 | p->o_arg.access = NFS4_ACCESS_READ | | 
|  | 1212 | NFS4_ACCESS_MODIFY | | 
|  | 1213 | NFS4_ACCESS_EXTEND | | 
|  | 1214 | NFS4_ACCESS_EXECUTE; | 
|  | 1215 | } | 
| Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1216 | } | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1217 | p->o_arg.clientid = server->nfs_client->cl_clientid; | 
| Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1218 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); | 
|  | 1219 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1220 | p->o_arg.name = &dentry->d_name; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1221 | p->o_arg.server = server; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1222 | p->o_arg.bitmask = nfs4_bitmask(server, label); | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1223 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; | 
| Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1224 | p->o_arg.label = nfs4_label_copy(p->a_label, label); | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1225 | switch (p->o_arg.claim) { | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1226 | case NFS4_OPEN_CLAIM_NULL: | 
|  | 1227 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | 
|  | 1228 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: | 
|  | 1229 | p->o_arg.fh = NFS_FH(dir); | 
|  | 1230 | break; | 
|  | 1231 | case NFS4_OPEN_CLAIM_PREVIOUS: | 
|  | 1232 | case NFS4_OPEN_CLAIM_FH: | 
|  | 1233 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | 
|  | 1234 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1235 | p->o_arg.fh = NFS_FH(d_inode(dentry)); | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1236 | } | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1237 | if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1238 | p->o_arg.u.attrs = &p->attrs; | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1239 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1240 |  | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1241 | memcpy(p->o_arg.u.verifier.data, c->verf, | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1242 | sizeof(p->o_arg.u.verifier.data)); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1243 | } | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1244 | p->c_arg.fh = &p->o_res.fh; | 
|  | 1245 | p->c_arg.stateid = &p->o_res.stateid; | 
|  | 1246 | p->c_arg.seqid = p->o_arg.seqid; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1247 | nfs4_init_opendata_res(p); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1248 | kref_init(&p->kref); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1249 | return p; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1250 |  | 
|  | 1251 | err_free_label: | 
| Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1252 | nfs4_label_free(p->a_label); | 
|  | 1253 | err_free_f: | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1254 | nfs4_label_free(p->f_label); | 
|  | 1255 | err_free_p: | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1256 | kfree(p); | 
|  | 1257 | err: | 
|  | 1258 | dput(parent); | 
|  | 1259 | return NULL; | 
|  | 1260 | } | 
|  | 1261 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1262 | static void nfs4_opendata_free(struct kref *kref) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1263 | { | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1264 | struct nfs4_opendata *p = container_of(kref, | 
|  | 1265 | struct nfs4_opendata, kref); | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1266 | struct super_block *sb = p->dentry->d_sb; | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1267 |  | 
|  | 1268 | nfs_free_seqid(p->o_arg.seqid); | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1269 | nfs4_sequence_free_slot(&p->o_res.seq_res); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1270 | if (p->state != NULL) | 
|  | 1271 | nfs4_put_open_state(p->state); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1272 | nfs4_put_state_owner(p->owner); | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1273 |  | 
| Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1274 | nfs4_label_free(p->a_label); | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1275 | nfs4_label_free(p->f_label); | 
|  | 1276 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | dput(p->dir); | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1278 | dput(p->dentry); | 
|  | 1279 | nfs_sb_deactive(sb); | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1280 | nfs_fattr_free_names(&p->f_attr); | 
| Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1281 | kfree(p->f_attr.mdsthreshold); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1282 | kfree(p); | 
|  | 1283 | } | 
|  | 1284 |  | 
|  | 1285 | static void nfs4_opendata_put(struct nfs4_opendata *p) | 
|  | 1286 | { | 
|  | 1287 | if (p != NULL) | 
|  | 1288 | kref_put(&p->kref, nfs4_opendata_free); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1289 | } | 
|  | 1290 |  | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1291 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, | 
|  | 1292 | fmode_t fmode) | 
|  | 1293 | { | 
|  | 1294 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { | 
|  | 1295 | case FMODE_READ|FMODE_WRITE: | 
|  | 1296 | return state->n_rdwr != 0; | 
|  | 1297 | case FMODE_WRITE: | 
|  | 1298 | return state->n_wronly != 0; | 
|  | 1299 | case FMODE_READ: | 
|  | 1300 | return state->n_rdonly != 0; | 
|  | 1301 | } | 
|  | 1302 | WARN_ON_ONCE(1); | 
|  | 1303 | return false; | 
|  | 1304 | } | 
|  | 1305 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1306 | 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] | 1307 | { | 
|  | 1308 | int ret = 0; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1309 |  | 
| Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1310 | if (open_mode & (O_EXCL|O_TRUNC)) | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1311 | goto out; | 
|  | 1312 | switch (mode & (FMODE_READ|FMODE_WRITE)) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1313 | case FMODE_READ: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1314 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 | 
|  | 1315 | && state->n_rdonly != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1316 | break; | 
|  | 1317 | case FMODE_WRITE: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1318 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 | 
|  | 1319 | && state->n_wronly != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1320 | break; | 
|  | 1321 | case FMODE_READ|FMODE_WRITE: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1322 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 | 
|  | 1323 | && state->n_rdwr != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1324 | } | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1325 | out: | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1326 | return ret; | 
|  | 1327 | } | 
|  | 1328 |  | 
| Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1329 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, | 
|  | 1330 | enum open_claim_type4 claim) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1331 | { | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1332 | if (delegation == NULL) | 
|  | 1333 | return 0; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1334 | if ((delegation->type & fmode) != fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1335 | return 0; | 
| Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1336 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) | 
|  | 1337 | return 0; | 
| Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1338 | switch (claim) { | 
|  | 1339 | case NFS4_OPEN_CLAIM_NULL: | 
|  | 1340 | case NFS4_OPEN_CLAIM_FH: | 
|  | 1341 | break; | 
|  | 1342 | case NFS4_OPEN_CLAIM_PREVIOUS: | 
|  | 1343 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) | 
|  | 1344 | break; | 
|  | 1345 | default: | 
|  | 1346 | return 0; | 
|  | 1347 | } | 
| Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1348 | nfs_mark_delegation_referenced(delegation); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1349 | return 1; | 
|  | 1350 | } | 
|  | 1351 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1352 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1353 | { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1354 | switch (fmode) { | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1355 | case FMODE_WRITE: | 
|  | 1356 | state->n_wronly++; | 
|  | 1357 | break; | 
|  | 1358 | case FMODE_READ: | 
|  | 1359 | state->n_rdonly++; | 
|  | 1360 | break; | 
|  | 1361 | case FMODE_READ|FMODE_WRITE: | 
|  | 1362 | state->n_rdwr++; | 
|  | 1363 | } | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1364 | nfs4_state_set_mode_locked(state, state->state | fmode); | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1365 | } | 
|  | 1366 |  | 
| Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1367 | #ifdef CONFIG_NFS_V4_1 | 
|  | 1368 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) | 
|  | 1369 | { | 
|  | 1370 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) | 
|  | 1371 | return true; | 
|  | 1372 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) | 
|  | 1373 | return true; | 
|  | 1374 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) | 
|  | 1375 | return true; | 
|  | 1376 | return false; | 
|  | 1377 | } | 
|  | 1378 | #endif /* CONFIG_NFS_V4_1 */ | 
|  | 1379 |  | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1380 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) | 
|  | 1381 | { | 
|  | 1382 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) | 
|  | 1383 | wake_up_all(&state->waitq); | 
|  | 1384 | } | 
|  | 1385 |  | 
|  | 1386 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, | 
|  | 1387 | const nfs4_stateid *stateid) | 
|  | 1388 | { | 
|  | 1389 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); | 
|  | 1390 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); | 
|  | 1391 |  | 
|  | 1392 | if (stateid_seqid == state_seqid + 1U || | 
|  | 1393 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) | 
|  | 1394 | nfs_state_log_update_open_stateid(state); | 
|  | 1395 | else | 
|  | 1396 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); | 
|  | 1397 | } | 
|  | 1398 |  | 
| Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1399 | 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] | 1400 | { | 
| Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1401 | struct nfs_client *clp = state->owner->so_server->nfs_client; | 
|  | 1402 | bool need_recover = false; | 
|  | 1403 |  | 
|  | 1404 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) | 
|  | 1405 | need_recover = true; | 
|  | 1406 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) | 
|  | 1407 | need_recover = true; | 
|  | 1408 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) | 
|  | 1409 | need_recover = true; | 
|  | 1410 | if (need_recover) | 
|  | 1411 | nfs4_state_mark_reclaim_nograce(clp, state); | 
|  | 1412 | } | 
|  | 1413 |  | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1414 | /* | 
|  | 1415 | * Check for whether or not the caller may update the open stateid | 
|  | 1416 | * to the value passed in by stateid. | 
|  | 1417 | * | 
|  | 1418 | * Note: This function relies heavily on the server implementing | 
|  | 1419 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 | 
|  | 1420 | * correctly. | 
|  | 1421 | * i.e. The stateid seqids have to be initialised to 1, and | 
|  | 1422 | * are then incremented on every state transition. | 
|  | 1423 | */ | 
| Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1424 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1425 | const nfs4_stateid *stateid) | 
| Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1426 | { | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1427 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || | 
|  | 1428 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { | 
|  | 1429 | if (stateid->seqid == cpu_to_be32(1)) | 
|  | 1430 | nfs_state_log_update_open_stateid(state); | 
|  | 1431 | else | 
|  | 1432 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); | 
| Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1433 | return true; | 
| Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1434 | } | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1435 |  | 
|  | 1436 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { | 
|  | 1437 | nfs_state_log_out_of_order_open_stateid(state, stateid); | 
| Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1438 | return true; | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1439 | } | 
| Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1440 | return false; | 
|  | 1441 | } | 
|  | 1442 |  | 
| Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1443 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) | 
|  | 1444 | { | 
| Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1445 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) | 
|  | 1446 | return; | 
| Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1447 | if (state->n_wronly) | 
|  | 1448 | set_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 1449 | if (state->n_rdonly) | 
|  | 1450 | set_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 1451 | if (state->n_rdwr) | 
|  | 1452 | set_bit(NFS_O_RDWR_STATE, &state->flags); | 
| Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1453 | set_bit(NFS_OPEN_STATE, &state->flags); | 
| Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1454 | } | 
|  | 1455 |  | 
| Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1456 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, | 
|  | 1457 | nfs4_stateid *stateid, fmode_t fmode) | 
|  | 1458 | { | 
|  | 1459 | clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
|  | 1460 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { | 
|  | 1461 | case FMODE_WRITE: | 
|  | 1462 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 1463 | break; | 
|  | 1464 | case FMODE_READ: | 
|  | 1465 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 1466 | break; | 
|  | 1467 | case 0: | 
|  | 1468 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 1469 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 1470 | clear_bit(NFS_OPEN_STATE, &state->flags); | 
|  | 1471 | } | 
|  | 1472 | if (stateid == NULL) | 
|  | 1473 | return; | 
| Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1474 | /* Handle OPEN+OPEN_DOWNGRADE races */ | 
|  | 1475 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && | 
|  | 1476 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { | 
| Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1477 | nfs_resync_open_stateid_locked(state); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1478 | goto out; | 
| Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1479 | } | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1480 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1481 | nfs4_stateid_copy(&state->stateid, stateid); | 
|  | 1482 | nfs4_stateid_copy(&state->open_stateid, stateid); | 
| Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1483 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1484 | out: | 
|  | 1485 | nfs_state_log_update_open_stateid(state); | 
| Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1486 | } | 
|  | 1487 |  | 
| Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1488 | static void nfs_clear_open_stateid(struct nfs4_state *state, | 
|  | 1489 | nfs4_stateid *arg_stateid, | 
|  | 1490 | nfs4_stateid *stateid, fmode_t fmode) | 
| Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1491 | { | 
|  | 1492 | write_seqlock(&state->seqlock); | 
| Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1493 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ | 
|  | 1494 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) | 
|  | 1495 | nfs_clear_open_stateid_locked(state, stateid, fmode); | 
| Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1496 | write_sequnlock(&state->seqlock); | 
| Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1497 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) | 
|  | 1498 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); | 
| Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1499 | } | 
|  | 1500 |  | 
| Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1501 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1502 | const nfs4_stateid *stateid, nfs4_stateid *freeme) | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1503 | { | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1504 | DEFINE_WAIT(wait); | 
|  | 1505 | int status = 0; | 
|  | 1506 | for (;;) { | 
|  | 1507 |  | 
|  | 1508 | if (!nfs_need_update_open_stateid(state, stateid)) | 
|  | 1509 | return; | 
|  | 1510 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1511 | break; | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1512 | if (status) | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1513 | break; | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1514 | /* Rely on seqids for serialisation with NFSv4.0 */ | 
|  | 1515 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) | 
|  | 1516 | break; | 
|  | 1517 |  | 
|  | 1518 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); | 
|  | 1519 | /* | 
|  | 1520 | * Ensure we process the state changes in the same order | 
|  | 1521 | * in which the server processed them by delaying the | 
|  | 1522 | * update of the stateid until we are in sequence. | 
|  | 1523 | */ | 
|  | 1524 | write_sequnlock(&state->seqlock); | 
|  | 1525 | spin_unlock(&state->owner->so_lock); | 
|  | 1526 | rcu_read_unlock(); | 
| Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1527 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1528 | if (!signal_pending(current)) { | 
|  | 1529 | if (schedule_timeout(5*HZ) == 0) | 
|  | 1530 | status = -EAGAIN; | 
|  | 1531 | else | 
|  | 1532 | status = 0; | 
|  | 1533 | } else | 
|  | 1534 | status = -EINTR; | 
|  | 1535 | finish_wait(&state->waitq, &wait); | 
|  | 1536 | rcu_read_lock(); | 
|  | 1537 | spin_lock(&state->owner->so_lock); | 
|  | 1538 | write_seqlock(&state->seqlock); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1539 | } | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1540 |  | 
| Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1541 | if (test_bit(NFS_OPEN_STATE, &state->flags) && | 
|  | 1542 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1543 | nfs4_stateid_copy(freeme, &state->open_stateid); | 
|  | 1544 | nfs_test_and_clear_all_open_stateid(state); | 
|  | 1545 | } | 
|  | 1546 |  | 
| Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1547 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
|  | 1548 | nfs4_stateid_copy(&state->stateid, stateid); | 
|  | 1549 | nfs4_stateid_copy(&state->open_stateid, stateid); | 
| Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1550 | trace_nfs4_open_stateid_update(state->inode, stateid, status); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1551 | nfs_state_log_update_open_stateid(state); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1552 | } | 
|  | 1553 |  | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1554 | static void nfs_state_set_open_stateid(struct nfs4_state *state, | 
| Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1555 | const nfs4_stateid *open_stateid, | 
| Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1556 | fmode_t fmode, | 
|  | 1557 | nfs4_stateid *freeme) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1559 | /* | 
|  | 1560 | * Protect the call to nfs4_state_set_mode_locked and | 
|  | 1561 | * serialise the stateid update | 
|  | 1562 | */ | 
|  | 1563 | write_seqlock(&state->seqlock); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1564 | nfs_set_open_stateid_locked(state, open_stateid, freeme); | 
|  | 1565 | switch (fmode) { | 
|  | 1566 | case FMODE_READ: | 
|  | 1567 | set_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 1568 | break; | 
|  | 1569 | case FMODE_WRITE: | 
|  | 1570 | set_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 1571 | break; | 
|  | 1572 | case FMODE_READ|FMODE_WRITE: | 
|  | 1573 | set_bit(NFS_O_RDWR_STATE, &state->flags); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1574 | } | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1575 | set_bit(NFS_OPEN_STATE, &state->flags); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1576 | write_sequnlock(&state->seqlock); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1577 | } | 
|  | 1578 |  | 
|  | 1579 | static void nfs_state_set_delegation(struct nfs4_state *state, | 
|  | 1580 | const nfs4_stateid *deleg_stateid, | 
|  | 1581 | fmode_t fmode) | 
|  | 1582 | { | 
|  | 1583 | /* | 
|  | 1584 | * Protect the call to nfs4_state_set_mode_locked and | 
|  | 1585 | * serialise the stateid update | 
|  | 1586 | */ | 
|  | 1587 | write_seqlock(&state->seqlock); | 
|  | 1588 | nfs4_stateid_copy(&state->stateid, deleg_stateid); | 
|  | 1589 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 1590 | write_sequnlock(&state->seqlock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } | 
|  | 1592 |  | 
| Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1593 | static int update_open_stateid(struct nfs4_state *state, | 
|  | 1594 | const nfs4_stateid *open_stateid, | 
|  | 1595 | const nfs4_stateid *delegation, | 
|  | 1596 | fmode_t fmode) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1597 | { | 
| Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1598 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 1599 | struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1600 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
|  | 1601 | struct nfs_delegation *deleg_cur; | 
| Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1602 | nfs4_stateid freeme = { }; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1603 | int ret = 0; | 
|  | 1604 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1605 | fmode &= (FMODE_READ|FMODE_WRITE); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1606 |  | 
|  | 1607 | rcu_read_lock(); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1608 | spin_lock(&state->owner->so_lock); | 
|  | 1609 | if (open_stateid != NULL) { | 
|  | 1610 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); | 
|  | 1611 | ret = 1; | 
|  | 1612 | } | 
|  | 1613 |  | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1614 | deleg_cur = rcu_dereference(nfsi->delegation); | 
|  | 1615 | if (deleg_cur == NULL) | 
|  | 1616 | goto no_delegation; | 
|  | 1617 |  | 
|  | 1618 | spin_lock(&deleg_cur->lock); | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1619 | if (rcu_dereference(nfsi->delegation) != deleg_cur || | 
| Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1620 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1621 | (deleg_cur->type & fmode) != fmode) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1622 | goto no_delegation_unlock; | 
|  | 1623 |  | 
|  | 1624 | if (delegation == NULL) | 
|  | 1625 | delegation = &deleg_cur->stateid; | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1626 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1627 | goto no_delegation_unlock; | 
|  | 1628 |  | 
| Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1629 | nfs_mark_delegation_referenced(deleg_cur); | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1630 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1631 | ret = 1; | 
|  | 1632 | no_delegation_unlock: | 
|  | 1633 | spin_unlock(&deleg_cur->lock); | 
|  | 1634 | no_delegation: | 
| Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1635 | if (ret) | 
|  | 1636 | update_open_stateflags(state, fmode); | 
|  | 1637 | spin_unlock(&state->owner->so_lock); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1638 | rcu_read_unlock(); | 
|  | 1639 |  | 
| Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1640 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) | 
| Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1641 | nfs4_schedule_state_manager(clp); | 
|  | 1642 | if (freeme.type != 0) | 
|  | 1643 | nfs4_test_and_free_stateid(server, &freeme, | 
|  | 1644 | state->owner->so_cred); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1645 |  | 
|  | 1646 | return ret; | 
|  | 1647 | } | 
|  | 1648 |  | 
| Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1649 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, | 
|  | 1650 | const nfs4_stateid *stateid) | 
|  | 1651 | { | 
|  | 1652 | struct nfs4_state *state = lsp->ls_state; | 
|  | 1653 | bool ret = false; | 
|  | 1654 |  | 
|  | 1655 | spin_lock(&state->state_lock); | 
|  | 1656 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) | 
|  | 1657 | goto out_noupdate; | 
|  | 1658 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) | 
|  | 1659 | goto out_noupdate; | 
|  | 1660 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); | 
|  | 1661 | ret = true; | 
|  | 1662 | out_noupdate: | 
|  | 1663 | spin_unlock(&state->state_lock); | 
|  | 1664 | return ret; | 
|  | 1665 | } | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1666 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1667 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1668 | { | 
|  | 1669 | struct nfs_delegation *delegation; | 
|  | 1670 |  | 
|  | 1671 | rcu_read_lock(); | 
|  | 1672 | delegation = rcu_dereference(NFS_I(inode)->delegation); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1673 | if (delegation == NULL || (delegation->type & fmode) == fmode) { | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1674 | rcu_read_unlock(); | 
|  | 1675 | return; | 
|  | 1676 | } | 
|  | 1677 | rcu_read_unlock(); | 
| Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1678 | nfs4_inode_return_delegation(inode); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1679 | } | 
|  | 1680 |  | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1681 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1682 | { | 
|  | 1683 | struct nfs4_state *state = opendata->state; | 
|  | 1684 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
|  | 1685 | struct nfs_delegation *delegation; | 
| Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1686 | int open_mode = opendata->o_arg.open_flags; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1687 | fmode_t fmode = opendata->o_arg.fmode; | 
| Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1688 | enum open_claim_type4 claim = opendata->o_arg.claim; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1689 | nfs4_stateid stateid; | 
|  | 1690 | int ret = -EAGAIN; | 
|  | 1691 |  | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1692 | for (;;) { | 
| Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1693 | spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1694 | if (can_open_cached(state, fmode, open_mode)) { | 
| Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1695 | update_open_stateflags(state, fmode); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1696 | spin_unlock(&state->owner->so_lock); | 
| Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1697 | goto out_return_state; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1698 | } | 
| Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1699 | spin_unlock(&state->owner->so_lock); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1700 | rcu_read_lock(); | 
|  | 1701 | delegation = rcu_dereference(nfsi->delegation); | 
| Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1702 | if (!can_open_delegated(delegation, fmode, claim)) { | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1703 | rcu_read_unlock(); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1704 | break; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1705 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1706 | /* Save the delegation */ | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1707 | nfs4_stateid_copy(&stateid, &delegation->stateid); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1708 | rcu_read_unlock(); | 
| Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1709 | nfs_release_seqid(opendata->o_arg.seqid); | 
| Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1710 | if (!opendata->is_recover) { | 
|  | 1711 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); | 
|  | 1712 | if (ret != 0) | 
|  | 1713 | goto out; | 
|  | 1714 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1715 | ret = -EAGAIN; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1716 |  | 
|  | 1717 | /* Try to update the stateid using the delegation */ | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1718 | if (update_open_stateid(state, NULL, &stateid, fmode)) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1719 | goto out_return_state; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1720 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1721 | out: | 
|  | 1722 | return ERR_PTR(ret); | 
|  | 1723 | out_return_state: | 
|  | 1724 | atomic_inc(&state->count); | 
|  | 1725 | return state; | 
|  | 1726 | } | 
|  | 1727 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1728 | static void | 
|  | 1729 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) | 
|  | 1730 | { | 
|  | 1731 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; | 
|  | 1732 | struct nfs_delegation *delegation; | 
|  | 1733 | int delegation_flags = 0; | 
|  | 1734 |  | 
|  | 1735 | rcu_read_lock(); | 
|  | 1736 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); | 
|  | 1737 | if (delegation) | 
|  | 1738 | delegation_flags = delegation->flags; | 
|  | 1739 | rcu_read_unlock(); | 
| Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1740 | switch (data->o_arg.claim) { | 
|  | 1741 | default: | 
|  | 1742 | break; | 
|  | 1743 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | 
|  | 1744 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1745 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " | 
|  | 1746 | "returning a delegation for " | 
|  | 1747 | "OPEN(CLAIM_DELEGATE_CUR)\n", | 
|  | 1748 | clp->cl_hostname); | 
| Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1749 | return; | 
|  | 1750 | } | 
|  | 1751 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1752 | nfs_inode_set_delegation(state->inode, | 
|  | 1753 | data->owner->so_cred, | 
|  | 1754 | &data->o_res); | 
|  | 1755 | else | 
|  | 1756 | nfs_inode_reclaim_delegation(state->inode, | 
|  | 1757 | data->owner->so_cred, | 
|  | 1758 | &data->o_res); | 
|  | 1759 | } | 
|  | 1760 |  | 
|  | 1761 | /* | 
|  | 1762 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes | 
|  | 1763 | * and update the nfs4_state. | 
|  | 1764 | */ | 
|  | 1765 | static struct nfs4_state * | 
|  | 1766 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) | 
|  | 1767 | { | 
|  | 1768 | struct inode *inode = data->state->inode; | 
|  | 1769 | struct nfs4_state *state = data->state; | 
|  | 1770 | int ret; | 
|  | 1771 |  | 
| Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1772 | if (!data->rpc_done) { | 
| Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1773 | if (data->rpc_status) | 
|  | 1774 | return ERR_PTR(data->rpc_status); | 
| Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1775 | /* cached opens have already been processed */ | 
|  | 1776 | goto update; | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1777 | } | 
|  | 1778 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1779 | ret = nfs_refresh_inode(inode, &data->f_attr); | 
|  | 1780 | if (ret) | 
| Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1781 | return ERR_PTR(ret); | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1782 |  | 
|  | 1783 | if (data->o_res.delegation_type != 0) | 
|  | 1784 | nfs4_opendata_check_deleg(data, state); | 
| Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1785 | update: | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1786 | update_open_stateid(state, &data->o_res.stateid, NULL, | 
|  | 1787 | data->o_arg.fmode); | 
| Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1788 | atomic_inc(&state->count); | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1789 |  | 
|  | 1790 | return state; | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1791 | } | 
|  | 1792 |  | 
| Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1793 | static struct inode * | 
|  | 1794 | nfs4_opendata_get_inode(struct nfs4_opendata *data) | 
|  | 1795 | { | 
|  | 1796 | struct inode *inode; | 
|  | 1797 |  | 
|  | 1798 | switch (data->o_arg.claim) { | 
|  | 1799 | case NFS4_OPEN_CLAIM_NULL: | 
|  | 1800 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | 
|  | 1801 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: | 
|  | 1802 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) | 
|  | 1803 | return ERR_PTR(-EAGAIN); | 
|  | 1804 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, | 
|  | 1805 | &data->f_attr, data->f_label); | 
|  | 1806 | break; | 
|  | 1807 | default: | 
|  | 1808 | inode = d_inode(data->dentry); | 
|  | 1809 | ihold(inode); | 
|  | 1810 | nfs_refresh_inode(inode, &data->f_attr); | 
|  | 1811 | } | 
|  | 1812 | return inode; | 
|  | 1813 | } | 
|  | 1814 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1815 | static struct nfs4_state * | 
| Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1816 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) | 
|  | 1817 | { | 
|  | 1818 | struct nfs4_state *state; | 
|  | 1819 | struct inode *inode; | 
|  | 1820 |  | 
|  | 1821 | inode = nfs4_opendata_get_inode(data); | 
|  | 1822 | if (IS_ERR(inode)) | 
|  | 1823 | return ERR_CAST(inode); | 
|  | 1824 | if (data->state != NULL && data->state->inode == inode) { | 
|  | 1825 | state = data->state; | 
|  | 1826 | atomic_inc(&state->count); | 
|  | 1827 | } else | 
|  | 1828 | state = nfs4_get_open_state(inode, data->owner); | 
|  | 1829 | iput(inode); | 
|  | 1830 | if (state == NULL) | 
|  | 1831 | state = ERR_PTR(-ENOMEM); | 
|  | 1832 | return state; | 
|  | 1833 | } | 
|  | 1834 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1835 | static struct nfs4_state * | 
|  | 1836 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1837 | { | 
| Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1838 | struct nfs4_state *state; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1839 |  | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1840 | if (!data->rpc_done) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1841 | state = nfs4_try_open_cached(data); | 
| Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1842 | trace_nfs4_cached_open(data->state); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1843 | goto out; | 
|  | 1844 | } | 
|  | 1845 |  | 
| Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1846 | state = nfs4_opendata_find_nfs4_state(data); | 
|  | 1847 | if (IS_ERR(state)) | 
|  | 1848 | goto out; | 
|  | 1849 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1850 | if (data->o_res.delegation_type != 0) | 
|  | 1851 | nfs4_opendata_check_deleg(data, state); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1852 | update_open_stateid(state, &data->o_res.stateid, NULL, | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1853 | data->o_arg.fmode); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1854 | out: | 
| Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1855 | nfs_release_seqid(data->o_arg.seqid); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1856 | return state; | 
|  | 1857 | } | 
|  | 1858 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1859 | static struct nfs4_state * | 
|  | 1860 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) | 
|  | 1861 | { | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1862 | struct nfs4_state *ret; | 
|  | 1863 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1864 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1865 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); | 
|  | 1866 | else | 
|  | 1867 | ret = _nfs4_opendata_to_nfs4_state(data); | 
|  | 1868 | nfs4_sequence_free_slot(&data->o_res.seq_res); | 
|  | 1869 | return ret; | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1870 | } | 
|  | 1871 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1872 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) | 
|  | 1873 | { | 
|  | 1874 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
|  | 1875 | struct nfs_open_context *ctx; | 
|  | 1876 |  | 
|  | 1877 | spin_lock(&state->inode->i_lock); | 
|  | 1878 | list_for_each_entry(ctx, &nfsi->open_files, list) { | 
|  | 1879 | if (ctx->state != state) | 
|  | 1880 | continue; | 
|  | 1881 | get_nfs_open_context(ctx); | 
|  | 1882 | spin_unlock(&state->inode->i_lock); | 
|  | 1883 | return ctx; | 
|  | 1884 | } | 
|  | 1885 | spin_unlock(&state->inode->i_lock); | 
|  | 1886 | return ERR_PTR(-ENOENT); | 
|  | 1887 | } | 
|  | 1888 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1889 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, | 
|  | 1890 | struct nfs4_state *state, enum open_claim_type4 claim) | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1891 | { | 
|  | 1892 | struct nfs4_opendata *opendata; | 
|  | 1893 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1894 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1895 | NULL, claim, GFP_NOFS); | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1896 | if (opendata == NULL) | 
|  | 1897 | return ERR_PTR(-ENOMEM); | 
|  | 1898 | opendata->state = state; | 
|  | 1899 | atomic_inc(&state->count); | 
|  | 1900 | return opendata; | 
|  | 1901 | } | 
|  | 1902 |  | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1903 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, | 
|  | 1904 | fmode_t fmode) | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1905 | { | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1906 | struct nfs4_state *newstate; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1907 | int ret; | 
|  | 1908 |  | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1909 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) | 
| NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1910 | return 0; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1911 | opendata->o_arg.open_flags = 0; | 
|  | 1912 | opendata->o_arg.fmode = fmode; | 
| Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1913 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( | 
|  | 1914 | NFS_SB(opendata->dentry->d_sb), | 
|  | 1915 | fmode, 0); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1916 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); | 
|  | 1917 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); | 
|  | 1918 | nfs4_init_opendata_res(opendata); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1919 | ret = _nfs4_recover_proc_open(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1920 | if (ret != 0) | 
|  | 1921 | return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1922 | newstate = nfs4_opendata_to_nfs4_state(opendata); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1923 | if (IS_ERR(newstate)) | 
|  | 1924 | return PTR_ERR(newstate); | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1925 | if (newstate != opendata->state) | 
|  | 1926 | ret = -ESTALE; | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1927 | nfs4_close_state(newstate, fmode); | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1928 | return ret; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1929 | } | 
|  | 1930 |  | 
|  | 1931 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) | 
|  | 1932 | { | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1933 | int ret; | 
|  | 1934 |  | 
| Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1935 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ | 
|  | 1936 | clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
|  | 1937 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 1938 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1939 | /* memory barrier prior to reading state->n_* */ | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1940 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 
| Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1941 | clear_bit(NFS_OPEN_STATE, &state->flags); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1942 | smp_rmb(); | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1943 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); | 
|  | 1944 | if (ret != 0) | 
|  | 1945 | return ret; | 
|  | 1946 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); | 
|  | 1947 | if (ret != 0) | 
|  | 1948 | return ret; | 
|  | 1949 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); | 
|  | 1950 | if (ret != 0) | 
|  | 1951 | return ret; | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1952 | /* | 
|  | 1953 | * We may have performed cached opens for all three recoveries. | 
|  | 1954 | * Check if we need to update the current stateid. | 
|  | 1955 | */ | 
|  | 1956 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1957 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1958 | write_seqlock(&state->seqlock); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1959 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1960 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1961 | write_sequnlock(&state->seqlock); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1962 | } | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1963 | return 0; | 
|  | 1964 | } | 
|  | 1965 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | /* | 
|  | 1967 | * OPEN_RECLAIM: | 
|  | 1968 | * 	reclaim state on the server after a reboot. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | */ | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1970 | 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] | 1971 | { | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1972 | struct nfs_delegation *delegation; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1973 | struct nfs4_opendata *opendata; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1974 | fmode_t delegation_type = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | int status; | 
|  | 1976 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1977 | opendata = nfs4_open_recoverdata_alloc(ctx, state, | 
|  | 1978 | NFS4_OPEN_CLAIM_PREVIOUS); | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1979 | if (IS_ERR(opendata)) | 
|  | 1980 | return PTR_ERR(opendata); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1981 | rcu_read_lock(); | 
|  | 1982 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); | 
| Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1983 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) | 
| Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1984 | delegation_type = delegation->type; | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1985 | rcu_read_unlock(); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1986 | opendata->o_arg.u.delegation_type = delegation_type; | 
|  | 1987 | status = nfs4_open_recover(opendata, state); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1988 | nfs4_opendata_put(opendata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | return status; | 
|  | 1990 | } | 
|  | 1991 |  | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1992 | 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] | 1993 | { | 
|  | 1994 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 1995 | struct nfs4_exception exception = { }; | 
|  | 1996 | int err; | 
|  | 1997 | do { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1998 | err = _nfs4_do_open_reclaim(ctx, state); | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1999 | trace_nfs4_open_reclaim(ctx, 0, err); | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2000 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) | 
|  | 2001 | continue; | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2002 | if (err != -NFS4ERR_DELAY) | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2003 | break; | 
|  | 2004 | nfs4_handle_exception(server, err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | } while (exception.retry); | 
|  | 2006 | return err; | 
|  | 2007 | } | 
|  | 2008 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2009 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|  | 2010 | { | 
|  | 2011 | struct nfs_open_context *ctx; | 
|  | 2012 | int ret; | 
|  | 2013 |  | 
|  | 2014 | ctx = nfs4_state_find_open_context(state); | 
|  | 2015 | if (IS_ERR(ctx)) | 
| Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2016 | return -EAGAIN; | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2017 | ret = nfs4_do_open_reclaim(ctx, state); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2018 | put_nfs_open_context(ctx); | 
|  | 2019 | return ret; | 
|  | 2020 | } | 
|  | 2021 |  | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2022 | static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | { | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2024 | switch (err) { | 
|  | 2025 | default: | 
|  | 2026 | printk(KERN_ERR "NFS: %s: unhandled error " | 
|  | 2027 | "%d.\n", __func__, err); | 
|  | 2028 | case 0: | 
|  | 2029 | case -ENOENT: | 
| Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2030 | case -EAGAIN: | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2031 | case -ESTALE: | 
|  | 2032 | break; | 
|  | 2033 | case -NFS4ERR_BADSESSION: | 
|  | 2034 | case -NFS4ERR_BADSLOT: | 
|  | 2035 | case -NFS4ERR_BAD_HIGH_SLOT: | 
|  | 2036 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|  | 2037 | case -NFS4ERR_DEADSESSION: | 
|  | 2038 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 2039 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); | 
|  | 2040 | return -EAGAIN; | 
|  | 2041 | case -NFS4ERR_STALE_CLIENTID: | 
|  | 2042 | case -NFS4ERR_STALE_STATEID: | 
|  | 2043 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2044 | /* Don't recall a delegation if it was lost */ | 
|  | 2045 | nfs4_schedule_lease_recovery(server->nfs_client); | 
|  | 2046 | return -EAGAIN; | 
| Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2047 | case -NFS4ERR_MOVED: | 
|  | 2048 | nfs4_schedule_migration_recovery(server); | 
|  | 2049 | return -EAGAIN; | 
| Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2050 | case -NFS4ERR_LEASE_MOVED: | 
|  | 2051 | nfs4_schedule_lease_moved_recovery(server->nfs_client); | 
|  | 2052 | return -EAGAIN; | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2053 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 2054 | case -NFS4ERR_ADMIN_REVOKED: | 
| Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2055 | case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2056 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2057 | case -NFS4ERR_OPENMODE: | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2058 | nfs_inode_find_state_and_recover(state->inode, | 
|  | 2059 | stateid); | 
|  | 2060 | nfs4_schedule_stateid_recovery(server, state); | 
| Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2061 | return -EAGAIN; | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2062 | case -NFS4ERR_DELAY: | 
|  | 2063 | case -NFS4ERR_GRACE: | 
|  | 2064 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 2065 | ssleep(1); | 
|  | 2066 | return -EAGAIN; | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2067 | case -ENOMEM: | 
|  | 2068 | case -NFS4ERR_DENIED: | 
|  | 2069 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ | 
|  | 2070 | return 0; | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2071 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | return err; | 
|  | 2073 | } | 
|  | 2074 |  | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2075 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, | 
|  | 2076 | struct nfs4_state *state, const nfs4_stateid *stateid, | 
|  | 2077 | fmode_t type) | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2078 | { | 
|  | 2079 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 2080 | struct nfs4_opendata *opendata; | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2081 | int err = 0; | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2082 |  | 
|  | 2083 | opendata = nfs4_open_recoverdata_alloc(ctx, state, | 
|  | 2084 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); | 
|  | 2085 | if (IS_ERR(opendata)) | 
|  | 2086 | return PTR_ERR(opendata); | 
|  | 2087 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); | 
| Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2088 | write_seqlock(&state->seqlock); | 
|  | 2089 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); | 
|  | 2090 | write_sequnlock(&state->seqlock); | 
| Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2091 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 2092 | switch (type & (FMODE_READ|FMODE_WRITE)) { | 
|  | 2093 | case FMODE_READ|FMODE_WRITE: | 
|  | 2094 | case FMODE_WRITE: | 
|  | 2095 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); | 
|  | 2096 | if (err) | 
|  | 2097 | break; | 
|  | 2098 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); | 
|  | 2099 | if (err) | 
|  | 2100 | break; | 
|  | 2101 | case FMODE_READ: | 
|  | 2102 | err = nfs4_open_recover_helper(opendata, FMODE_READ); | 
|  | 2103 | } | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2104 | nfs4_opendata_put(opendata); | 
|  | 2105 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); | 
|  | 2106 | } | 
|  | 2107 |  | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2108 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) | 
|  | 2109 | { | 
|  | 2110 | struct nfs4_opendata *data = calldata; | 
|  | 2111 |  | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2112 | nfs4_setup_sequence(data->o_arg.server->nfs_client, | 
|  | 2113 | &data->c_arg.seq_args, &data->c_res.seq_res, task); | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2114 | } | 
|  | 2115 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2116 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) | 
|  | 2117 | { | 
|  | 2118 | struct nfs4_opendata *data = calldata; | 
|  | 2119 |  | 
| Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2120 | nfs40_sequence_done(task, &data->c_res.seq_res); | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2121 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2122 | data->rpc_status = task->tk_status; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2123 | if (data->rpc_status == 0) { | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2124 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); | 
| Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2125 | nfs_confirm_seqid(&data->owner->so_seqid, 0); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2126 | renew_lease(data->o_res.server, data->timestamp); | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2127 | data->rpc_done = true; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2128 | } | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2129 | } | 
|  | 2130 |  | 
|  | 2131 | static void nfs4_open_confirm_release(void *calldata) | 
|  | 2132 | { | 
|  | 2133 | struct nfs4_opendata *data = calldata; | 
|  | 2134 | struct nfs4_state *state = NULL; | 
|  | 2135 |  | 
|  | 2136 | /* If this request hasn't been cancelled, do nothing */ | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2137 | if (!data->cancelled) | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2138 | goto out_free; | 
|  | 2139 | /* In case of error, no cleanup! */ | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2140 | if (!data->rpc_done) | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2141 | goto out_free; | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2142 | state = nfs4_opendata_to_nfs4_state(data); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2143 | if (!IS_ERR(state)) | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2144 | nfs4_close_state(state, data->o_arg.fmode); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2145 | out_free: | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2146 | nfs4_opendata_put(data); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2147 | } | 
|  | 2148 |  | 
|  | 2149 | static const struct rpc_call_ops nfs4_open_confirm_ops = { | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2150 | .rpc_call_prepare = nfs4_open_confirm_prepare, | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2151 | .rpc_call_done = nfs4_open_confirm_done, | 
|  | 2152 | .rpc_release = nfs4_open_confirm_release, | 
|  | 2153 | }; | 
|  | 2154 |  | 
|  | 2155 | /* | 
|  | 2156 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata | 
|  | 2157 | */ | 
|  | 2158 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) | 
|  | 2159 | { | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2160 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2161 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2162 | struct  rpc_message msg = { | 
|  | 2163 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], | 
|  | 2164 | .rpc_argp = &data->c_arg, | 
|  | 2165 | .rpc_resp = &data->c_res, | 
|  | 2166 | .rpc_cred = data->owner->so_cred, | 
|  | 2167 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2168 | struct rpc_task_setup task_setup_data = { | 
|  | 2169 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2170 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2171 | .callback_ops = &nfs4_open_confirm_ops, | 
|  | 2172 | .callback_data = data, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2173 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2174 | .flags = RPC_TASK_ASYNC, | 
|  | 2175 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | int status; | 
|  | 2177 |  | 
| Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2178 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2179 | kref_get(&data->kref); | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2180 | data->rpc_done = false; | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2181 | data->rpc_status = 0; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2182 | data->timestamp = jiffies; | 
| Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2183 | if (data->is_recover) | 
|  | 2184 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2185 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2186 | if (IS_ERR(task)) | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2187 | return PTR_ERR(task); | 
| Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2188 | status = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2189 | if (status != 0) { | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2190 | data->cancelled = true; | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2191 | smp_wmb(); | 
|  | 2192 | } else | 
|  | 2193 | status = data->rpc_status; | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2194 | rpc_put_task(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | return status; | 
|  | 2196 | } | 
|  | 2197 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2198 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | { | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2200 | struct nfs4_opendata *data = calldata; | 
|  | 2201 | struct nfs4_state_owner *sp = data->owner; | 
| Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2202 | struct nfs_client *clp = sp->so_server->nfs_client; | 
| Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2203 | enum open_claim_type4 claim = data->o_arg.claim; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2204 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2205 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2206 | goto out_wait; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2207 | /* | 
|  | 2208 | * Check if we still need to send an OPEN call, or if we can use | 
|  | 2209 | * a delegation instead. | 
|  | 2210 | */ | 
|  | 2211 | if (data->state != NULL) { | 
|  | 2212 | struct nfs_delegation *delegation; | 
|  | 2213 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2214 | 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] | 2215 | goto out_no_action; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2216 | rcu_read_lock(); | 
|  | 2217 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); | 
| Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2218 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2219 | goto unlock_no_action; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2220 | rcu_read_unlock(); | 
|  | 2221 | } | 
| Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2222 | /* Update client id. */ | 
| Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2223 | data->o_arg.clientid = clp->cl_clientid; | 
| Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2224 | switch (claim) { | 
|  | 2225 | default: | 
|  | 2226 | break; | 
| Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2227 | case NFS4_OPEN_CLAIM_PREVIOUS: | 
|  | 2228 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | 
|  | 2229 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2230 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; | 
| Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2231 | case NFS4_OPEN_CLAIM_FH: | 
|  | 2232 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2233 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2234 | data->timestamp = jiffies; | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2235 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2236 | &data->o_arg.seq_args, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2237 | &data->o_res.seq_res, | 
|  | 2238 | task) != 0) | 
|  | 2239 | nfs_release_seqid(data->o_arg.seqid); | 
| Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2240 |  | 
|  | 2241 | /* Set the create mode (note dependency on the session type) */ | 
|  | 2242 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; | 
|  | 2243 | if (data->o_arg.open_flags & O_EXCL) { | 
|  | 2244 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; | 
|  | 2245 | if (nfs4_has_persistent_session(clp)) | 
|  | 2246 | data->o_arg.createmode = NFS4_CREATE_GUARDED; | 
|  | 2247 | else if (clp->cl_mvops->minor_version > 0) | 
|  | 2248 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; | 
|  | 2249 | } | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2250 | return; | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2251 | unlock_no_action: | 
| Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2252 | trace_nfs4_cached_open(data->state); | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2253 | rcu_read_unlock(); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2254 | out_no_action: | 
|  | 2255 | task->tk_action = NULL; | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2256 | out_wait: | 
| Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2257 | nfs4_sequence_done(task, &data->o_res.seq_res); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2258 | } | 
|  | 2259 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2260 | static void nfs4_open_done(struct rpc_task *task, void *calldata) | 
|  | 2261 | { | 
|  | 2262 | struct nfs4_opendata *data = calldata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2264 | data->rpc_status = task->tk_status; | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2265 |  | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2266 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2267 | return; | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2268 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2269 | if (task->tk_status == 0) { | 
| Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2270 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { | 
|  | 2271 | switch (data->o_res.f_attr->mode & S_IFMT) { | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2272 | case S_IFREG: | 
|  | 2273 | break; | 
|  | 2274 | case S_IFLNK: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2275 | data->rpc_status = -ELOOP; | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2276 | break; | 
|  | 2277 | case S_IFDIR: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2278 | data->rpc_status = -EISDIR; | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2279 | break; | 
|  | 2280 | default: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2281 | data->rpc_status = -ENOTDIR; | 
| Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2282 | } | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2283 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2284 | renew_lease(data->o_res.server, data->timestamp); | 
| Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2285 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) | 
|  | 2286 | nfs_confirm_seqid(&data->owner->so_seqid, 0); | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2287 | } | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2288 | data->rpc_done = true; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2289 | } | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2290 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2291 | static void nfs4_open_release(void *calldata) | 
|  | 2292 | { | 
|  | 2293 | struct nfs4_opendata *data = calldata; | 
|  | 2294 | struct nfs4_state *state = NULL; | 
|  | 2295 |  | 
|  | 2296 | /* If this request hasn't been cancelled, do nothing */ | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2297 | if (!data->cancelled) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2298 | goto out_free; | 
|  | 2299 | /* In case of error, no cleanup! */ | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2300 | if (data->rpc_status != 0 || !data->rpc_done) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2301 | goto out_free; | 
|  | 2302 | /* In case we need an open_confirm, no cleanup! */ | 
|  | 2303 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) | 
|  | 2304 | goto out_free; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2305 | state = nfs4_opendata_to_nfs4_state(data); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2306 | if (!IS_ERR(state)) | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2307 | nfs4_close_state(state, data->o_arg.fmode); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2308 | out_free: | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2309 | nfs4_opendata_put(data); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2310 | } | 
|  | 2311 |  | 
|  | 2312 | static const struct rpc_call_ops nfs4_open_ops = { | 
|  | 2313 | .rpc_call_prepare = nfs4_open_prepare, | 
|  | 2314 | .rpc_call_done = nfs4_open_done, | 
|  | 2315 | .rpc_release = nfs4_open_release, | 
|  | 2316 | }; | 
|  | 2317 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2318 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2319 | { | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2320 | struct inode *dir = d_inode(data->dir); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2321 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 2322 | struct nfs_openargs *o_arg = &data->o_arg; | 
|  | 2323 | struct nfs_openres *o_res = &data->o_res; | 
|  | 2324 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2325 | struct rpc_message msg = { | 
|  | 2326 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], | 
|  | 2327 | .rpc_argp = o_arg, | 
|  | 2328 | .rpc_resp = o_res, | 
|  | 2329 | .rpc_cred = data->owner->so_cred, | 
|  | 2330 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2331 | struct rpc_task_setup task_setup_data = { | 
|  | 2332 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2333 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2334 | .callback_ops = &nfs4_open_ops, | 
|  | 2335 | .callback_data = data, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2336 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2337 | .flags = RPC_TASK_ASYNC, | 
|  | 2338 | }; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2339 | int status; | 
|  | 2340 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2341 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2342 | kref_get(&data->kref); | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2343 | data->rpc_done = false; | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2344 | data->rpc_status = 0; | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2345 | data->cancelled = false; | 
|  | 2346 | data->is_recover = false; | 
| Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2347 | if (isrecover) { | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2348 | nfs4_set_sequence_privileged(&o_arg->seq_args); | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2349 | data->is_recover = true; | 
| Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2350 | } | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2351 | task = rpc_run_task(&task_setup_data); | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2352 | if (IS_ERR(task)) | 
|  | 2353 | return PTR_ERR(task); | 
| Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2354 | status = rpc_wait_for_completion_task(task); | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2355 | if (status != 0) { | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2356 | data->cancelled = true; | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2357 | smp_wmb(); | 
|  | 2358 | } else | 
|  | 2359 | status = data->rpc_status; | 
|  | 2360 | rpc_put_task(task); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2361 |  | 
|  | 2362 | return status; | 
|  | 2363 | } | 
|  | 2364 |  | 
|  | 2365 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) | 
|  | 2366 | { | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2367 | struct inode *dir = d_inode(data->dir); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2368 | struct nfs_openres *o_res = &data->o_res; | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2369 | int status; | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2370 |  | 
|  | 2371 | status = nfs4_run_open_task(data, 1); | 
|  | 2372 | if (status != 0 || !data->rpc_done) | 
|  | 2373 | return status; | 
|  | 2374 |  | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2375 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); | 
|  | 2376 |  | 
| Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2377 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2378 | status = _nfs4_proc_open_confirm(data); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2379 |  | 
|  | 2380 | return status; | 
|  | 2381 | } | 
|  | 2382 |  | 
| Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2383 | /* | 
|  | 2384 | * Additional permission checks in order to distinguish between an | 
|  | 2385 | * open for read, and an open for execute. This works around the | 
|  | 2386 | * fact that NFSv4 OPEN treats read and execute permissions as being | 
|  | 2387 | * the same. | 
|  | 2388 | * Note that in the non-execute case, we want to turn off permission | 
|  | 2389 | * checking if we just created a new file (POSIX open() semantics). | 
|  | 2390 | */ | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2391 | static int nfs4_opendata_access(struct rpc_cred *cred, | 
|  | 2392 | struct nfs4_opendata *opendata, | 
| Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2393 | struct nfs4_state *state, fmode_t fmode, | 
|  | 2394 | int openflags) | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2395 | { | 
|  | 2396 | struct nfs_access_entry cache; | 
| Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2397 | u32 mask, flags; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2398 |  | 
|  | 2399 | /* access call failed or for some reason the server doesn't | 
|  | 2400 | * support any access modes -- defer access call until later */ | 
|  | 2401 | if (opendata->o_res.access_supported == 0) | 
|  | 2402 | return 0; | 
|  | 2403 |  | 
|  | 2404 | mask = 0; | 
| Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2405 | /* | 
|  | 2406 | * Use openflags to check for exec, because fmode won't | 
|  | 2407 | * always have FMODE_EXEC set when file open for exec. | 
|  | 2408 | */ | 
| Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2409 | if (openflags & __FMODE_EXEC) { | 
|  | 2410 | /* ONLY check for exec rights */ | 
| Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2411 | if (S_ISDIR(state->inode->i_mode)) | 
|  | 2412 | mask = NFS4_ACCESS_LOOKUP; | 
|  | 2413 | else | 
|  | 2414 | mask = NFS4_ACCESS_EXECUTE; | 
| Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2415 | } else if ((fmode & FMODE_READ) && !opendata->file_created) | 
| Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2416 | mask = NFS4_ACCESS_READ; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2417 |  | 
|  | 2418 | cache.cred = cred; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2419 | nfs_access_set_mask(&cache, opendata->o_res.access_result); | 
|  | 2420 | nfs_access_add_cache(state->inode, &cache); | 
|  | 2421 |  | 
| Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2422 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; | 
|  | 2423 | if ((mask & ~cache.mask & flags) == 0) | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2424 | return 0; | 
|  | 2425 |  | 
| Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2426 | return -EACCES; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2427 | } | 
|  | 2428 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2429 | /* | 
|  | 2430 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata | 
|  | 2431 | */ | 
|  | 2432 | static int _nfs4_proc_open(struct nfs4_opendata *data) | 
|  | 2433 | { | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2434 | struct inode *dir = d_inode(data->dir); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2435 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 2436 | struct nfs_openargs *o_arg = &data->o_arg; | 
|  | 2437 | struct nfs_openres *o_res = &data->o_res; | 
|  | 2438 | int status; | 
|  | 2439 |  | 
|  | 2440 | status = nfs4_run_open_task(data, 0); | 
| Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2441 | if (!data->rpc_done) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2442 | return status; | 
| Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2443 | if (status != 0) { | 
|  | 2444 | if (status == -NFS4ERR_BADNAME && | 
|  | 2445 | !(o_arg->open_flags & O_CREAT)) | 
|  | 2446 | return -ENOENT; | 
|  | 2447 | return status; | 
|  | 2448 | } | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2449 |  | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2450 | nfs_fattr_map_and_free_names(server, &data->f_attr); | 
|  | 2451 |  | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2452 | if (o_arg->open_flags & O_CREAT) { | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2453 | if (o_arg->open_flags & O_EXCL) | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2454 | data->file_created = true; | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2455 | else if (o_res->cinfo.before != o_res->cinfo.after) | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2456 | data->file_created = true; | 
| Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2457 | if (data->file_created || dir->i_version != o_res->cinfo.after) | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2458 | update_changeattr(dir, &o_res->cinfo, | 
|  | 2459 | o_res->f_attr->time_start); | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2460 | } | 
| Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2461 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) | 
|  | 2462 | server->caps &= ~NFS_CAP_POSIX_LOCK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2464 | status = _nfs4_proc_open_confirm(data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | if (status != 0) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2466 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | } | 
| Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2468 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { | 
|  | 2469 | nfs4_sequence_free_slot(&o_res->seq_res); | 
| Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2470 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); | 
| Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2471 | } | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2472 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } | 
|  | 2474 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | /* | 
|  | 2476 | * OPEN_EXPIRED: | 
|  | 2477 | * 	reclaim state on the server after a network partition. | 
|  | 2478 | * 	Assumes caller holds the appropriate lock | 
|  | 2479 | */ | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2480 | 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] | 2481 | { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2482 | struct nfs4_opendata *opendata; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2483 | int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2485 | opendata = nfs4_open_recoverdata_alloc(ctx, state, | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2486 | NFS4_OPEN_CLAIM_FH); | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2487 | if (IS_ERR(opendata)) | 
|  | 2488 | return PTR_ERR(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2489 | ret = nfs4_open_recover(opendata, state); | 
| Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2490 | if (ret == -ESTALE) | 
| Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2491 | d_drop(ctx->dentry); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2492 | nfs4_opendata_put(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2493 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } | 
|  | 2495 |  | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2496 | 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] | 2497 | { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2498 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2499 | struct nfs4_exception exception = { }; | 
|  | 2500 | int err; | 
|  | 2501 |  | 
|  | 2502 | do { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2503 | err = _nfs4_open_expired(ctx, state); | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2504 | trace_nfs4_open_expired(ctx, 0, err); | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2505 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) | 
|  | 2506 | continue; | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2507 | switch (err) { | 
|  | 2508 | default: | 
|  | 2509 | goto out; | 
|  | 2510 | case -NFS4ERR_GRACE: | 
|  | 2511 | case -NFS4ERR_DELAY: | 
|  | 2512 | nfs4_handle_exception(server, err, &exception); | 
|  | 2513 | err = 0; | 
|  | 2514 | } | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2515 | } while (exception.retry); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2516 | out: | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2517 | return err; | 
|  | 2518 | } | 
|  | 2519 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|  | 2521 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | struct nfs_open_context *ctx; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2523 | int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2525 | ctx = nfs4_state_find_open_context(state); | 
|  | 2526 | if (IS_ERR(ctx)) | 
| Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2527 | return -EAGAIN; | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2528 | ret = nfs4_do_open_expired(ctx, state); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2529 | put_nfs_open_context(ctx); | 
|  | 2530 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | } | 
|  | 2532 |  | 
| Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2533 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, | 
|  | 2534 | const nfs4_stateid *stateid) | 
| Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2535 | { | 
| Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2536 | nfs_remove_bad_delegation(state->inode, stateid); | 
| Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2537 | write_seqlock(&state->seqlock); | 
|  | 2538 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); | 
|  | 2539 | write_sequnlock(&state->seqlock); | 
|  | 2540 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 2541 | } | 
|  | 2542 |  | 
|  | 2543 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) | 
|  | 2544 | { | 
|  | 2545 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) | 
| Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2546 | nfs_finish_clear_delegation_stateid(state, NULL); | 
| Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2547 | } | 
|  | 2548 |  | 
|  | 2549 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|  | 2550 | { | 
|  | 2551 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ | 
|  | 2552 | nfs40_clear_delegation_stateid(state); | 
|  | 2553 | return nfs4_open_expired(sp, state); | 
|  | 2554 | } | 
|  | 2555 |  | 
| Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2556 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, | 
|  | 2557 | nfs4_stateid *stateid, | 
|  | 2558 | struct rpc_cred *cred) | 
|  | 2559 | { | 
|  | 2560 | return -NFS4ERR_BAD_STATEID; | 
|  | 2561 | } | 
|  | 2562 |  | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2563 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2564 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, | 
|  | 2565 | nfs4_stateid *stateid, | 
|  | 2566 | struct rpc_cred *cred) | 
|  | 2567 | { | 
|  | 2568 | int status; | 
|  | 2569 |  | 
| Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2570 | switch (stateid->type) { | 
|  | 2571 | default: | 
|  | 2572 | break; | 
|  | 2573 | case NFS4_INVALID_STATEID_TYPE: | 
|  | 2574 | case NFS4_SPECIAL_STATEID_TYPE: | 
|  | 2575 | return -NFS4ERR_BAD_STATEID; | 
|  | 2576 | case NFS4_REVOKED_STATEID_TYPE: | 
|  | 2577 | goto out_free; | 
|  | 2578 | } | 
| Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2579 |  | 
| Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2580 | status = nfs41_test_stateid(server, stateid, cred); | 
| Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2581 | switch (status) { | 
|  | 2582 | case -NFS4ERR_EXPIRED: | 
|  | 2583 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 2584 | case -NFS4ERR_DELEG_REVOKED: | 
| Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2585 | break; | 
|  | 2586 | default: | 
| Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2587 | return status; | 
|  | 2588 | } | 
| Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2589 | out_free: | 
|  | 2590 | /* Ack the revoked state to the server */ | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2591 | nfs41_free_stateid(server, stateid, cred, true); | 
| Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2592 | return -NFS4ERR_EXPIRED; | 
| Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2593 | } | 
|  | 2594 |  | 
| Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2595 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2596 | { | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2597 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2598 | nfs4_stateid stateid; | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2599 | struct nfs_delegation *delegation; | 
| Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2600 | struct rpc_cred *cred; | 
|  | 2601 | int status; | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2602 |  | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2603 | /* Get the delegation credential for use by test/free_stateid */ | 
|  | 2604 | rcu_read_lock(); | 
|  | 2605 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); | 
| Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2606 | if (delegation == NULL) { | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2607 | rcu_read_unlock(); | 
| Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2608 | return; | 
|  | 2609 | } | 
|  | 2610 |  | 
|  | 2611 | nfs4_stateid_copy(&stateid, &delegation->stateid); | 
| Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2612 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || | 
|  | 2613 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, | 
|  | 2614 | &delegation->flags)) { | 
| Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2615 | rcu_read_unlock(); | 
| Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2616 | nfs_finish_clear_delegation_stateid(state, &stateid); | 
| Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2617 | return; | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2618 | } | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2619 |  | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2620 | cred = get_rpccred(delegation->cred); | 
|  | 2621 | rcu_read_unlock(); | 
| Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2622 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2623 | trace_nfs4_test_delegation_stateid(state, NULL, status); | 
| Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2624 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) | 
| Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2625 | nfs_finish_clear_delegation_stateid(state, &stateid); | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2626 |  | 
| Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2627 | put_rpccred(cred); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2628 | } | 
|  | 2629 |  | 
|  | 2630 | /** | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2631 | * nfs41_check_expired_locks - possibly free a lock stateid | 
|  | 2632 | * | 
|  | 2633 | * @state: NFSv4 state for an inode | 
|  | 2634 | * | 
|  | 2635 | * Returns NFS_OK if recovery for this stateid is now finished. | 
|  | 2636 | * Otherwise a negative NFS4ERR value is returned. | 
|  | 2637 | */ | 
|  | 2638 | static int nfs41_check_expired_locks(struct nfs4_state *state) | 
|  | 2639 | { | 
|  | 2640 | int status, ret = NFS_OK; | 
| Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2641 | struct nfs4_lock_state *lsp, *prev = NULL; | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2642 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 2643 |  | 
|  | 2644 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) | 
|  | 2645 | goto out; | 
| Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2646 |  | 
|  | 2647 | spin_lock(&state->state_lock); | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2648 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { | 
|  | 2649 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { | 
|  | 2650 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; | 
|  | 2651 |  | 
| Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2652 | refcount_inc(&lsp->ls_count); | 
| Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2653 | spin_unlock(&state->state_lock); | 
|  | 2654 |  | 
|  | 2655 | nfs4_put_lock_state(prev); | 
|  | 2656 | prev = lsp; | 
|  | 2657 |  | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2658 | status = nfs41_test_and_free_expired_stateid(server, | 
|  | 2659 | &lsp->ls_stateid, | 
|  | 2660 | cred); | 
|  | 2661 | trace_nfs4_test_lock_stateid(state, lsp, status); | 
|  | 2662 | if (status == -NFS4ERR_EXPIRED || | 
|  | 2663 | status == -NFS4ERR_BAD_STATEID) { | 
|  | 2664 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); | 
| Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2665 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2666 | if (!recover_lost_locks) | 
|  | 2667 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); | 
|  | 2668 | } else if (status != NFS_OK) { | 
|  | 2669 | ret = status; | 
| Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2670 | nfs4_put_lock_state(prev); | 
|  | 2671 | goto out; | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2672 | } | 
| Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2673 | spin_lock(&state->state_lock); | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2674 | } | 
| Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2675 | } | 
|  | 2676 | spin_unlock(&state->state_lock); | 
|  | 2677 | nfs4_put_lock_state(prev); | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2678 | out: | 
|  | 2679 | return ret; | 
|  | 2680 | } | 
|  | 2681 |  | 
|  | 2682 | /** | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2683 | * nfs41_check_open_stateid - possibly free an open stateid | 
|  | 2684 | * | 
|  | 2685 | * @state: NFSv4 state for an inode | 
|  | 2686 | * | 
|  | 2687 | * Returns NFS_OK if recovery for this stateid is now finished. | 
|  | 2688 | * Otherwise a negative NFS4ERR value is returned. | 
|  | 2689 | */ | 
|  | 2690 | static int nfs41_check_open_stateid(struct nfs4_state *state) | 
|  | 2691 | { | 
|  | 2692 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2693 | nfs4_stateid *stateid = &state->open_stateid; | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2694 | struct rpc_cred *cred = state->owner->so_cred; | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2695 | int status; | 
|  | 2696 |  | 
| Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2697 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { | 
| Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2698 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)  { | 
|  | 2699 | if (nfs4_have_delegation(state->inode, state->state)) | 
|  | 2700 | return NFS_OK; | 
|  | 2701 | return -NFS4ERR_OPENMODE; | 
|  | 2702 | } | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2703 | return -NFS4ERR_BAD_STATEID; | 
| Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2704 | } | 
| Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2705 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); | 
| Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2706 | trace_nfs4_test_open_stateid(state, NULL, status); | 
| Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2707 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2708 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 2709 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 2710 | clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
| Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2711 | clear_bit(NFS_OPEN_STATE, &state->flags); | 
| Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2712 | stateid->type = NFS4_INVALID_STATEID_TYPE; | 
| Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2713 | return status; | 
| Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2714 | } | 
| Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2715 | if (nfs_open_stateid_recover_openmode(state)) | 
|  | 2716 | return -NFS4ERR_OPENMODE; | 
|  | 2717 | return NFS_OK; | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2718 | } | 
|  | 2719 |  | 
|  | 2720 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|  | 2721 | { | 
| Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2722 | int status; | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2723 |  | 
| Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2724 | nfs41_check_delegation_stateid(state); | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2725 | status = nfs41_check_expired_locks(state); | 
|  | 2726 | if (status != NFS_OK) | 
|  | 2727 | return status; | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2728 | status = nfs41_check_open_stateid(state); | 
| Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2729 | if (status != NFS_OK) | 
|  | 2730 | status = nfs4_open_expired(sp, state); | 
|  | 2731 | return status; | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2732 | } | 
|  | 2733 | #endif | 
|  | 2734 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | /* | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2736 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* | 
|  | 2737 | * fields corresponding to attributes that were used to store the verifier. | 
|  | 2738 | * Make sure we clobber those fields in the later setattr call | 
|  | 2739 | */ | 
| Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2740 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, | 
|  | 2741 | struct iattr *sattr, struct nfs4_label **label) | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2742 | { | 
| Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2743 | const u32 *attrset = opendata->o_res.attrset; | 
|  | 2744 |  | 
|  | 2745 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2746 | !(sattr->ia_valid & ATTR_ATIME_SET)) | 
|  | 2747 | sattr->ia_valid |= ATTR_ATIME; | 
|  | 2748 |  | 
| Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2749 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2750 | !(sattr->ia_valid & ATTR_MTIME_SET)) | 
|  | 2751 | sattr->ia_valid |= ATTR_MTIME; | 
| Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2752 |  | 
|  | 2753 | /* Except MODE, it seems harmless of setting twice. */ | 
| Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2754 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && | 
| Benjamin Coddington | 501e7a4 | 2017-06-02 11:21:34 -0400 | [diff] [blame] | 2755 | (attrset[1] & FATTR4_WORD1_MODE || | 
|  | 2756 | attrset[2] & FATTR4_WORD2_MODE_UMASK)) | 
| Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2757 | sattr->ia_valid &= ~ATTR_MODE; | 
|  | 2758 |  | 
|  | 2759 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) | 
|  | 2760 | *label = NULL; | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2761 | } | 
|  | 2762 |  | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2763 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, | 
|  | 2764 | fmode_t fmode, | 
|  | 2765 | int flags, | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2766 | struct nfs_open_context *ctx) | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2767 | { | 
|  | 2768 | struct nfs4_state_owner *sp = opendata->owner; | 
|  | 2769 | struct nfs_server *server = sp->so_server; | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2770 | struct dentry *dentry; | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2771 | struct nfs4_state *state; | 
|  | 2772 | unsigned int seq; | 
|  | 2773 | int ret; | 
|  | 2774 |  | 
|  | 2775 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); | 
|  | 2776 |  | 
|  | 2777 | ret = _nfs4_proc_open(opendata); | 
| Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2778 | if (ret != 0) | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2779 | goto out; | 
|  | 2780 |  | 
|  | 2781 | state = nfs4_opendata_to_nfs4_state(opendata); | 
|  | 2782 | ret = PTR_ERR(state); | 
|  | 2783 | if (IS_ERR(state)) | 
|  | 2784 | goto out; | 
| Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2785 | ctx->state = state; | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2786 | if (server->caps & NFS_CAP_POSIX_LOCK) | 
|  | 2787 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); | 
| Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2788 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) | 
|  | 2789 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2790 |  | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2791 | dentry = opendata->dentry; | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2792 | if (d_really_is_negative(dentry)) { | 
| Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2793 | struct dentry *alias; | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2794 | d_drop(dentry); | 
| Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2795 | alias = d_exact_alias(dentry, state->inode); | 
|  | 2796 | if (!alias) | 
|  | 2797 | alias = d_splice_alias(igrab(state->inode), dentry); | 
|  | 2798 | /* d_splice_alias() can't fail here - it's a non-directory */ | 
|  | 2799 | if (alias) { | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2800 | dput(ctx->dentry); | 
| Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2801 | ctx->dentry = dentry = alias; | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2802 | } | 
|  | 2803 | nfs_set_verifier(dentry, | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2804 | nfs_save_change_attribute(d_inode(opendata->dir))); | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2805 | } | 
|  | 2806 |  | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2807 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); | 
|  | 2808 | if (ret != 0) | 
|  | 2809 | goto out; | 
|  | 2810 |  | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2811 | if (d_inode(dentry) == state->inode) { | 
| Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2812 | nfs_inode_attach_open_context(ctx); | 
|  | 2813 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) | 
|  | 2814 | nfs4_schedule_stateid_recovery(server, state); | 
|  | 2815 | } | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2816 | out: | 
|  | 2817 | return ret; | 
|  | 2818 | } | 
|  | 2819 |  | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2820 | /* | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2821 | * Returns a referenced nfs4_state | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | */ | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2823 | static int _nfs4_do_open(struct inode *dir, | 
| Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2824 | struct nfs_open_context *ctx, | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2825 | int flags, | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2826 | const struct nfs4_open_createattrs *c, | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2827 | int *opened) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | { | 
|  | 2829 | struct nfs4_state_owner  *sp; | 
|  | 2830 | struct nfs4_state     *state = NULL; | 
|  | 2831 | struct nfs_server       *server = NFS_SERVER(dir); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2832 | struct nfs4_opendata *opendata; | 
| Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2833 | struct dentry *dentry = ctx->dentry; | 
|  | 2834 | struct rpc_cred *cred = ctx->cred; | 
|  | 2835 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; | 
|  | 2836 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2837 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2838 | struct iattr *sattr = c->sattr; | 
|  | 2839 | struct nfs4_label *label = c->label; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2840 | struct nfs4_label *olabel = NULL; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2841 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 |  | 
|  | 2843 | /* Protect against reboot recovery conflicts */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | status = -ENOMEM; | 
| Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2845 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); | 
|  | 2846 | if (sp == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); | 
|  | 2848 | goto out_err; | 
|  | 2849 | } | 
| Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2850 | status = nfs4_client_recover_expired_lease(server->nfs_client); | 
| Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2851 | if (status != 0) | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2852 | goto err_put_state_owner; | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2853 | if (d_really_is_positive(dentry)) | 
|  | 2854 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); | 
| Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2855 | status = -ENOMEM; | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2856 | if (d_really_is_positive(dentry)) | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2857 | claim = NFS4_OPEN_CLAIM_FH; | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2858 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, | 
|  | 2859 | c, claim, GFP_KERNEL); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2860 | if (opendata == NULL) | 
| Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2861 | goto err_put_state_owner; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2863 | if (label) { | 
|  | 2864 | olabel = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 2865 | if (IS_ERR(olabel)) { | 
|  | 2866 | status = PTR_ERR(olabel); | 
|  | 2867 | goto err_opendata_put; | 
|  | 2868 | } | 
|  | 2869 | } | 
|  | 2870 |  | 
| Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2871 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { | 
|  | 2872 | if (!opendata->f_attr.mdsthreshold) { | 
|  | 2873 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); | 
|  | 2874 | if (!opendata->f_attr.mdsthreshold) | 
|  | 2875 | goto err_free_label; | 
|  | 2876 | } | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2877 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2878 | } | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2879 | if (d_really_is_positive(dentry)) | 
|  | 2880 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2881 |  | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2882 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2883 | if (status != 0) | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2884 | goto err_free_label; | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2885 | state = ctx->state; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2886 |  | 
| NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2887 | 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] | 2888 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { | 
| Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2889 | nfs4_exclusive_attrset(opendata, sattr, &label); | 
| Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2890 | /* | 
|  | 2891 | * send create attributes which was not set by open | 
|  | 2892 | * with an extra setattr. | 
|  | 2893 | */ | 
|  | 2894 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { | 
|  | 2895 | nfs_fattr_init(opendata->o_res.f_attr); | 
|  | 2896 | status = nfs4_do_setattr(state->inode, cred, | 
|  | 2897 | opendata->o_res.f_attr, sattr, | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2898 | ctx, label, olabel); | 
| Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2899 | if (status == 0) { | 
|  | 2900 | nfs_setattr_update_inode(state->inode, sattr, | 
|  | 2901 | opendata->o_res.f_attr); | 
|  | 2902 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); | 
|  | 2903 | } | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2904 | } | 
| Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2905 | } | 
| Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2906 | if (opened && opendata->file_created) | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2907 | *opened |= FILE_CREATED; | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2908 |  | 
| Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2909 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2910 | *ctx_th = opendata->f_attr.mdsthreshold; | 
| Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2911 | opendata->f_attr.mdsthreshold = NULL; | 
|  | 2912 | } | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2913 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2914 | nfs4_label_free(olabel); | 
|  | 2915 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2916 | nfs4_opendata_put(opendata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | nfs4_put_state_owner(sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | return 0; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2919 | err_free_label: | 
|  | 2920 | nfs4_label_free(olabel); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2921 | err_opendata_put: | 
|  | 2922 | nfs4_opendata_put(opendata); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2923 | err_put_state_owner: | 
|  | 2924 | nfs4_put_state_owner(sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | out_err: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | return status; | 
|  | 2927 | } | 
|  | 2928 |  | 
|  | 2929 |  | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2930 | static struct nfs4_state *nfs4_do_open(struct inode *dir, | 
| Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2931 | struct nfs_open_context *ctx, | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2932 | int flags, | 
|  | 2933 | struct iattr *sattr, | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2934 | struct nfs4_label *label, | 
|  | 2935 | int *opened) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | { | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2937 | struct nfs_server *server = NFS_SERVER(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | struct nfs4_exception exception = { }; | 
|  | 2939 | struct nfs4_state *res; | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2940 | struct nfs4_open_createattrs c = { | 
|  | 2941 | .label = label, | 
|  | 2942 | .sattr = sattr, | 
|  | 2943 | .verf = { | 
|  | 2944 | [0] = (__u32)jiffies, | 
|  | 2945 | [1] = (__u32)current->pid, | 
|  | 2946 | }, | 
|  | 2947 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | int status; | 
|  | 2949 |  | 
|  | 2950 | do { | 
| Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2951 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2952 | res = ctx->state; | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2953 | trace_nfs4_open_file(ctx, flags, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | if (status == 0) | 
|  | 2955 | break; | 
|  | 2956 | /* NOTE: BAD_SEQID means the server and client disagree about the | 
|  | 2957 | * book-keeping w.r.t. state-changing operations | 
|  | 2958 | * (OPEN/CLOSE/LOCK/LOCKU...) | 
|  | 2959 | * It is actually a sign of a bug on the client or on the server. | 
|  | 2960 | * | 
|  | 2961 | * If we receive a BAD_SEQID error in the particular case of | 
| Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2962 | * doing an OPEN, we assume that nfs_increment_open_seqid() will | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | * have unhashed the old state_owner for us, and that we can | 
|  | 2964 | * therefore safely retry using a new one. We should still warn | 
|  | 2965 | * the user though... | 
|  | 2966 | */ | 
|  | 2967 | if (status == -NFS4ERR_BAD_SEQID) { | 
| Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2968 | pr_warn_ratelimited("NFS: v4 server %s " | 
| Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2969 | " returned a bad sequence-id error!\n", | 
|  | 2970 | NFS_SERVER(dir)->nfs_client->cl_hostname); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | exception.retry = 1; | 
|  | 2972 | continue; | 
|  | 2973 | } | 
| Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2974 | /* | 
|  | 2975 | * BAD_STATEID on OPEN means that the server cancelled our | 
|  | 2976 | * state before it received the OPEN_CONFIRM. | 
|  | 2977 | * Recover by retrying the request as per the discussion | 
|  | 2978 | * on Page 181 of RFC3530. | 
|  | 2979 | */ | 
|  | 2980 | if (status == -NFS4ERR_BAD_STATEID) { | 
|  | 2981 | exception.retry = 1; | 
|  | 2982 | continue; | 
|  | 2983 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2984 | if (status == -EAGAIN) { | 
|  | 2985 | /* We must have found a delegation */ | 
|  | 2986 | exception.retry = 1; | 
|  | 2987 | continue; | 
|  | 2988 | } | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2989 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) | 
|  | 2990 | continue; | 
|  | 2991 | res = ERR_PTR(nfs4_handle_exception(server, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | status, &exception)); | 
|  | 2993 | } while (exception.retry); | 
|  | 2994 | return res; | 
|  | 2995 | } | 
|  | 2996 |  | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2997 | static int _nfs4_do_setattr(struct inode *inode, | 
|  | 2998 | struct nfs_setattrargs *arg, | 
|  | 2999 | struct nfs_setattrres *res, | 
|  | 3000 | struct rpc_cred *cred, | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3001 | struct nfs_open_context *ctx) | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3002 | { | 
|  | 3003 | struct nfs_server *server = NFS_SERVER(inode); | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3004 | struct rpc_message msg = { | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3005 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETATTR], | 
|  | 3006 | .rpc_argp	= arg, | 
|  | 3007 | .rpc_resp	= res, | 
|  | 3008 | .rpc_cred	= cred, | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3009 | }; | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3010 | struct rpc_cred *delegation_cred = NULL; | 
|  | 3011 | unsigned long timestamp = jiffies; | 
|  | 3012 | fmode_t fmode; | 
|  | 3013 | bool truncate; | 
|  | 3014 | int status; | 
|  | 3015 |  | 
|  | 3016 | nfs_fattr_init(res->fattr); | 
|  | 3017 |  | 
|  | 3018 | /* Servers should only apply open mode checks for file size changes */ | 
|  | 3019 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; | 
|  | 3020 | fmode = truncate ? FMODE_WRITE : FMODE_READ; | 
|  | 3021 |  | 
|  | 3022 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { | 
|  | 3023 | /* Use that stateid */ | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3024 | } else if (truncate && ctx != NULL) { | 
| NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3025 | struct nfs_lock_context *l_ctx; | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3026 | if (!nfs4_valid_open_stateid(ctx->state)) | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3027 | return -EBADF; | 
| NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3028 | l_ctx = nfs_get_lock_context(ctx); | 
|  | 3029 | if (IS_ERR(l_ctx)) | 
|  | 3030 | return PTR_ERR(l_ctx); | 
| NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3031 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, | 
|  | 3032 | &arg->stateid, &delegation_cred); | 
|  | 3033 | nfs_put_lock_context(l_ctx); | 
|  | 3034 | if (status == -EIO) | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3035 | return -EBADF; | 
|  | 3036 | } else | 
|  | 3037 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); | 
|  | 3038 | if (delegation_cred) | 
|  | 3039 | msg.rpc_cred = delegation_cred; | 
|  | 3040 |  | 
|  | 3041 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); | 
|  | 3042 |  | 
|  | 3043 | put_rpccred(delegation_cred); | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3044 | if (status == 0 && ctx != NULL) | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3045 | renew_lease(server, timestamp); | 
|  | 3046 | trace_nfs4_setattr(inode, &arg->stateid, status); | 
|  | 3047 | return status; | 
|  | 3048 | } | 
|  | 3049 |  | 
|  | 3050 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
|  | 3051 | struct nfs_fattr *fattr, struct iattr *sattr, | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3052 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3053 | struct nfs4_label *olabel) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | { | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3055 | struct nfs_server *server = NFS_SERVER(inode); | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3056 | struct nfs4_state *state = ctx ? ctx->state : NULL; | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3057 | struct nfs_setattrargs	arg = { | 
|  | 3058 | .fh		= NFS_FH(inode), | 
|  | 3059 | .iap		= sattr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | .server		= server, | 
|  | 3061 | .bitmask = server->attr_bitmask, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3062 | .label		= ilabel, | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3063 | }; | 
|  | 3064 | struct nfs_setattrres  res = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | .fattr		= fattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3066 | .label		= olabel, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | .server		= server, | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3068 | }; | 
| Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3069 | struct nfs4_exception exception = { | 
|  | 3070 | .state = state, | 
|  | 3071 | .inode = inode, | 
|  | 3072 | .stateid = &arg.stateid, | 
|  | 3073 | }; | 
|  | 3074 | int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3076 | arg.bitmask = nfs4_bitmask(server, ilabel); | 
|  | 3077 | if (ilabel) | 
|  | 3078 | arg.bitmask = nfs4_bitmask(server, olabel); | 
|  | 3079 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | do { | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3081 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); | 
| Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3082 | switch (err) { | 
|  | 3083 | case -NFS4ERR_OPENMODE: | 
| Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3084 | if (!(sattr->ia_valid & ATTR_SIZE)) { | 
|  | 3085 | pr_warn_once("NFSv4: server %s is incorrectly " | 
|  | 3086 | "applying open mode checks to " | 
|  | 3087 | "a SETATTR that is not " | 
|  | 3088 | "changing file size.\n", | 
|  | 3089 | server->nfs_client->cl_hostname); | 
|  | 3090 | } | 
| Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3091 | if (state && !(state->state & FMODE_WRITE)) { | 
|  | 3092 | err = -EBADF; | 
|  | 3093 | if (sattr->ia_valid & ATTR_OPEN) | 
|  | 3094 | err = -EACCES; | 
|  | 3095 | goto out; | 
|  | 3096 | } | 
|  | 3097 | } | 
|  | 3098 | err = nfs4_handle_exception(server, err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | } while (exception.retry); | 
| Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3100 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | return err; | 
|  | 3102 | } | 
|  | 3103 |  | 
| Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3104 | static bool | 
|  | 3105 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) | 
|  | 3106 | { | 
|  | 3107 | if (inode == NULL || !nfs_have_layout(inode)) | 
|  | 3108 | return false; | 
|  | 3109 |  | 
|  | 3110 | return pnfs_wait_on_layoutreturn(inode, task); | 
|  | 3111 | } | 
|  | 3112 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | struct nfs4_closedata { | 
|  | 3114 | struct inode *inode; | 
|  | 3115 | struct nfs4_state *state; | 
|  | 3116 | struct nfs_closeargs arg; | 
|  | 3117 | struct nfs_closeres res; | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3118 | struct { | 
|  | 3119 | struct nfs4_layoutreturn_args arg; | 
|  | 3120 | struct nfs4_layoutreturn_res res; | 
| Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3121 | struct nfs4_xdr_opaque_data ld_private; | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3122 | u32 roc_barrier; | 
|  | 3123 | bool roc; | 
|  | 3124 | } lr; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3125 | struct nfs_fattr fattr; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3126 | unsigned long timestamp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | }; | 
|  | 3128 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3129 | static void nfs4_free_closedata(void *data) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3130 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3131 | struct nfs4_closedata *calldata = data; | 
|  | 3132 | struct nfs4_state_owner *sp = calldata->state->owner; | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3133 | struct super_block *sb = calldata->state->inode->i_sb; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3134 |  | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3135 | if (calldata->lr.roc) | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3136 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, | 
|  | 3137 | calldata->res.lr_ret); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3138 | nfs4_put_open_state(calldata->state); | 
|  | 3139 | nfs_free_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3140 | nfs4_put_state_owner(sp); | 
| Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3141 | nfs_sb_deactive(sb); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3142 | kfree(calldata); | 
|  | 3143 | } | 
|  | 3144 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3145 | static void nfs4_close_done(struct rpc_task *task, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3147 | struct nfs4_closedata *calldata = data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | struct nfs4_state *state = calldata->state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | struct nfs_server *server = NFS_SERVER(calldata->inode); | 
| Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3150 | nfs4_stateid *res_stateid = NULL; | 
| Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3151 | struct nfs4_exception exception = { | 
|  | 3152 | .state = state, | 
|  | 3153 | .inode = calldata->inode, | 
|  | 3154 | .stateid = &calldata->arg.stateid, | 
|  | 3155 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 |  | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3157 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3158 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) | 
|  | 3159 | return; | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3160 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3161 |  | 
|  | 3162 | /* Handle Layoutreturn errors */ | 
|  | 3163 | if (calldata->arg.lr_args && task->tk_status != 0) { | 
|  | 3164 | switch (calldata->res.lr_ret) { | 
|  | 3165 | default: | 
|  | 3166 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; | 
|  | 3167 | break; | 
|  | 3168 | case 0: | 
|  | 3169 | calldata->arg.lr_args = NULL; | 
|  | 3170 | calldata->res.lr_res = NULL; | 
|  | 3171 | break; | 
| Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3172 | case -NFS4ERR_OLD_STATEID: | 
|  | 3173 | if (nfs4_refresh_layout_stateid(&calldata->arg.lr_args->stateid, | 
| Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3174 | calldata->inode)) | 
|  | 3175 | goto lr_restart; | 
| Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3176 | /* Fallthrough */ | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3177 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 3178 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 3179 | case -NFS4ERR_EXPIRED: | 
|  | 3180 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3181 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: | 
|  | 3182 | case -NFS4ERR_WRONG_CRED: | 
|  | 3183 | calldata->arg.lr_args = NULL; | 
|  | 3184 | calldata->res.lr_res = NULL; | 
| Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3185 | goto lr_restart; | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3186 | } | 
|  | 3187 | } | 
|  | 3188 |  | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3189 | /* 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] | 3190 | * the state_owner. we keep this around to process errors | 
|  | 3191 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | switch (task->tk_status) { | 
|  | 3193 | case 0: | 
| Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3194 | res_stateid = &calldata->res.stateid; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3195 | renew_lease(server, calldata->timestamp); | 
| Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3196 | break; | 
| Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3197 | case -NFS4ERR_ACCESS: | 
|  | 3198 | if (calldata->arg.bitmask != NULL) { | 
|  | 3199 | calldata->arg.bitmask = NULL; | 
|  | 3200 | calldata->res.fattr = NULL; | 
| Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3201 | goto out_restart; | 
| Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3202 |  | 
|  | 3203 | } | 
|  | 3204 | break; | 
| Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3205 | case -NFS4ERR_OLD_STATEID: | 
|  | 3206 | /* Did we race with OPEN? */ | 
|  | 3207 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, | 
| Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3208 | state)) | 
|  | 3209 | goto out_restart; | 
| Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3210 | goto out_release; | 
| Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3211 | case -NFS4ERR_ADMIN_REVOKED: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3213 | case -NFS4ERR_EXPIRED: | 
|  | 3214 | nfs4_free_revoked_stateid(server, | 
|  | 3215 | &calldata->arg.stateid, | 
|  | 3216 | task->tk_msg.rpc_cred); | 
| Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3217 | /* Fallthrough */ | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3218 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3219 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | default: | 
| Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3221 | task->tk_status = nfs4_async_handle_exception(task, | 
|  | 3222 | server, task->tk_status, &exception); | 
|  | 3223 | if (exception.retry) | 
| Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3224 | goto out_restart; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | } | 
| Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3226 | nfs_clear_open_stateid(state, &calldata->arg.stateid, | 
|  | 3227 | res_stateid, calldata->arg.fmode); | 
| Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3228 | out_release: | 
| Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3229 | task->tk_status = 0; | 
| Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3230 | nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3231 | nfs_refresh_inode(calldata->inode, &calldata->fattr); | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3232 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); | 
| Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3233 | return; | 
|  | 3234 | lr_restart: | 
|  | 3235 | calldata->res.lr_ret = 0; | 
|  | 3236 | out_restart: | 
|  | 3237 | task->tk_status = 0; | 
|  | 3238 | rpc_restart_call_prepare(task); | 
|  | 3239 | goto out_release; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | } | 
|  | 3241 |  | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3242 | static void nfs4_close_prepare(struct rpc_task *task, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3244 | struct nfs4_closedata *calldata = data; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3245 | struct nfs4_state *state = calldata->state; | 
| Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3246 | struct inode *inode = calldata->inode; | 
| Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3247 | bool is_rdonly, is_wronly, is_rdwr; | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3248 | int call_close = 0; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3249 |  | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3250 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3251 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3252 | goto out_wait; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3253 |  | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3254 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; | 
| Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3255 | spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3256 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); | 
|  | 3257 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 3258 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3259 | /* Calculate the change in open mode */ | 
| Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3260 | calldata->arg.fmode = 0; | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3261 | if (state->n_rdwr == 0) { | 
| Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3262 | if (state->n_rdonly == 0) | 
|  | 3263 | call_close |= is_rdonly; | 
|  | 3264 | else if (is_rdonly) | 
|  | 3265 | calldata->arg.fmode |= FMODE_READ; | 
|  | 3266 | if (state->n_wronly == 0) | 
|  | 3267 | call_close |= is_wronly; | 
|  | 3268 | else if (is_wronly) | 
|  | 3269 | calldata->arg.fmode |= FMODE_WRITE; | 
| Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3270 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) | 
|  | 3271 | call_close |= is_rdwr; | 
| Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3272 | } else if (is_rdwr) | 
|  | 3273 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; | 
|  | 3274 |  | 
| Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3275 | if (!nfs4_valid_open_stateid(state) || | 
| Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3276 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3277 | call_close = 0; | 
| Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3278 | spin_unlock(&state->owner->so_lock); | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3279 |  | 
|  | 3280 | if (!call_close) { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3281 | /* Note: exit _without_ calling nfs4_close_done */ | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3282 | goto out_no_action; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3283 | } | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3284 |  | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3285 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { | 
| Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3286 | nfs_release_seqid(calldata->arg.seqid); | 
|  | 3287 | goto out_wait; | 
|  | 3288 | } | 
|  | 3289 |  | 
| Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3290 | if (calldata->arg.fmode == 0) | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3291 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; | 
| Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3292 |  | 
| Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3293 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { | 
| Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3294 | /* Close-to-open cache consistency revalidation */ | 
|  | 3295 | if (!nfs4_have_delegation(inode, FMODE_READ)) | 
|  | 3296 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; | 
|  | 3297 | else | 
|  | 3298 | calldata->arg.bitmask = NULL; | 
|  | 3299 | } | 
| Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3300 |  | 
| Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3301 | calldata->arg.share_access = | 
|  | 3302 | nfs4_map_atomic_open_share(NFS_SERVER(inode), | 
|  | 3303 | calldata->arg.fmode, 0); | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3304 |  | 
| Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3305 | if (calldata->res.fattr == NULL) | 
|  | 3306 | calldata->arg.bitmask = NULL; | 
|  | 3307 | else if (calldata->arg.bitmask == NULL) | 
|  | 3308 | calldata->res.fattr = NULL; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3309 | calldata->timestamp = jiffies; | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3310 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, | 
| Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3311 | &calldata->arg.seq_args, | 
|  | 3312 | &calldata->res.seq_res, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3313 | task) != 0) | 
|  | 3314 | nfs_release_seqid(calldata->arg.seqid); | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3315 | dprintk("%s: done!\n", __func__); | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3316 | return; | 
|  | 3317 | out_no_action: | 
|  | 3318 | task->tk_action = NULL; | 
|  | 3319 | out_wait: | 
|  | 3320 | nfs4_sequence_done(task, &calldata->res.seq_res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | } | 
|  | 3322 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3323 | static const struct rpc_call_ops nfs4_close_ops = { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3324 | .rpc_call_prepare = nfs4_close_prepare, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3325 | .rpc_call_done = nfs4_close_done, | 
|  | 3326 | .rpc_release = nfs4_free_closedata, | 
|  | 3327 | }; | 
|  | 3328 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | /* | 
|  | 3330 | * It is possible for data to be read/written from a mem-mapped file | 
|  | 3331 | * after the sys_close call (which hits the vfs layer as a flush). | 
|  | 3332 | * This means that we can't safely call nfsv4 close on a file until | 
|  | 3333 | * the inode is cleared. This in turn means that we are not good | 
|  | 3334 | * NFSv4 citizens - we do not indicate to the server to update the file's | 
|  | 3335 | * share state even when we are done with one of the three share | 
|  | 3336 | * stateid's in the inode. | 
|  | 3337 | * | 
|  | 3338 | * NOTE: Caller must be holding the sp->so_owner semaphore! | 
|  | 3339 | */ | 
| Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3340 | 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] | 3341 | { | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3342 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3343 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | struct nfs4_closedata *calldata; | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3345 | struct nfs4_state_owner *sp = state->owner; | 
|  | 3346 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3347 | struct rpc_message msg = { | 
|  | 3348 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], | 
|  | 3349 | .rpc_cred = state->owner->so_cred, | 
|  | 3350 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3351 | struct rpc_task_setup task_setup_data = { | 
|  | 3352 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3353 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3354 | .callback_ops = &nfs4_close_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3355 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3356 | .flags = RPC_TASK_ASYNC, | 
|  | 3357 | }; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3358 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 |  | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3360 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, | 
|  | 3361 | &task_setup_data.rpc_client, &msg); | 
|  | 3362 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3363 | calldata = kzalloc(sizeof(*calldata), gfp_mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | if (calldata == NULL) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3365 | goto out; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3366 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3367 | calldata->inode = state->inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | calldata->state = state; | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3369 | calldata->arg.fh = NFS_FH(state->inode); | 
| Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3370 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) | 
|  | 3371 | goto out_free_calldata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | /* Serialization for the sequence id */ | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3373 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; | 
|  | 3374 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); | 
| Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3375 | if (IS_ERR(calldata->arg.seqid)) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3376 | goto out_free_calldata; | 
| Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3377 | nfs_fattr_init(&calldata->fattr); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3378 | calldata->arg.fmode = 0; | 
| Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3379 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3380 | calldata->res.fattr = &calldata->fattr; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3381 | calldata->res.seqid = calldata->arg.seqid; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3382 | calldata->res.server = server; | 
| Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3383 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3384 | calldata->lr.roc = pnfs_roc(state->inode, | 
|  | 3385 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); | 
|  | 3386 | if (calldata->lr.roc) { | 
|  | 3387 | calldata->arg.lr_args = &calldata->lr.arg; | 
|  | 3388 | calldata->res.lr_res = &calldata->lr.res; | 
|  | 3389 | } | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3390 | nfs_sb_active(calldata->inode->i_sb); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3391 |  | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3392 | msg.rpc_argp = &calldata->arg; | 
|  | 3393 | msg.rpc_resp = &calldata->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3394 | task_setup_data.callback_data = calldata; | 
|  | 3395 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3396 | if (IS_ERR(task)) | 
|  | 3397 | return PTR_ERR(task); | 
| Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3398 | status = 0; | 
|  | 3399 | if (wait) | 
|  | 3400 | status = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3401 | rpc_put_task(task); | 
| Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3402 | return status; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3403 | out_free_calldata: | 
|  | 3404 | kfree(calldata); | 
|  | 3405 | out: | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3406 | nfs4_put_open_state(state); | 
|  | 3407 | nfs4_put_state_owner(sp); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3408 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | } | 
|  | 3410 |  | 
| Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3411 | static struct inode * | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3412 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, | 
|  | 3413 | int open_flags, struct iattr *attr, int *opened) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | struct nfs4_state *state; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3416 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; | 
|  | 3417 |  | 
|  | 3418 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 |  | 
| Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3420 | /* Protect against concurrent sillydeletes */ | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3421 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3422 |  | 
|  | 3423 | nfs4_label_release_security(label); | 
|  | 3424 |  | 
| Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3425 | if (IS_ERR(state)) | 
|  | 3426 | return ERR_CAST(state); | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3427 | return state->inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | } | 
|  | 3429 |  | 
| Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3430 | 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] | 3431 | { | 
|  | 3432 | if (ctx->state == NULL) | 
|  | 3433 | return; | 
|  | 3434 | if (is_sync) | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3435 | nfs4_close_sync(ctx->state, ctx->mode); | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3436 | else | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3437 | nfs4_close_state(ctx->state, ctx->mode); | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3438 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 |  | 
| Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3440 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) | 
|  | 3441 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3442 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) | 
| Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3443 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 
|  | 3445 | { | 
| Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3446 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; | 
| Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3447 | struct nfs4_server_caps_arg args = { | 
|  | 3448 | .fhandle = fhandle, | 
| Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3449 | .bitmask = bitmask, | 
| Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3450 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | struct nfs4_server_caps_res res = {}; | 
|  | 3452 | struct rpc_message msg = { | 
|  | 3453 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], | 
| Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3454 | .rpc_argp = &args, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | .rpc_resp = &res, | 
|  | 3456 | }; | 
|  | 3457 | int status; | 
| Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3458 | int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 |  | 
| Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3460 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | | 
|  | 3461 | FATTR4_WORD0_FH_EXPIRE_TYPE | | 
|  | 3462 | FATTR4_WORD0_LINK_SUPPORT | | 
|  | 3463 | FATTR4_WORD0_SYMLINK_SUPPORT | | 
|  | 3464 | FATTR4_WORD0_ACLSUPPORT; | 
|  | 3465 | if (minorversion) | 
|  | 3466 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; | 
|  | 3467 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3468 | 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] | 3469 | if (status == 0) { | 
| Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3470 | /* Sanity check the server answers */ | 
| Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3471 | switch (minorversion) { | 
| Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3472 | case 0: | 
|  | 3473 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; | 
|  | 3474 | res.attr_bitmask[2] = 0; | 
|  | 3475 | break; | 
|  | 3476 | case 1: | 
|  | 3477 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; | 
|  | 3478 | break; | 
|  | 3479 | case 2: | 
|  | 3480 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; | 
|  | 3481 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); | 
| Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3483 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| | 
|  | 3484 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| | 
|  | 3485 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| | 
|  | 3486 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| | 
| Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3487 | NFS_CAP_CTIME|NFS_CAP_MTIME| | 
|  | 3488 | NFS_CAP_SECURITY_LABEL); | 
| Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3489 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && | 
|  | 3490 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | server->caps |= NFS_CAP_ACLS; | 
|  | 3492 | if (res.has_links != 0) | 
|  | 3493 | server->caps |= NFS_CAP_HARDLINKS; | 
|  | 3494 | if (res.has_symlinks != 0) | 
|  | 3495 | server->caps |= NFS_CAP_SYMLINKS; | 
| Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3496 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) | 
|  | 3497 | server->caps |= NFS_CAP_FILEID; | 
|  | 3498 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) | 
|  | 3499 | server->caps |= NFS_CAP_MODE; | 
|  | 3500 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) | 
|  | 3501 | server->caps |= NFS_CAP_NLINK; | 
|  | 3502 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) | 
|  | 3503 | server->caps |= NFS_CAP_OWNER; | 
|  | 3504 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) | 
|  | 3505 | server->caps |= NFS_CAP_OWNER_GROUP; | 
|  | 3506 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) | 
|  | 3507 | server->caps |= NFS_CAP_ATIME; | 
|  | 3508 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) | 
|  | 3509 | server->caps |= NFS_CAP_CTIME; | 
|  | 3510 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) | 
|  | 3511 | server->caps |= NFS_CAP_MTIME; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3512 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 3513 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) | 
|  | 3514 | server->caps |= NFS_CAP_SECURITY_LABEL; | 
|  | 3515 | #endif | 
|  | 3516 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, | 
|  | 3517 | sizeof(server->attr_bitmask)); | 
| Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3518 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; | 
| Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3519 |  | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3520 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); | 
|  | 3521 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; | 
|  | 3522 | 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] | 3523 | server->cache_consistency_bitmask[2] = 0; | 
| Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3524 |  | 
|  | 3525 | /* Avoid a regression due to buggy server */ | 
|  | 3526 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) | 
|  | 3527 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; | 
| Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3528 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, | 
|  | 3529 | sizeof(server->exclcreat_bitmask)); | 
| Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3530 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | server->acl_bitmask = res.acl_bitmask; | 
| Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3532 | server->fh_expire_type = res.fh_expire_type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | } | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3534 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | return status; | 
|  | 3536 | } | 
|  | 3537 |  | 
| Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3538 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | { | 
|  | 3540 | struct nfs4_exception exception = { }; | 
|  | 3541 | int err; | 
|  | 3542 | do { | 
|  | 3543 | err = nfs4_handle_exception(server, | 
|  | 3544 | _nfs4_server_capabilities(server, fhandle), | 
|  | 3545 | &exception); | 
|  | 3546 | } while (exception.retry); | 
|  | 3547 | return err; | 
|  | 3548 | } | 
|  | 3549 |  | 
|  | 3550 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3551 | struct nfs_fsinfo *info) | 
|  | 3552 | { | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3553 | u32 bitmask[3]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | struct nfs4_lookup_root_arg args = { | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3555 | .bitmask = bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | }; | 
|  | 3557 | struct nfs4_lookup_res res = { | 
|  | 3558 | .server = server, | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3559 | .fattr = info->fattr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | .fh = fhandle, | 
|  | 3561 | }; | 
|  | 3562 | struct rpc_message msg = { | 
|  | 3563 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], | 
|  | 3564 | .rpc_argp = &args, | 
|  | 3565 | .rpc_resp = &res, | 
|  | 3566 | }; | 
| Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3567 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3568 | bitmask[0] = nfs4_fattr_bitmap[0]; | 
|  | 3569 | bitmask[1] = nfs4_fattr_bitmap[1]; | 
|  | 3570 | /* | 
|  | 3571 | * Process the label in the upcoming getfattr | 
|  | 3572 | */ | 
|  | 3573 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; | 
|  | 3574 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3575 | nfs_fattr_init(info->fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3576 | 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] | 3577 | } | 
|  | 3578 |  | 
|  | 3579 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3580 | struct nfs_fsinfo *info) | 
|  | 3581 | { | 
|  | 3582 | struct nfs4_exception exception = { }; | 
|  | 3583 | int err; | 
|  | 3584 | do { | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3585 | err = _nfs4_lookup_root(server, fhandle, info); | 
| Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3586 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3587 | switch (err) { | 
|  | 3588 | case 0: | 
|  | 3589 | case -NFS4ERR_WRONGSEC: | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3590 | goto out; | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3591 | default: | 
|  | 3592 | err = nfs4_handle_exception(server, err, &exception); | 
|  | 3593 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | } while (exception.retry); | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3595 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | return err; | 
|  | 3597 | } | 
|  | 3598 |  | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3599 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3600 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) | 
|  | 3601 | { | 
| Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3602 | struct rpc_auth_create_args auth_args = { | 
|  | 3603 | .pseudoflavor = flavor, | 
|  | 3604 | }; | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3605 | struct rpc_auth *auth; | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3606 |  | 
| Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3607 | auth = rpcauth_create(&auth_args, server->client); | 
| Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3608 | if (IS_ERR(auth)) | 
|  | 3609 | return -EACCES; | 
|  | 3610 | return nfs4_lookup_root(server, fhandle, info); | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3611 | } | 
|  | 3612 |  | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3613 | /* | 
|  | 3614 | * Retry pseudoroot lookup with various security flavors.  We do this when: | 
|  | 3615 | * | 
|  | 3616 | *   NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC | 
|  | 3617 | *   NFSv4.1: the server does not support the SECINFO_NO_NAME operation | 
|  | 3618 | * | 
|  | 3619 | * Returns zero on success, or a negative NFS4ERR value, or a | 
|  | 3620 | * negative errno value. | 
|  | 3621 | */ | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3622 | 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] | 3623 | struct nfs_fsinfo *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | { | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3625 | /* Per 3530bis 15.33.5 */ | 
|  | 3626 | static const rpc_authflavor_t flav_array[] = { | 
|  | 3627 | RPC_AUTH_GSS_KRB5P, | 
|  | 3628 | RPC_AUTH_GSS_KRB5I, | 
|  | 3629 | RPC_AUTH_GSS_KRB5, | 
| Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3630 | RPC_AUTH_UNIX,			/* courtesy */ | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3631 | RPC_AUTH_NULL, | 
|  | 3632 | }; | 
|  | 3633 | int status = -EPERM; | 
|  | 3634 | size_t i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 |  | 
| Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3636 | if (server->auth_info.flavor_len > 0) { | 
|  | 3637 | /* try each flavor specified by user */ | 
|  | 3638 | for (i = 0; i < server->auth_info.flavor_len; i++) { | 
|  | 3639 | status = nfs4_lookup_root_sec(server, fhandle, info, | 
|  | 3640 | server->auth_info.flavors[i]); | 
|  | 3641 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) | 
|  | 3642 | continue; | 
|  | 3643 | break; | 
|  | 3644 | } | 
|  | 3645 | } else { | 
|  | 3646 | /* no flavors specified by user, try default list */ | 
|  | 3647 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { | 
|  | 3648 | status = nfs4_lookup_root_sec(server, fhandle, info, | 
|  | 3649 | flav_array[i]); | 
|  | 3650 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) | 
|  | 3651 | continue; | 
|  | 3652 | break; | 
|  | 3653 | } | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3654 | } | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3655 |  | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3656 | /* | 
|  | 3657 | * -EACCESS could mean that the user doesn't have correct permissions | 
|  | 3658 | * to access the mount.  It could also mean that we tried to mount | 
|  | 3659 | * with a gss auth flavor, but rpc.gssd isn't running.  Either way, | 
|  | 3660 | * existing mount programs don't handle -EACCES very well so it should | 
|  | 3661 | * be mapped to -EPERM instead. | 
|  | 3662 | */ | 
|  | 3663 | if (status == -EACCES) | 
|  | 3664 | status = -EPERM; | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3665 | return status; | 
|  | 3666 | } | 
|  | 3667 |  | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3668 | /** | 
|  | 3669 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot | 
|  | 3670 | * @server: initialized nfs_server handle | 
|  | 3671 | * @fhandle: we fill in the pseudo-fs root file handle | 
|  | 3672 | * @info: we fill in an FSINFO struct | 
| Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3673 | * @auth_probe: probe the auth flavours | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3674 | * | 
|  | 3675 | * Returns zero on success, or a negative errno. | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3676 | */ | 
| Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3677 | 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] | 3678 | struct nfs_fsinfo *info, | 
|  | 3679 | bool auth_probe) | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3680 | { | 
| Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3681 | int status = 0; | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3682 |  | 
| Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3683 | if (!auth_probe) | 
| Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3684 | status = nfs4_lookup_root(server, fhandle, info); | 
| Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3685 |  | 
|  | 3686 | if (auth_probe || status == NFS4ERR_WRONGSEC) | 
| Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3687 | status = server->nfs_client->cl_mvops->find_root_sec(server, | 
|  | 3688 | fhandle, info); | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3689 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | if (status == 0) | 
|  | 3691 | status = nfs4_server_capabilities(server, fhandle); | 
|  | 3692 | if (status == 0) | 
|  | 3693 | status = nfs4_do_fsinfo(server, fhandle, info); | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3694 |  | 
| Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3695 | return nfs4_map_errors(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | } | 
|  | 3697 |  | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3698 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, | 
|  | 3699 | struct nfs_fsinfo *info) | 
|  | 3700 | { | 
|  | 3701 | int error; | 
|  | 3702 | struct nfs_fattr *fattr = info->fattr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3703 | struct nfs4_label *label = NULL; | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3704 |  | 
|  | 3705 | error = nfs4_server_capabilities(server, mntfh); | 
|  | 3706 | if (error < 0) { | 
|  | 3707 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); | 
|  | 3708 | return error; | 
|  | 3709 | } | 
|  | 3710 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3711 | label = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 3712 | if (IS_ERR(label)) | 
|  | 3713 | return PTR_ERR(label); | 
|  | 3714 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3715 | error = nfs4_proc_getattr(server, mntfh, fattr, label); | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3716 | if (error < 0) { | 
|  | 3717 | dprintk("nfs4_get_root: getattr error = %d\n", -error); | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3718 | goto err_free_label; | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3719 | } | 
|  | 3720 |  | 
|  | 3721 | if (fattr->valid & NFS_ATTR_FATTR_FSID && | 
|  | 3722 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) | 
|  | 3723 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); | 
|  | 3724 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3725 | err_free_label: | 
|  | 3726 | nfs4_label_free(label); | 
|  | 3727 |  | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3728 | return error; | 
|  | 3729 | } | 
|  | 3730 |  | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3731 | /* | 
|  | 3732 | * Get locations and (maybe) other attributes of a referral. | 
|  | 3733 | * Note that we'll actually follow the referral later when | 
|  | 3734 | * we detect fsid mismatch in inode revalidation | 
|  | 3735 | */ | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3736 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, | 
|  | 3737 | const struct qstr *name, struct nfs_fattr *fattr, | 
|  | 3738 | struct nfs_fh *fhandle) | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3739 | { | 
|  | 3740 | int status = -ENOMEM; | 
|  | 3741 | struct page *page = NULL; | 
|  | 3742 | struct nfs4_fs_locations *locations = NULL; | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3743 |  | 
|  | 3744 | page = alloc_page(GFP_KERNEL); | 
|  | 3745 | if (page == NULL) | 
|  | 3746 | goto out; | 
|  | 3747 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); | 
|  | 3748 | if (locations == NULL) | 
|  | 3749 | goto out; | 
|  | 3750 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3751 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3752 | if (status != 0) | 
|  | 3753 | goto out; | 
| Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3754 |  | 
|  | 3755 | /* | 
|  | 3756 | * If the fsid didn't change, this is a migration event, not a | 
|  | 3757 | * referral.  Cause us to drop into the exception handler, which | 
|  | 3758 | * will kick off migration recovery. | 
|  | 3759 | */ | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3760 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3761 | dprintk("%s: server did not return a different fsid for" | 
|  | 3762 | " a referral at %s\n", __func__, name->name); | 
| Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3763 | status = -NFS4ERR_MOVED; | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3764 | goto out; | 
|  | 3765 | } | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3766 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ | 
|  | 3767 | nfs_fixup_referral_attributes(&locations->fattr); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3768 |  | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3769 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3770 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3771 | memset(fhandle, 0, sizeof(struct nfs_fh)); | 
|  | 3772 | out: | 
|  | 3773 | if (page) | 
|  | 3774 | __free_page(page); | 
| Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3775 | kfree(locations); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3776 | return status; | 
|  | 3777 | } | 
|  | 3778 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3779 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3780 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | { | 
|  | 3782 | struct nfs4_getattr_arg args = { | 
|  | 3783 | .fh = fhandle, | 
|  | 3784 | .bitmask = server->attr_bitmask, | 
|  | 3785 | }; | 
|  | 3786 | struct nfs4_getattr_res res = { | 
|  | 3787 | .fattr = fattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3788 | .label = label, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | .server = server, | 
|  | 3790 | }; | 
|  | 3791 | struct rpc_message msg = { | 
|  | 3792 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], | 
|  | 3793 | .rpc_argp = &args, | 
|  | 3794 | .rpc_resp = &res, | 
|  | 3795 | }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3796 |  | 
|  | 3797 | args.bitmask = nfs4_bitmask(server, label); | 
|  | 3798 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3799 | nfs_fattr_init(fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3800 | 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] | 3801 | } | 
|  | 3802 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3803 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3804 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | { | 
|  | 3806 | struct nfs4_exception exception = { }; | 
|  | 3807 | int err; | 
|  | 3808 | do { | 
| Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3809 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); | 
|  | 3810 | trace_nfs4_getattr(server, fhandle, fattr, err); | 
|  | 3811 | err = nfs4_handle_exception(server, err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | &exception); | 
|  | 3813 | } while (exception.retry); | 
|  | 3814 | return err; | 
|  | 3815 | } | 
|  | 3816 |  | 
|  | 3817 | /* | 
|  | 3818 | * The file is not closed if it is opened due to the a request to change | 
|  | 3819 | * the size of the file. The open call will not be needed once the | 
|  | 3820 | * VFS layer lookup-intents are implemented. | 
|  | 3821 | * | 
|  | 3822 | * Close is called when the inode is destroyed. | 
|  | 3823 | * If we haven't opened the file for O_WRONLY, we | 
|  | 3824 | * need to in the size_change case to obtain a stateid. | 
|  | 3825 | * | 
|  | 3826 | * Got race? | 
|  | 3827 | * Because OPEN is always done by name in nfsv4, it is | 
|  | 3828 | * possible that we opened a different file by the same | 
|  | 3829 | * name.  We can recognize this race condition, but we | 
|  | 3830 | * can't do anything about it besides returning an error. | 
|  | 3831 | * | 
|  | 3832 | * This will be fixed with VFS changes (lookup-intent). | 
|  | 3833 | */ | 
|  | 3834 | static int | 
|  | 3835 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, | 
|  | 3836 | struct iattr *sattr) | 
|  | 3837 | { | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3838 | struct inode *inode = d_inode(dentry); | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3839 | struct rpc_cred *cred = NULL; | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3840 | struct nfs_open_context *ctx = NULL; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3841 | struct nfs4_label *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | int status; | 
|  | 3843 |  | 
| Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3844 | if (pnfs_ld_layoutret_on_setattr(inode) && | 
|  | 3845 | sattr->ia_valid & ATTR_SIZE && | 
|  | 3846 | sattr->ia_size < i_size_read(inode)) | 
| Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3847 | pnfs_commit_and_return_layout(inode); | 
| Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3848 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3849 | nfs_fattr_init(fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 |  | 
| Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3851 | /* Deal with open(O_TRUNC) */ | 
|  | 3852 | if (sattr->ia_valid & ATTR_OPEN) | 
| Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3853 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); | 
| Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3854 |  | 
|  | 3855 | /* Optimization: if the end result is no change, don't RPC */ | 
| Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3856 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) | 
| Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3857 | return 0; | 
|  | 3858 |  | 
| Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3859 | /* Search for an existing open(O_WRITE) file */ | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3860 | if (sattr->ia_valid & ATTR_FILE) { | 
| Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3861 |  | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3862 | ctx = nfs_file_open_context(sattr->ia_file); | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3863 | if (ctx) | 
| Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3864 | cred = ctx->cred; | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3865 | } | 
|  | 3866 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3867 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); | 
|  | 3868 | if (IS_ERR(label)) | 
|  | 3869 | return PTR_ERR(label); | 
|  | 3870 |  | 
| NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3871 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3872 | if (status == 0) { | 
| Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3873 | nfs_setattr_update_inode(inode, sattr, fattr); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3874 | nfs_setsecurity(inode, fattr, label); | 
|  | 3875 | } | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3876 | nfs4_label_free(label); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | return status; | 
|  | 3878 | } | 
|  | 3879 |  | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3880 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, | 
|  | 3881 | const struct qstr *name, struct nfs_fh *fhandle, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3882 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3883 | { | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3884 | struct nfs_server *server = NFS_SERVER(dir); | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3885 | int		       status; | 
|  | 3886 | struct nfs4_lookup_arg args = { | 
|  | 3887 | .bitmask = server->attr_bitmask, | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3888 | .dir_fh = NFS_FH(dir), | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3889 | .name = name, | 
|  | 3890 | }; | 
|  | 3891 | struct nfs4_lookup_res res = { | 
|  | 3892 | .server = server, | 
|  | 3893 | .fattr = fattr, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3894 | .label = label, | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3895 | .fh = fhandle, | 
|  | 3896 | }; | 
|  | 3897 | struct rpc_message msg = { | 
|  | 3898 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], | 
|  | 3899 | .rpc_argp = &args, | 
|  | 3900 | .rpc_resp = &res, | 
|  | 3901 | }; | 
|  | 3902 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3903 | args.bitmask = nfs4_bitmask(server, label); | 
|  | 3904 |  | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3905 | nfs_fattr_init(fattr); | 
|  | 3906 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | dprintk("NFS call  lookup %s\n", name->name); | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3908 | 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] | 3909 | dprintk("NFS reply lookup: %d\n", status); | 
|  | 3910 | return status; | 
|  | 3911 | } | 
|  | 3912 |  | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3913 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3914 | { | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3915 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3916 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3917 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; | 
|  | 3918 | fattr->nlink = 2; | 
|  | 3919 | } | 
|  | 3920 |  | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3921 | 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] | 3922 | const struct qstr *name, struct nfs_fh *fhandle, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3923 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3924 | { | 
|  | 3925 | struct nfs4_exception exception = { }; | 
|  | 3926 | struct rpc_clnt *client = *clnt; | 
|  | 3927 | int err; | 
|  | 3928 | do { | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3929 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3930 | trace_nfs4_lookup(dir, name, err); | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3931 | switch (err) { | 
|  | 3932 | case -NFS4ERR_BADNAME: | 
|  | 3933 | err = -ENOENT; | 
|  | 3934 | goto out; | 
|  | 3935 | case -NFS4ERR_MOVED: | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3936 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); | 
| Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3937 | if (err == -NFS4ERR_MOVED) | 
|  | 3938 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3939 | goto out; | 
|  | 3940 | case -NFS4ERR_WRONGSEC: | 
|  | 3941 | err = -EPERM; | 
|  | 3942 | if (client != *clnt) | 
|  | 3943 | goto out; | 
| Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3944 | client = nfs4_negotiate_security(client, dir, name); | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3945 | if (IS_ERR(client)) | 
|  | 3946 | return PTR_ERR(client); | 
|  | 3947 |  | 
|  | 3948 | exception.retry = 1; | 
|  | 3949 | break; | 
|  | 3950 | default: | 
|  | 3951 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); | 
|  | 3952 | } | 
|  | 3953 | } while (exception.retry); | 
|  | 3954 |  | 
|  | 3955 | out: | 
|  | 3956 | if (err == 0) | 
|  | 3957 | *clnt = client; | 
|  | 3958 | else if (client != *clnt) | 
|  | 3959 | rpc_shutdown_client(client); | 
|  | 3960 |  | 
|  | 3961 | return err; | 
|  | 3962 | } | 
|  | 3963 |  | 
| Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3964 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3965 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, | 
|  | 3966 | struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | { | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3968 | int status; | 
|  | 3969 | struct rpc_clnt *client = NFS_CLIENT(dir); | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3970 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3971 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3972 | if (client != NFS_CLIENT(dir)) { | 
|  | 3973 | rpc_shutdown_client(client); | 
|  | 3974 | nfs_fixup_secinfo_attributes(fattr); | 
|  | 3975 | } | 
|  | 3976 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | } | 
|  | 3978 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3979 | struct rpc_clnt * | 
| Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3980 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3981 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 
|  | 3982 | { | 
| Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3983 | struct rpc_clnt *client = NFS_CLIENT(dir); | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3984 | int status; | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3985 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3986 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); | 
| Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3987 | if (status < 0) | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3988 | return ERR_PTR(status); | 
| Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3989 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3990 | } | 
|  | 3991 |  | 
| Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 3992 | static int _nfs4_proc_lookupp(struct inode *inode, | 
|  | 3993 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, | 
|  | 3994 | struct nfs4_label *label) | 
|  | 3995 | { | 
|  | 3996 | struct rpc_clnt *clnt = NFS_CLIENT(inode); | 
|  | 3997 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 3998 | int		       status; | 
|  | 3999 | struct nfs4_lookupp_arg args = { | 
|  | 4000 | .bitmask = server->attr_bitmask, | 
|  | 4001 | .fh = NFS_FH(inode), | 
|  | 4002 | }; | 
|  | 4003 | struct nfs4_lookupp_res res = { | 
|  | 4004 | .server = server, | 
|  | 4005 | .fattr = fattr, | 
|  | 4006 | .label = label, | 
|  | 4007 | .fh = fhandle, | 
|  | 4008 | }; | 
|  | 4009 | struct rpc_message msg = { | 
|  | 4010 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], | 
|  | 4011 | .rpc_argp = &args, | 
|  | 4012 | .rpc_resp = &res, | 
|  | 4013 | }; | 
|  | 4014 |  | 
|  | 4015 | args.bitmask = nfs4_bitmask(server, label); | 
|  | 4016 |  | 
|  | 4017 | nfs_fattr_init(fattr); | 
|  | 4018 |  | 
|  | 4019 | dprintk("NFS call  lookupp ino=0x%lx\n", inode->i_ino); | 
|  | 4020 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, | 
|  | 4021 | &res.seq_res, 0); | 
|  | 4022 | dprintk("NFS reply lookupp: %d\n", status); | 
|  | 4023 | return status; | 
|  | 4024 | } | 
|  | 4025 |  | 
|  | 4026 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, | 
|  | 4027 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
|  | 4028 | { | 
|  | 4029 | struct nfs4_exception exception = { }; | 
|  | 4030 | int err; | 
|  | 4031 | do { | 
|  | 4032 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); | 
|  | 4033 | trace_nfs4_lookupp(inode, err); | 
|  | 4034 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
|  | 4035 | &exception); | 
|  | 4036 | } while (exception.retry); | 
|  | 4037 | return err; | 
|  | 4038 | } | 
|  | 4039 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 
|  | 4041 | { | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4042 | struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | struct nfs4_accessargs args = { | 
|  | 4044 | .fh = NFS_FH(inode), | 
| Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 4045 | .bitmask = server->cache_consistency_bitmask, | 
| Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4046 | .access = entry->mask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | }; | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4048 | struct nfs4_accessres res = { | 
|  | 4049 | .server = server, | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4050 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | struct rpc_message msg = { | 
|  | 4052 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], | 
|  | 4053 | .rpc_argp = &args, | 
|  | 4054 | .rpc_resp = &res, | 
|  | 4055 | .rpc_cred = entry->cred, | 
|  | 4056 | }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4057 | int status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 |  | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4059 | res.fattr = nfs_alloc_fattr(); | 
|  | 4060 | if (res.fattr == NULL) | 
|  | 4061 | return -ENOMEM; | 
|  | 4062 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4063 | 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] | 4064 | if (!status) { | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4065 | nfs_access_set_mask(entry, res.access); | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4066 | nfs_refresh_inode(inode, res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | } | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4068 | nfs_free_fattr(res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | return status; | 
|  | 4070 | } | 
|  | 4071 |  | 
|  | 4072 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 
|  | 4073 | { | 
|  | 4074 | struct nfs4_exception exception = { }; | 
|  | 4075 | int err; | 
|  | 4076 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4077 | err = _nfs4_proc_access(inode, entry); | 
|  | 4078 | trace_nfs4_access(inode, err); | 
|  | 4079 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | &exception); | 
|  | 4081 | } while (exception.retry); | 
|  | 4082 | return err; | 
|  | 4083 | } | 
|  | 4084 |  | 
|  | 4085 | /* | 
|  | 4086 | * TODO: For the time being, we don't try to get any attributes | 
|  | 4087 | * along with any of the zero-copy operations READ, READDIR, | 
|  | 4088 | * READLINK, WRITE. | 
|  | 4089 | * | 
|  | 4090 | * In the case of the first three, we want to put the GETATTR | 
|  | 4091 | * after the read-type operation -- this is because it is hard | 
|  | 4092 | * to predict the length of a GETATTR response in v4, and thus | 
|  | 4093 | * align the READ data correctly.  This means that the GETATTR | 
|  | 4094 | * may end up partially falling into the page cache, and we should | 
|  | 4095 | * shift it into the 'tail' of the xdr_buf before processing. | 
|  | 4096 | * To do this efficiently, we need to know the total length | 
|  | 4097 | * of data received, which doesn't seem to be available outside | 
|  | 4098 | * of the RPC layer. | 
|  | 4099 | * | 
|  | 4100 | * In the case of WRITE, we also want to put the GETATTR after | 
|  | 4101 | * the operation -- in this case because we want to make sure | 
| Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4102 | * we get the post-operation mtime and size. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | * | 
|  | 4104 | * Both of these changes to the XDR layer would in fact be quite | 
|  | 4105 | * minor, but I decided to leave them for a subsequent patch. | 
|  | 4106 | */ | 
|  | 4107 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, | 
|  | 4108 | unsigned int pgbase, unsigned int pglen) | 
|  | 4109 | { | 
|  | 4110 | struct nfs4_readlink args = { | 
|  | 4111 | .fh       = NFS_FH(inode), | 
|  | 4112 | .pgbase	  = pgbase, | 
|  | 4113 | .pglen    = pglen, | 
|  | 4114 | .pages    = &page, | 
|  | 4115 | }; | 
| Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4116 | struct nfs4_readlink_res res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | struct rpc_message msg = { | 
|  | 4118 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], | 
|  | 4119 | .rpc_argp = &args, | 
| Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4120 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | }; | 
|  | 4122 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4123 | 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] | 4124 | } | 
|  | 4125 |  | 
|  | 4126 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, | 
|  | 4127 | unsigned int pgbase, unsigned int pglen) | 
|  | 4128 | { | 
|  | 4129 | struct nfs4_exception exception = { }; | 
|  | 4130 | int err; | 
|  | 4131 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4132 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); | 
|  | 4133 | trace_nfs4_readlink(inode, err); | 
|  | 4134 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | &exception); | 
|  | 4136 | } while (exception.retry); | 
|  | 4137 | return err; | 
|  | 4138 | } | 
|  | 4139 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | /* | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4141 | * 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] | 4142 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | static int | 
|  | 4144 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4145 | int flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | { | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4147 | struct nfs_server *server = NFS_SERVER(dir); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4148 | struct nfs4_label l, *ilabel = NULL; | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4149 | struct nfs_open_context *ctx; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | struct nfs4_state *state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | int status = 0; | 
|  | 4152 |  | 
| NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4153 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4154 | if (IS_ERR(ctx)) | 
|  | 4155 | return PTR_ERR(ctx); | 
|  | 4156 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4157 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 4158 |  | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4159 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) | 
|  | 4160 | sattr->ia_mode &= ~current_umask(); | 
| Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4161 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | if (IS_ERR(state)) { | 
|  | 4163 | status = PTR_ERR(state); | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4164 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | out: | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4167 | nfs4_label_release_security(ilabel); | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4168 | put_nfs_open_context(ctx); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | return status; | 
|  | 4170 | } | 
|  | 4171 |  | 
| Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4172 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | { | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4174 | struct nfs_server *server = NFS_SERVER(dir); | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4175 | struct nfs_removeargs args = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | .fh = NFS_FH(dir), | 
| Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4177 | .name = *name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | }; | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4179 | struct nfs_removeres res = { | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4180 | .server = server, | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4181 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | struct rpc_message msg = { | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4183 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], | 
|  | 4184 | .rpc_argp = &args, | 
|  | 4185 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | }; | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4187 | unsigned long timestamp = jiffies; | 
| Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4188 | int status; | 
| Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4189 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4190 | 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] | 4191 | if (status == 0) | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4192 | update_changeattr(dir, &res.cinfo, timestamp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | return status; | 
|  | 4194 | } | 
|  | 4195 |  | 
| Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4196 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | { | 
|  | 4198 | struct nfs4_exception exception = { }; | 
|  | 4199 | int err; | 
|  | 4200 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4201 | err = _nfs4_proc_remove(dir, name); | 
|  | 4202 | trace_nfs4_remove(dir, name, err); | 
|  | 4203 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | &exception); | 
|  | 4205 | } while (exception.retry); | 
|  | 4206 | return err; | 
|  | 4207 | } | 
|  | 4208 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4209 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | { | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4211 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 4212 | struct nfs_removeargs *args = msg->rpc_argp; | 
|  | 4213 | struct nfs_removeres *res = msg->rpc_resp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4215 | res->server = server; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4217 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4218 |  | 
|  | 4219 | nfs_fattr_init(res->dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | } | 
|  | 4221 |  | 
| Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4222 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) | 
|  | 4223 | { | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4224 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4225 | &data->args.seq_args, | 
|  | 4226 | &data->res.seq_res, | 
|  | 4227 | task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | } | 
|  | 4229 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4230 | 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] | 4231 | { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4232 | struct nfs_unlinkdata *data = task->tk_calldata; | 
|  | 4233 | struct nfs_removeres *res = &data->res; | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4234 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4235 | if (!nfs4_sequence_done(task, &res->seq_res)) | 
|  | 4236 | return 0; | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4237 | if (nfs4_async_handle_error(task, res->server, NULL, | 
|  | 4238 | &data->timeout) == -EAGAIN) | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4239 | return 0; | 
| Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4240 | if (task->tk_status == 0) | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4241 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4242 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | } | 
|  | 4244 |  | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4245 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) | 
|  | 4246 | { | 
|  | 4247 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 4248 | struct nfs_renameargs *arg = msg->rpc_argp; | 
|  | 4249 | struct nfs_renameres *res = msg->rpc_resp; | 
|  | 4250 |  | 
|  | 4251 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4252 | res->server = server; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4253 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4254 | } | 
|  | 4255 |  | 
| Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4256 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) | 
|  | 4257 | { | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4258 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4259 | &data->args.seq_args, | 
|  | 4260 | &data->res.seq_res, | 
|  | 4261 | task); | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4262 | } | 
|  | 4263 |  | 
|  | 4264 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, | 
|  | 4265 | struct inode *new_dir) | 
|  | 4266 | { | 
| Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4267 | struct nfs_renamedata *data = task->tk_calldata; | 
|  | 4268 | struct nfs_renameres *res = &data->res; | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4269 |  | 
|  | 4270 | if (!nfs4_sequence_done(task, &res->seq_res)) | 
|  | 4271 | return 0; | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4272 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4273 | return 0; | 
|  | 4274 |  | 
| Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4275 | if (task->tk_status == 0) { | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4276 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); | 
| Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4277 | if (new_dir != old_dir) | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4278 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); | 
| Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4279 | } | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4280 | return 1; | 
|  | 4281 | } | 
|  | 4282 |  | 
| Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4283 | 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] | 4284 | { | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4285 | struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | struct nfs4_link_arg arg = { | 
|  | 4287 | .fh     = NFS_FH(inode), | 
|  | 4288 | .dir_fh = NFS_FH(dir), | 
|  | 4289 | .name   = name, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4290 | .bitmask = server->attr_bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | }; | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4292 | struct nfs4_link_res res = { | 
|  | 4293 | .server = server, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4294 | .label = NULL, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4295 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | struct rpc_message msg = { | 
|  | 4297 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], | 
|  | 4298 | .rpc_argp = &arg, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4299 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | }; | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4301 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 |  | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4303 | res.fattr = nfs_alloc_fattr(); | 
| Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4304 | if (res.fattr == NULL) | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4305 | goto out; | 
|  | 4306 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4307 | res.label = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 4308 | if (IS_ERR(res.label)) { | 
|  | 4309 | status = PTR_ERR(res.label); | 
|  | 4310 | goto out; | 
|  | 4311 | } | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4312 | arg.bitmask = nfs4_bitmask(server, res.label); | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4313 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4314 | 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] | 4315 | if (!status) { | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4316 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4317 | status = nfs_post_op_update_inode(inode, res.fattr); | 
|  | 4318 | if (!status) | 
|  | 4319 | nfs_setsecurity(inode, res.fattr, res.label); | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4320 | } | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4321 |  | 
|  | 4322 |  | 
|  | 4323 | nfs4_label_free(res.label); | 
|  | 4324 |  | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4325 | out: | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4326 | nfs_free_fattr(res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | return status; | 
|  | 4328 | } | 
|  | 4329 |  | 
| Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4330 | 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] | 4331 | { | 
|  | 4332 | struct nfs4_exception exception = { }; | 
|  | 4333 | int err; | 
|  | 4334 | do { | 
|  | 4335 | err = nfs4_handle_exception(NFS_SERVER(inode), | 
|  | 4336 | _nfs4_proc_link(inode, dir, name), | 
|  | 4337 | &exception); | 
|  | 4338 | } while (exception.retry); | 
|  | 4339 | return err; | 
|  | 4340 | } | 
|  | 4341 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4342 | struct nfs4_createdata { | 
|  | 4343 | struct rpc_message msg; | 
|  | 4344 | struct nfs4_create_arg arg; | 
|  | 4345 | struct nfs4_create_res res; | 
|  | 4346 | struct nfs_fh fh; | 
|  | 4347 | struct nfs_fattr fattr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4348 | struct nfs4_label *label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4349 | }; | 
|  | 4350 |  | 
|  | 4351 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, | 
| Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4352 | const struct qstr *name, struct iattr *sattr, u32 ftype) | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4353 | { | 
|  | 4354 | struct nfs4_createdata *data; | 
|  | 4355 |  | 
|  | 4356 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 
|  | 4357 | if (data != NULL) { | 
|  | 4358 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 4359 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4360 | data->label = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 4361 | if (IS_ERR(data->label)) | 
|  | 4362 | goto out_free; | 
|  | 4363 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4364 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; | 
|  | 4365 | data->msg.rpc_argp = &data->arg; | 
|  | 4366 | data->msg.rpc_resp = &data->res; | 
|  | 4367 | data->arg.dir_fh = NFS_FH(dir); | 
|  | 4368 | data->arg.server = server; | 
|  | 4369 | data->arg.name = name; | 
|  | 4370 | data->arg.attrs = sattr; | 
|  | 4371 | data->arg.ftype = ftype; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4372 | data->arg.bitmask = nfs4_bitmask(server, data->label); | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4373 | data->arg.umask = current_umask(); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4374 | data->res.server = server; | 
|  | 4375 | data->res.fh = &data->fh; | 
|  | 4376 | data->res.fattr = &data->fattr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4377 | data->res.label = data->label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4378 | nfs_fattr_init(data->res.fattr); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4379 | } | 
|  | 4380 | return data; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4381 | out_free: | 
|  | 4382 | kfree(data); | 
|  | 4383 | return NULL; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4384 | } | 
|  | 4385 |  | 
|  | 4386 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) | 
|  | 4387 | { | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4388 | 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] | 4389 | &data->arg.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4390 | if (status == 0) { | 
| Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4391 | update_changeattr(dir, &data->res.dir_cinfo, | 
|  | 4392 | data->res.fattr->time_start); | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4393 | 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] | 4394 | } | 
|  | 4395 | return status; | 
|  | 4396 | } | 
|  | 4397 |  | 
|  | 4398 | static void nfs4_free_createdata(struct nfs4_createdata *data) | 
|  | 4399 | { | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4400 | nfs4_label_free(data->label); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4401 | kfree(data); | 
|  | 4402 | } | 
|  | 4403 |  | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4404 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4405 | struct page *page, unsigned int len, struct iattr *sattr, | 
|  | 4406 | struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4408 | struct nfs4_createdata *data; | 
|  | 4409 | int status = -ENAMETOOLONG; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 |  | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4411 | if (len > NFS4_MAXPATHLEN) | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4412 | goto out; | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4413 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4414 | status = -ENOMEM; | 
|  | 4415 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); | 
|  | 4416 | if (data == NULL) | 
|  | 4417 | goto out; | 
|  | 4418 |  | 
|  | 4419 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; | 
|  | 4420 | data->arg.u.symlink.pages = &page; | 
|  | 4421 | data->arg.u.symlink.len = len; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4422 | data->arg.label = label; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4424 | status = nfs4_do_create(dir, dentry, data); | 
|  | 4425 |  | 
|  | 4426 | nfs4_free_createdata(data); | 
|  | 4427 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | return status; | 
|  | 4429 | } | 
|  | 4430 |  | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4431 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4432 | struct page *page, unsigned int len, struct iattr *sattr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | { | 
|  | 4434 | struct nfs4_exception exception = { }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4435 | struct nfs4_label l, *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | int err; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4437 |  | 
|  | 4438 | label = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 4439 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4441 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); | 
|  | 4442 | trace_nfs4_symlink(dir, &dentry->d_name, err); | 
|  | 4443 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | &exception); | 
|  | 4445 | } while (exception.retry); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4446 |  | 
|  | 4447 | nfs4_label_release_security(label); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | return err; | 
|  | 4449 | } | 
|  | 4450 |  | 
|  | 4451 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4452 | struct iattr *sattr, struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4454 | struct nfs4_createdata *data; | 
|  | 4455 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4457 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); | 
|  | 4458 | if (data == NULL) | 
|  | 4459 | goto out; | 
|  | 4460 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4461 | data->arg.label = label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4462 | status = nfs4_do_create(dir, dentry, data); | 
|  | 4463 |  | 
|  | 4464 | nfs4_free_createdata(data); | 
|  | 4465 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | return status; | 
|  | 4467 | } | 
|  | 4468 |  | 
|  | 4469 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 
|  | 4470 | struct iattr *sattr) | 
|  | 4471 | { | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4472 | struct nfs_server *server = NFS_SERVER(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | struct nfs4_exception exception = { }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4474 | struct nfs4_label l, *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | int err; | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4476 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4477 | label = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 4478 |  | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4479 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) | 
|  | 4480 | sattr->ia_mode &= ~current_umask(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4482 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); | 
|  | 4483 | trace_nfs4_mkdir(dir, &dentry->d_name, err); | 
|  | 4484 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | &exception); | 
|  | 4486 | } while (exception.retry); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4487 | nfs4_label_release_security(label); | 
|  | 4488 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | return err; | 
|  | 4490 | } | 
|  | 4491 |  | 
|  | 4492 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4493 | u64 cookie, struct page **pages, unsigned int count, bool plus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | { | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4495 | struct inode		*dir = d_inode(dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | struct nfs4_readdir_arg args = { | 
|  | 4497 | .fh = NFS_FH(dir), | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4498 | .pages = pages, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | .pgbase = 0, | 
|  | 4500 | .count = count, | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4501 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, | 
| Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4502 | .plus = plus, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | }; | 
|  | 4504 | struct nfs4_readdir_res res; | 
|  | 4505 | struct rpc_message msg = { | 
|  | 4506 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], | 
|  | 4507 | .rpc_argp = &args, | 
|  | 4508 | .rpc_resp = &res, | 
|  | 4509 | .rpc_cred = cred, | 
|  | 4510 | }; | 
|  | 4511 | int			status; | 
|  | 4512 |  | 
| Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4513 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, | 
|  | 4514 | dentry, | 
| Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4515 | (unsigned long long)cookie); | 
| Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4516 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | res.pgbase = args.pgbase; | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4518 | 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] | 4519 | if (status >= 0) { | 
| Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4520 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); | 
| Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4521 | status += args.pgbase; | 
|  | 4522 | } | 
| Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4523 |  | 
|  | 4524 | nfs_invalidate_atime(dir); | 
|  | 4525 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4526 | dprintk("%s: returns %d\n", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | return status; | 
|  | 4528 | } | 
|  | 4529 |  | 
|  | 4530 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4531 | u64 cookie, struct page **pages, unsigned int count, bool plus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | { | 
|  | 4533 | struct nfs4_exception exception = { }; | 
|  | 4534 | int err; | 
|  | 4535 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4536 | err = _nfs4_proc_readdir(dentry, cred, cookie, | 
|  | 4537 | pages, count, plus); | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4538 | trace_nfs4_readdir(d_inode(dentry), err); | 
|  | 4539 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | &exception); | 
|  | 4541 | } while (exception.retry); | 
|  | 4542 | return err; | 
|  | 4543 | } | 
|  | 4544 |  | 
|  | 4545 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4546 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4548 | struct nfs4_createdata *data; | 
|  | 4549 | int mode = sattr->ia_mode; | 
|  | 4550 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4552 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); | 
|  | 4553 | if (data == NULL) | 
|  | 4554 | goto out; | 
|  | 4555 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | if (S_ISFIFO(mode)) | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4557 | data->arg.ftype = NF4FIFO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | else if (S_ISBLK(mode)) { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4559 | data->arg.ftype = NF4BLK; | 
|  | 4560 | data->arg.u.device.specdata1 = MAJOR(rdev); | 
|  | 4561 | data->arg.u.device.specdata2 = MINOR(rdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | } | 
|  | 4563 | else if (S_ISCHR(mode)) { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4564 | data->arg.ftype = NF4CHR; | 
|  | 4565 | data->arg.u.device.specdata1 = MAJOR(rdev); | 
|  | 4566 | data->arg.u.device.specdata2 = MINOR(rdev); | 
| Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4567 | } else if (!S_ISSOCK(mode)) { | 
|  | 4568 | status = -EINVAL; | 
|  | 4569 | goto out_free; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | } | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4571 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4572 | data->arg.label = label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4573 | status = nfs4_do_create(dir, dentry, data); | 
| Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4574 | out_free: | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4575 | nfs4_free_createdata(data); | 
|  | 4576 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | return status; | 
|  | 4578 | } | 
|  | 4579 |  | 
|  | 4580 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 
|  | 4581 | struct iattr *sattr, dev_t rdev) | 
|  | 4582 | { | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4583 | struct nfs_server *server = NFS_SERVER(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | struct nfs4_exception exception = { }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4585 | struct nfs4_label l, *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | int err; | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4587 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4588 | label = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 4589 |  | 
| Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4590 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) | 
|  | 4591 | sattr->ia_mode &= ~current_umask(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4593 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); | 
|  | 4594 | trace_nfs4_mknod(dir, &dentry->d_name, err); | 
|  | 4595 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | &exception); | 
|  | 4597 | } while (exception.retry); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4598 |  | 
|  | 4599 | nfs4_label_release_security(label); | 
|  | 4600 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | return err; | 
|  | 4602 | } | 
|  | 4603 |  | 
|  | 4604 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 4605 | struct nfs_fsstat *fsstat) | 
|  | 4606 | { | 
|  | 4607 | struct nfs4_statfs_arg args = { | 
|  | 4608 | .fh = fhandle, | 
|  | 4609 | .bitmask = server->attr_bitmask, | 
|  | 4610 | }; | 
| Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4611 | struct nfs4_statfs_res res = { | 
|  | 4612 | .fsstat = fsstat, | 
|  | 4613 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4614 | struct rpc_message msg = { | 
|  | 4615 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], | 
|  | 4616 | .rpc_argp = &args, | 
| Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4617 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | }; | 
|  | 4619 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4620 | nfs_fattr_init(fsstat->fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4621 | 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] | 4622 | } | 
|  | 4623 |  | 
|  | 4624 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) | 
|  | 4625 | { | 
|  | 4626 | struct nfs4_exception exception = { }; | 
|  | 4627 | int err; | 
|  | 4628 | do { | 
|  | 4629 | err = nfs4_handle_exception(server, | 
|  | 4630 | _nfs4_proc_statfs(server, fhandle, fsstat), | 
|  | 4631 | &exception); | 
|  | 4632 | } while (exception.retry); | 
|  | 4633 | return err; | 
|  | 4634 | } | 
|  | 4635 |  | 
|  | 4636 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 4637 | struct nfs_fsinfo *fsinfo) | 
|  | 4638 | { | 
|  | 4639 | struct nfs4_fsinfo_arg args = { | 
|  | 4640 | .fh = fhandle, | 
|  | 4641 | .bitmask = server->attr_bitmask, | 
|  | 4642 | }; | 
| Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4643 | struct nfs4_fsinfo_res res = { | 
|  | 4644 | .fsinfo = fsinfo, | 
|  | 4645 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | struct rpc_message msg = { | 
|  | 4647 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], | 
|  | 4648 | .rpc_argp = &args, | 
| Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4649 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | }; | 
|  | 4651 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4652 | 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] | 4653 | } | 
|  | 4654 |  | 
|  | 4655 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 
|  | 4656 | { | 
|  | 4657 | struct nfs4_exception exception = { }; | 
| Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4658 | unsigned long now = jiffies; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | int err; | 
|  | 4660 |  | 
|  | 4661 | do { | 
| Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4662 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); | 
| Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4663 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); | 
| Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4664 | if (err == 0) { | 
| Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4665 | nfs4_set_lease_period(server->nfs_client, | 
|  | 4666 | fsinfo->lease_time * HZ, | 
|  | 4667 | now); | 
| Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4668 | break; | 
|  | 4669 | } | 
|  | 4670 | err = nfs4_handle_exception(server, err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | } while (exception.retry); | 
|  | 4672 | return err; | 
|  | 4673 | } | 
|  | 4674 |  | 
|  | 4675 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 
|  | 4676 | { | 
| Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4677 | int error; | 
|  | 4678 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4679 | nfs_fattr_init(fsinfo->fattr); | 
| Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4680 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); | 
| Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4681 | if (error == 0) { | 
|  | 4682 | /* block layout checks this! */ | 
|  | 4683 | server->pnfs_blksize = fsinfo->blksize; | 
| Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4684 | set_pnfs_layoutdriver(server, fhandle, fsinfo); | 
| Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4685 | } | 
| Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4686 |  | 
|  | 4687 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | } | 
|  | 4689 |  | 
|  | 4690 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 4691 | struct nfs_pathconf *pathconf) | 
|  | 4692 | { | 
|  | 4693 | struct nfs4_pathconf_arg args = { | 
|  | 4694 | .fh = fhandle, | 
|  | 4695 | .bitmask = server->attr_bitmask, | 
|  | 4696 | }; | 
| Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4697 | struct nfs4_pathconf_res res = { | 
|  | 4698 | .pathconf = pathconf, | 
|  | 4699 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | struct rpc_message msg = { | 
|  | 4701 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], | 
|  | 4702 | .rpc_argp = &args, | 
| Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4703 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | }; | 
|  | 4705 |  | 
|  | 4706 | /* None of the pathconf attributes are mandatory to implement */ | 
|  | 4707 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { | 
|  | 4708 | memset(pathconf, 0, sizeof(*pathconf)); | 
|  | 4709 | return 0; | 
|  | 4710 | } | 
|  | 4711 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4712 | nfs_fattr_init(pathconf->fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4713 | 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] | 4714 | } | 
|  | 4715 |  | 
|  | 4716 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 4717 | struct nfs_pathconf *pathconf) | 
|  | 4718 | { | 
|  | 4719 | struct nfs4_exception exception = { }; | 
|  | 4720 | int err; | 
|  | 4721 |  | 
|  | 4722 | do { | 
|  | 4723 | err = nfs4_handle_exception(server, | 
|  | 4724 | _nfs4_proc_pathconf(server, fhandle, pathconf), | 
|  | 4725 | &exception); | 
|  | 4726 | } while (exception.retry); | 
|  | 4727 | return err; | 
|  | 4728 | } | 
|  | 4729 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4730 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4731 | const struct nfs_open_context *ctx, | 
|  | 4732 | const struct nfs_lock_context *l_ctx, | 
|  | 4733 | fmode_t fmode) | 
|  | 4734 | { | 
| NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4735 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4736 | } | 
|  | 4737 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); | 
|  | 4738 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4739 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, | 
|  | 4740 | const struct nfs_open_context *ctx, | 
|  | 4741 | const struct nfs_lock_context *l_ctx, | 
|  | 4742 | fmode_t fmode) | 
|  | 4743 | { | 
|  | 4744 | nfs4_stateid current_stateid; | 
|  | 4745 |  | 
| Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4746 | /* If the current stateid represents a lost lock, then exit */ | 
|  | 4747 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) | 
|  | 4748 | return true; | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4749 | return nfs4_stateid_match(stateid, ¤t_stateid); | 
|  | 4750 | } | 
|  | 4751 |  | 
|  | 4752 | static bool nfs4_error_stateid_expired(int err) | 
|  | 4753 | { | 
|  | 4754 | switch (err) { | 
|  | 4755 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 4756 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 4757 | case -NFS4ERR_BAD_STATEID: | 
|  | 4758 | case -NFS4ERR_STALE_STATEID: | 
|  | 4759 | case -NFS4ERR_OLD_STATEID: | 
|  | 4760 | case -NFS4ERR_OPENMODE: | 
|  | 4761 | case -NFS4ERR_EXPIRED: | 
|  | 4762 | return true; | 
|  | 4763 | } | 
|  | 4764 | return false; | 
|  | 4765 | } | 
|  | 4766 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4767 | 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] | 4768 | { | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4769 | struct nfs_server *server = NFS_SERVER(hdr->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4771 | trace_nfs4_read(hdr, task->tk_status); | 
| Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4772 | if (task->tk_status < 0) { | 
|  | 4773 | struct nfs4_exception exception = { | 
|  | 4774 | .inode = hdr->inode, | 
|  | 4775 | .state = hdr->args.context->state, | 
|  | 4776 | .stateid = &hdr->args.stateid, | 
|  | 4777 | }; | 
|  | 4778 | task->tk_status = nfs4_async_handle_exception(task, | 
|  | 4779 | server, task->tk_status, &exception); | 
|  | 4780 | if (exception.retry) { | 
|  | 4781 | rpc_restart_call_prepare(task); | 
|  | 4782 | return -EAGAIN; | 
|  | 4783 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | } | 
| Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4785 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | if (task->tk_status > 0) | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4787 | renew_lease(server, hdr->timestamp); | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4788 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | } | 
|  | 4790 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4791 | static bool nfs4_read_stateid_changed(struct rpc_task *task, | 
| Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4792 | struct nfs_pgio_args *args) | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4793 | { | 
|  | 4794 |  | 
|  | 4795 | if (!nfs4_error_stateid_expired(task->tk_status) || | 
|  | 4796 | nfs4_stateid_is_current(&args->stateid, | 
|  | 4797 | args->context, | 
|  | 4798 | args->lock_context, | 
|  | 4799 | FMODE_READ)) | 
|  | 4800 | return false; | 
|  | 4801 | rpc_restart_call_prepare(task); | 
|  | 4802 | return true; | 
|  | 4803 | } | 
|  | 4804 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4805 | 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] | 4806 | { | 
|  | 4807 |  | 
|  | 4808 | dprintk("--> %s\n", __func__); | 
|  | 4809 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4810 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) | 
| Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4811 | return -EAGAIN; | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4812 | if (nfs4_read_stateid_changed(task, &hdr->args)) | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4813 | return -EAGAIN; | 
| Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4814 | if (task->tk_status > 0) | 
|  | 4815 | nfs_invalidate_atime(hdr->inode); | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4816 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : | 
|  | 4817 | nfs4_read_done_cb(task, hdr); | 
| Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4818 | } | 
|  | 4819 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4820 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, | 
|  | 4821 | struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | { | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4823 | hdr->timestamp   = jiffies; | 
| Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4824 | if (!hdr->pgio_done_cb) | 
|  | 4825 | hdr->pgio_done_cb = nfs4_read_done_cb; | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4826 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4827 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | } | 
|  | 4829 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4830 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, | 
|  | 4831 | struct nfs_pgio_header *hdr) | 
| Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4832 | { | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4833 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4834 | &hdr->args.seq_args, | 
|  | 4835 | &hdr->res.seq_res, | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4836 | task)) | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4837 | return 0; | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4838 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, | 
|  | 4839 | hdr->args.lock_context, | 
| Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4840 | hdr->rw_mode) == -EIO) | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4841 | return -EIO; | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4842 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4843 | return -EIO; | 
|  | 4844 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | } | 
|  | 4846 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4847 | static int nfs4_write_done_cb(struct rpc_task *task, | 
|  | 4848 | struct nfs_pgio_header *hdr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | { | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4850 | struct inode *inode = hdr->inode; | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4851 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4852 | trace_nfs4_write(hdr, task->tk_status); | 
| Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4853 | if (task->tk_status < 0) { | 
|  | 4854 | struct nfs4_exception exception = { | 
|  | 4855 | .inode = hdr->inode, | 
|  | 4856 | .state = hdr->args.context->state, | 
|  | 4857 | .stateid = &hdr->args.stateid, | 
|  | 4858 | }; | 
|  | 4859 | task->tk_status = nfs4_async_handle_exception(task, | 
|  | 4860 | NFS_SERVER(inode), task->tk_status, | 
|  | 4861 | &exception); | 
|  | 4862 | if (exception.retry) { | 
|  | 4863 | rpc_restart_call_prepare(task); | 
|  | 4864 | return -EAGAIN; | 
|  | 4865 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | } | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4867 | if (task->tk_status >= 0) { | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4868 | renew_lease(NFS_SERVER(inode), hdr->timestamp); | 
| Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4869 | nfs_writeback_update_inode(hdr); | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4870 | } | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4871 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | } | 
|  | 4873 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4874 | static bool nfs4_write_stateid_changed(struct rpc_task *task, | 
| Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4875 | struct nfs_pgio_args *args) | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4876 | { | 
|  | 4877 |  | 
|  | 4878 | if (!nfs4_error_stateid_expired(task->tk_status) || | 
|  | 4879 | nfs4_stateid_is_current(&args->stateid, | 
|  | 4880 | args->context, | 
|  | 4881 | args->lock_context, | 
|  | 4882 | FMODE_WRITE)) | 
|  | 4883 | return false; | 
|  | 4884 | rpc_restart_call_prepare(task); | 
|  | 4885 | return true; | 
|  | 4886 | } | 
|  | 4887 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4888 | 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] | 4889 | { | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4890 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) | 
| Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4891 | return -EAGAIN; | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4892 | if (nfs4_write_stateid_changed(task, &hdr->args)) | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4893 | return -EAGAIN; | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4894 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : | 
|  | 4895 | nfs4_write_done_cb(task, hdr); | 
| Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4896 | } | 
|  | 4897 |  | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4898 | static | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4899 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) | 
| Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4900 | { | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4901 | /* Don't request attributes for pNFS or O_DIRECT writes */ | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4902 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4903 | return false; | 
|  | 4904 | /* Otherwise, request attributes if and only if we don't hold | 
|  | 4905 | * a delegation | 
|  | 4906 | */ | 
| Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4907 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; | 
| Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4908 | } | 
| Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4909 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4910 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, | 
|  | 4911 | struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | { | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4913 | struct nfs_server *server = NFS_SERVER(hdr->inode); | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4914 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4915 | if (!nfs4_write_need_cache_consistency_data(hdr)) { | 
|  | 4916 | hdr->args.bitmask = NULL; | 
|  | 4917 | hdr->res.fattr = NULL; | 
| Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4918 | } else | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4919 | hdr->args.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4920 |  | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4921 | if (!hdr->pgio_done_cb) | 
|  | 4922 | hdr->pgio_done_cb = nfs4_write_done_cb; | 
|  | 4923 | hdr->res.server = server; | 
|  | 4924 | hdr->timestamp   = jiffies; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4926 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; | 
| Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4927 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | } | 
|  | 4929 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4930 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) | 
|  | 4931 | { | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4932 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4933 | &data->args.seq_args, | 
|  | 4934 | &data->res.seq_res, | 
|  | 4935 | task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | } | 
|  | 4937 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4938 | 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] | 4939 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | struct inode *inode = data->inode; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4941 |  | 
| Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4942 | trace_nfs4_commit(data, task->tk_status); | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4943 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), | 
|  | 4944 | NULL, NULL) == -EAGAIN) { | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4945 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4946 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | } | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4948 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | } | 
|  | 4950 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4951 | 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] | 4952 | { | 
|  | 4953 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 4954 | return -EAGAIN; | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4955 | return data->commit_done_cb(task, data); | 
| Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4956 | } | 
|  | 4957 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4958 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | { | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4960 | struct nfs_server *server = NFS_SERVER(data->inode); | 
| Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4961 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4962 | if (data->commit_done_cb == NULL) | 
|  | 4963 | data->commit_done_cb = nfs4_commit_done_cb; | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4964 | data->res.server = server; | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4965 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4966 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | } | 
|  | 4968 |  | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4969 | struct nfs4_renewdata { | 
|  | 4970 | struct nfs_client	*client; | 
|  | 4971 | unsigned long		timestamp; | 
|  | 4972 | }; | 
|  | 4973 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4974 | /* | 
|  | 4975 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special | 
|  | 4976 | * standalone procedure for queueing an asynchronous RENEW. | 
|  | 4977 | */ | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4978 | static void nfs4_renew_release(void *calldata) | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4979 | { | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4980 | struct nfs4_renewdata *data = calldata; | 
|  | 4981 | struct nfs_client *clp = data->client; | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4982 |  | 
| Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 4983 | if (refcount_read(&clp->cl_count) > 1) | 
| Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4984 | nfs4_schedule_state_renewal(clp); | 
|  | 4985 | nfs_put_client(clp); | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4986 | kfree(data); | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4987 | } | 
|  | 4988 |  | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4989 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | { | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4991 | struct nfs4_renewdata *data = calldata; | 
|  | 4992 | struct nfs_client *clp = data->client; | 
|  | 4993 | unsigned long timestamp = data->timestamp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4995 | trace_nfs4_renew_async(clp, task->tk_status); | 
| Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4996 | switch (task->tk_status) { | 
|  | 4997 | case 0: | 
|  | 4998 | break; | 
|  | 4999 | case -NFS4ERR_LEASE_MOVED: | 
|  | 5000 | nfs4_schedule_lease_moved_recovery(clp); | 
|  | 5001 | break; | 
|  | 5002 | default: | 
| Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5003 | /* Unless we're shutting down, schedule state recovery! */ | 
| Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5004 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) | 
|  | 5005 | return; | 
|  | 5006 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5007 | nfs4_schedule_lease_recovery(clp); | 
| Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5008 | return; | 
|  | 5009 | } | 
|  | 5010 | nfs4_schedule_path_down_recovery(clp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | } | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5012 | do_renew_lease(clp, timestamp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | } | 
|  | 5014 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5015 | static const struct rpc_call_ops nfs4_renew_ops = { | 
|  | 5016 | .rpc_call_done = nfs4_renew_done, | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5017 | .rpc_release = nfs4_renew_release, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5018 | }; | 
|  | 5019 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5020 | 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] | 5021 | { | 
|  | 5022 | struct rpc_message msg = { | 
|  | 5023 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 
|  | 5024 | .rpc_argp	= clp, | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5025 | .rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | }; | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5027 | struct nfs4_renewdata *data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5028 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5029 | if (renew_flags == 0) | 
|  | 5030 | return 0; | 
| Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5031 | if (!refcount_inc_not_zero(&clp->cl_count)) | 
| Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5032 | return -EIO; | 
| Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5033 | data = kmalloc(sizeof(*data), GFP_NOFS); | 
| Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5034 | if (data == NULL) { | 
|  | 5035 | nfs_put_client(clp); | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5036 | return -ENOMEM; | 
| Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5037 | } | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5038 | data->client = clp; | 
|  | 5039 | data->timestamp = jiffies; | 
| Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5040 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5041 | &nfs4_renew_ops, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | } | 
|  | 5043 |  | 
| Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5044 | 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] | 5045 | { | 
|  | 5046 | struct rpc_message msg = { | 
|  | 5047 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 
|  | 5048 | .rpc_argp	= clp, | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5049 | .rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | }; | 
|  | 5051 | unsigned long now = jiffies; | 
|  | 5052 | int status; | 
|  | 5053 |  | 
| Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5054 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | if (status < 0) | 
|  | 5056 | return status; | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5057 | do_renew_lease(clp, now); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | return 0; | 
|  | 5059 | } | 
|  | 5060 |  | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5061 | static inline int nfs4_server_supports_acls(struct nfs_server *server) | 
|  | 5062 | { | 
| Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5063 | return server->caps & NFS_CAP_ACLS; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5064 | } | 
|  | 5065 |  | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5066 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that | 
|  | 5067 | * 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] | 5068 | * the stack. | 
|  | 5069 | */ | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5070 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5071 |  | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5072 | static int buf_to_pages_noslab(const void *buf, size_t buflen, | 
| Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5073 | struct page **pages) | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5074 | { | 
|  | 5075 | struct page *newpage, **spages; | 
|  | 5076 | int rc = 0; | 
|  | 5077 | size_t len; | 
|  | 5078 | spages = pages; | 
|  | 5079 |  | 
|  | 5080 | do { | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5081 | len = min_t(size_t, PAGE_SIZE, buflen); | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5082 | newpage = alloc_page(GFP_KERNEL); | 
|  | 5083 |  | 
|  | 5084 | if (newpage == NULL) | 
|  | 5085 | goto unwind; | 
|  | 5086 | memcpy(page_address(newpage), buf, len); | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5087 | buf += len; | 
|  | 5088 | buflen -= len; | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5089 | *pages++ = newpage; | 
|  | 5090 | rc++; | 
|  | 5091 | } while (buflen != 0); | 
|  | 5092 |  | 
|  | 5093 | return rc; | 
|  | 5094 |  | 
|  | 5095 | unwind: | 
|  | 5096 | for(; rc > 0; rc--) | 
|  | 5097 | __free_page(spages[rc-1]); | 
|  | 5098 | return -ENOMEM; | 
|  | 5099 | } | 
|  | 5100 |  | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5101 | struct nfs4_cached_acl { | 
|  | 5102 | int cached; | 
|  | 5103 | size_t len; | 
| Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5104 | char data[0]; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5105 | }; | 
|  | 5106 |  | 
|  | 5107 | 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] | 5108 | { | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5109 | struct nfs_inode *nfsi = NFS_I(inode); | 
|  | 5110 |  | 
|  | 5111 | spin_lock(&inode->i_lock); | 
|  | 5112 | kfree(nfsi->nfs4_acl); | 
|  | 5113 | nfsi->nfs4_acl = acl; | 
|  | 5114 | spin_unlock(&inode->i_lock); | 
|  | 5115 | } | 
|  | 5116 |  | 
|  | 5117 | static void nfs4_zap_acl_attr(struct inode *inode) | 
|  | 5118 | { | 
|  | 5119 | nfs4_set_cached_acl(inode, NULL); | 
|  | 5120 | } | 
|  | 5121 |  | 
|  | 5122 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) | 
|  | 5123 | { | 
|  | 5124 | struct nfs_inode *nfsi = NFS_I(inode); | 
|  | 5125 | struct nfs4_cached_acl *acl; | 
|  | 5126 | int ret = -ENOENT; | 
|  | 5127 |  | 
|  | 5128 | spin_lock(&inode->i_lock); | 
|  | 5129 | acl = nfsi->nfs4_acl; | 
|  | 5130 | if (acl == NULL) | 
|  | 5131 | goto out; | 
|  | 5132 | if (buf == NULL) /* user is just asking for length */ | 
|  | 5133 | goto out_len; | 
|  | 5134 | if (acl->cached == 0) | 
|  | 5135 | goto out; | 
|  | 5136 | ret = -ERANGE; /* see getxattr(2) man page */ | 
|  | 5137 | if (acl->len > buflen) | 
|  | 5138 | goto out; | 
|  | 5139 | memcpy(buf, acl->data, acl->len); | 
|  | 5140 | out_len: | 
|  | 5141 | ret = acl->len; | 
|  | 5142 | out: | 
|  | 5143 | spin_unlock(&inode->i_lock); | 
|  | 5144 | return ret; | 
|  | 5145 | } | 
|  | 5146 |  | 
| Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5147 | 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] | 5148 | { | 
|  | 5149 | struct nfs4_cached_acl *acl; | 
| Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5150 | size_t buflen = sizeof(*acl) + acl_len; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5151 |  | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5152 | if (buflen <= PAGE_SIZE) { | 
| Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5153 | acl = kmalloc(buflen, GFP_KERNEL); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5154 | if (acl == NULL) | 
|  | 5155 | goto out; | 
|  | 5156 | acl->cached = 1; | 
| Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5157 | _copy_from_pages(acl->data, pages, pgbase, acl_len); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5158 | } else { | 
|  | 5159 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); | 
|  | 5160 | if (acl == NULL) | 
|  | 5161 | goto out; | 
|  | 5162 | acl->cached = 0; | 
|  | 5163 | } | 
|  | 5164 | acl->len = acl_len; | 
|  | 5165 | out: | 
|  | 5166 | nfs4_set_cached_acl(inode, acl); | 
|  | 5167 | } | 
|  | 5168 |  | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5169 | /* | 
|  | 5170 | * The getxattr API returns the required buffer length when called with a | 
|  | 5171 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating | 
|  | 5172 | * the required buf.  On a NULL buf, we send a page of data to the server | 
|  | 5173 | * guessing that the ACL request can be serviced by a page. If so, we cache | 
|  | 5174 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by | 
|  | 5175 | * the cache. If not so, we throw away the page, and cache the required | 
|  | 5176 | * length. The next getxattr call will then produce another round trip to | 
|  | 5177 | * the server, this time with the input buf of the required size. | 
|  | 5178 | */ | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5179 | 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] | 5180 | { | 
| Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5181 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5182 | struct nfs_getaclargs args = { | 
|  | 5183 | .fh = NFS_FH(inode), | 
|  | 5184 | .acl_pages = pages, | 
|  | 5185 | .acl_len = buflen, | 
|  | 5186 | }; | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5187 | struct nfs_getaclres res = { | 
|  | 5188 | .acl_len = buflen, | 
|  | 5189 | }; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5190 | struct rpc_message msg = { | 
|  | 5191 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], | 
|  | 5192 | .rpc_argp = &args, | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5193 | .rpc_resp = &res, | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5194 | }; | 
| Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5195 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5196 | int ret = -ENOMEM, i; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5197 |  | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5198 | if (npages > ARRAY_SIZE(pages)) | 
|  | 5199 | return -ERANGE; | 
| Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5200 |  | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5201 | for (i = 0; i < npages; i++) { | 
|  | 5202 | pages[i] = alloc_page(GFP_KERNEL); | 
|  | 5203 | if (!pages[i]) | 
|  | 5204 | goto out_free; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5205 | } | 
| Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5206 |  | 
|  | 5207 | /* for decoding across pages */ | 
|  | 5208 | res.acl_scratch = alloc_page(GFP_KERNEL); | 
|  | 5209 | if (!res.acl_scratch) | 
|  | 5210 | goto out_free; | 
|  | 5211 |  | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5212 | args.acl_len = npages * PAGE_SIZE; | 
| Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5213 |  | 
| Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5214 | 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] | 5215 | __func__, buf, buflen, npages, args.acl_len); | 
|  | 5216 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), | 
|  | 5217 | &msg, &args.seq_args, &res.seq_res, 0); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5218 | if (ret) | 
|  | 5219 | goto out_free; | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5220 |  | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5221 | /* Handle the case where the passed-in buffer is too short */ | 
|  | 5222 | if (res.acl_flags & NFS4_ACL_TRUNC) { | 
|  | 5223 | /* Did the user only issue a request for the acl length? */ | 
|  | 5224 | if (buf == NULL) | 
|  | 5225 | goto out_ok; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5226 | ret = -ERANGE; | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5227 | goto out_free; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5228 | } | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5229 | 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] | 5230 | if (buf) { | 
|  | 5231 | if (res.acl_len > buflen) { | 
|  | 5232 | ret = -ERANGE; | 
|  | 5233 | goto out_free; | 
|  | 5234 | } | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5235 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); | 
| Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5236 | } | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5237 | out_ok: | 
|  | 5238 | ret = res.acl_len; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5239 | out_free: | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5240 | for (i = 0; i < npages; i++) | 
|  | 5241 | if (pages[i]) | 
|  | 5242 | __free_page(pages[i]); | 
| Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5243 | if (res.acl_scratch) | 
|  | 5244 | __free_page(res.acl_scratch); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5245 | return ret; | 
|  | 5246 | } | 
|  | 5247 |  | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5248 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) | 
|  | 5249 | { | 
|  | 5250 | struct nfs4_exception exception = { }; | 
|  | 5251 | ssize_t ret; | 
|  | 5252 | do { | 
|  | 5253 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5254 | trace_nfs4_get_acl(inode, ret); | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5255 | if (ret >= 0) | 
|  | 5256 | break; | 
|  | 5257 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); | 
|  | 5258 | } while (exception.retry); | 
|  | 5259 | return ret; | 
|  | 5260 | } | 
|  | 5261 |  | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5262 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) | 
|  | 5263 | { | 
|  | 5264 | struct nfs_server *server = NFS_SERVER(inode); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5265 | int ret; | 
|  | 5266 |  | 
|  | 5267 | if (!nfs4_server_supports_acls(server)) | 
|  | 5268 | return -EOPNOTSUPP; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5269 | ret = nfs_revalidate_inode(server, inode); | 
|  | 5270 | if (ret < 0) | 
|  | 5271 | return ret; | 
| Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5272 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) | 
|  | 5273 | nfs_zap_acl_cache(inode); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5274 | ret = nfs4_read_cached_acl(inode, buf, buflen); | 
|  | 5275 | if (ret != -ENOENT) | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5276 | /* -ENOENT is returned if there is no ACL or if there is an ACL | 
|  | 5277 | * but no cached acl data, just the acl length */ | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5278 | return ret; | 
|  | 5279 | return nfs4_get_acl_uncached(inode, buf, buflen); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5280 | } | 
|  | 5281 |  | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5282 | 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] | 5283 | { | 
|  | 5284 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 5285 | struct page *pages[NFS4ACL_MAXPAGES]; | 
|  | 5286 | struct nfs_setaclargs arg = { | 
|  | 5287 | .fh		= NFS_FH(inode), | 
|  | 5288 | .acl_pages	= pages, | 
|  | 5289 | .acl_len	= buflen, | 
|  | 5290 | }; | 
| Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5291 | struct nfs_setaclres res; | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5292 | struct rpc_message msg = { | 
|  | 5293 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETACL], | 
|  | 5294 | .rpc_argp	= &arg, | 
| Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5295 | .rpc_resp	= &res, | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5296 | }; | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5297 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5298 | int ret, i; | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5299 |  | 
|  | 5300 | if (!nfs4_server_supports_acls(server)) | 
|  | 5301 | return -EOPNOTSUPP; | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5302 | if (npages > ARRAY_SIZE(pages)) | 
|  | 5303 | return -ERANGE; | 
| Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5304 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5305 | if (i < 0) | 
|  | 5306 | return i; | 
| Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5307 | nfs4_inode_return_delegation(inode); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5308 | 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] | 5309 |  | 
|  | 5310 | /* | 
|  | 5311 | * Free each page after tx, so the only ref left is | 
|  | 5312 | * held by the network stack | 
|  | 5313 | */ | 
|  | 5314 | for (; i > 0; i--) | 
|  | 5315 | put_page(pages[i-1]); | 
|  | 5316 |  | 
| Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5317 | /* | 
|  | 5318 | * Acl update can result in inode attribute update. | 
|  | 5319 | * so mark the attribute cache invalid. | 
|  | 5320 | */ | 
|  | 5321 | spin_lock(&inode->i_lock); | 
|  | 5322 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; | 
|  | 5323 | spin_unlock(&inode->i_lock); | 
| Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5324 | nfs_access_zap_cache(inode); | 
|  | 5325 | nfs_zap_acl_cache(inode); | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5326 | return ret; | 
|  | 5327 | } | 
|  | 5328 |  | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5329 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) | 
|  | 5330 | { | 
|  | 5331 | struct nfs4_exception exception = { }; | 
|  | 5332 | int err; | 
|  | 5333 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5334 | err = __nfs4_proc_set_acl(inode, buf, buflen); | 
|  | 5335 | trace_nfs4_set_acl(inode, err); | 
|  | 5336 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5337 | &exception); | 
|  | 5338 | } while (exception.retry); | 
|  | 5339 | return err; | 
|  | 5340 | } | 
|  | 5341 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5342 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 5343 | static int _nfs4_get_security_label(struct inode *inode, void *buf, | 
|  | 5344 | size_t buflen) | 
|  | 5345 | { | 
|  | 5346 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 5347 | struct nfs_fattr fattr; | 
|  | 5348 | struct nfs4_label label = {0, 0, buflen, buf}; | 
|  | 5349 |  | 
|  | 5350 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; | 
| Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5351 | struct nfs4_getattr_arg arg = { | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5352 | .fh		= NFS_FH(inode), | 
|  | 5353 | .bitmask	= bitmask, | 
|  | 5354 | }; | 
|  | 5355 | struct nfs4_getattr_res res = { | 
|  | 5356 | .fattr		= &fattr, | 
|  | 5357 | .label		= &label, | 
|  | 5358 | .server		= server, | 
|  | 5359 | }; | 
|  | 5360 | struct rpc_message msg = { | 
|  | 5361 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_GETATTR], | 
| Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5362 | .rpc_argp	= &arg, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5363 | .rpc_resp	= &res, | 
|  | 5364 | }; | 
|  | 5365 | int ret; | 
|  | 5366 |  | 
|  | 5367 | nfs_fattr_init(&fattr); | 
|  | 5368 |  | 
| Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5369 | 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] | 5370 | if (ret) | 
|  | 5371 | return ret; | 
|  | 5372 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) | 
|  | 5373 | return -ENOENT; | 
|  | 5374 | if (buflen < label.len) | 
|  | 5375 | return -ERANGE; | 
|  | 5376 | return 0; | 
|  | 5377 | } | 
|  | 5378 |  | 
|  | 5379 | static int nfs4_get_security_label(struct inode *inode, void *buf, | 
|  | 5380 | size_t buflen) | 
|  | 5381 | { | 
|  | 5382 | struct nfs4_exception exception = { }; | 
|  | 5383 | int err; | 
|  | 5384 |  | 
|  | 5385 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) | 
|  | 5386 | return -EOPNOTSUPP; | 
|  | 5387 |  | 
|  | 5388 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5389 | err = _nfs4_get_security_label(inode, buf, buflen); | 
|  | 5390 | trace_nfs4_get_security_label(inode, err); | 
|  | 5391 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5392 | &exception); | 
|  | 5393 | } while (exception.retry); | 
|  | 5394 | return err; | 
|  | 5395 | } | 
|  | 5396 |  | 
|  | 5397 | static int _nfs4_do_set_security_label(struct inode *inode, | 
|  | 5398 | struct nfs4_label *ilabel, | 
|  | 5399 | struct nfs_fattr *fattr, | 
|  | 5400 | struct nfs4_label *olabel) | 
|  | 5401 | { | 
|  | 5402 |  | 
|  | 5403 | struct iattr sattr = {0}; | 
|  | 5404 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 5405 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; | 
| Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5406 | struct nfs_setattrargs arg = { | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5407 | .fh		= NFS_FH(inode), | 
|  | 5408 | .iap		= &sattr, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5409 | .server		= server, | 
|  | 5410 | .bitmask	= bitmask, | 
|  | 5411 | .label		= ilabel, | 
|  | 5412 | }; | 
|  | 5413 | struct nfs_setattrres res = { | 
|  | 5414 | .fattr		= fattr, | 
|  | 5415 | .label		= olabel, | 
|  | 5416 | .server		= server, | 
|  | 5417 | }; | 
|  | 5418 | struct rpc_message msg = { | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5419 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETATTR], | 
|  | 5420 | .rpc_argp	= &arg, | 
|  | 5421 | .rpc_resp	= &res, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5422 | }; | 
|  | 5423 | int status; | 
|  | 5424 |  | 
| Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5425 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5426 |  | 
| Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5427 | 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] | 5428 | if (status) | 
|  | 5429 | dprintk("%s failed: %d\n", __func__, status); | 
|  | 5430 |  | 
|  | 5431 | return status; | 
|  | 5432 | } | 
|  | 5433 |  | 
|  | 5434 | static int nfs4_do_set_security_label(struct inode *inode, | 
|  | 5435 | struct nfs4_label *ilabel, | 
|  | 5436 | struct nfs_fattr *fattr, | 
|  | 5437 | struct nfs4_label *olabel) | 
|  | 5438 | { | 
|  | 5439 | struct nfs4_exception exception = { }; | 
|  | 5440 | int err; | 
|  | 5441 |  | 
|  | 5442 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5443 | err = _nfs4_do_set_security_label(inode, ilabel, | 
|  | 5444 | fattr, olabel); | 
|  | 5445 | trace_nfs4_set_security_label(inode, err); | 
|  | 5446 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5447 | &exception); | 
|  | 5448 | } while (exception.retry); | 
|  | 5449 | return err; | 
|  | 5450 | } | 
|  | 5451 |  | 
|  | 5452 | static int | 
| Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5453 | 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] | 5454 | { | 
|  | 5455 | struct nfs4_label ilabel, *olabel = NULL; | 
|  | 5456 | struct nfs_fattr fattr; | 
|  | 5457 | struct rpc_cred *cred; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5458 | int status; | 
|  | 5459 |  | 
|  | 5460 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) | 
|  | 5461 | return -EOPNOTSUPP; | 
|  | 5462 |  | 
|  | 5463 | nfs_fattr_init(&fattr); | 
|  | 5464 |  | 
|  | 5465 | ilabel.pi = 0; | 
|  | 5466 | ilabel.lfs = 0; | 
|  | 5467 | ilabel.label = (char *)buf; | 
|  | 5468 | ilabel.len = buflen; | 
|  | 5469 |  | 
|  | 5470 | cred = rpc_lookup_cred(); | 
|  | 5471 | if (IS_ERR(cred)) | 
|  | 5472 | return PTR_ERR(cred); | 
|  | 5473 |  | 
|  | 5474 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); | 
|  | 5475 | if (IS_ERR(olabel)) { | 
|  | 5476 | status = -PTR_ERR(olabel); | 
|  | 5477 | goto out; | 
|  | 5478 | } | 
|  | 5479 |  | 
|  | 5480 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); | 
|  | 5481 | if (status == 0) | 
|  | 5482 | nfs_setsecurity(inode, &fattr, olabel); | 
|  | 5483 |  | 
|  | 5484 | nfs4_label_free(olabel); | 
|  | 5485 | out: | 
|  | 5486 | put_rpccred(cred); | 
|  | 5487 | return status; | 
|  | 5488 | } | 
|  | 5489 | #endif	/* CONFIG_NFS_V4_SECURITY_LABEL */ | 
|  | 5490 |  | 
|  | 5491 |  | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5492 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, | 
|  | 5493 | nfs4_verifier *bootverf) | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5494 | { | 
|  | 5495 | __be32 verf[2]; | 
|  | 5496 |  | 
| Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5497 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { | 
|  | 5498 | /* An impossible timestamp guarantees this value | 
|  | 5499 | * will never match a generated boot time. */ | 
| Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5500 | verf[0] = cpu_to_be32(U32_MAX); | 
|  | 5501 | verf[1] = cpu_to_be32(U32_MAX); | 
| Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5502 | } else { | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5503 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); | 
| Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5504 | u64 ns = ktime_to_ns(nn->boot_time); | 
|  | 5505 |  | 
|  | 5506 | verf[0] = cpu_to_be32(ns >> 32); | 
|  | 5507 | verf[1] = cpu_to_be32(ns); | 
| Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5508 | } | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5509 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); | 
|  | 5510 | } | 
|  | 5511 |  | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5512 | static int | 
|  | 5513 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5514 | { | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5515 | size_t len; | 
|  | 5516 | char *str; | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5517 |  | 
| Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5518 | if (clp->cl_owner_id != NULL) | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5519 | return 0; | 
| Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5520 |  | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5521 | rcu_read_lock(); | 
| Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5522 | len = 14 + strlen(clp->cl_ipaddr) + 1 + | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5523 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + | 
|  | 5524 | 1 + | 
|  | 5525 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + | 
|  | 5526 | 1; | 
|  | 5527 | rcu_read_unlock(); | 
|  | 5528 |  | 
|  | 5529 | if (len > NFS4_OPAQUE_LIMIT + 1) | 
|  | 5530 | return -EINVAL; | 
|  | 5531 |  | 
|  | 5532 | /* | 
|  | 5533 | * Since this string is allocated at mount time, and held until the | 
|  | 5534 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying | 
|  | 5535 | * about a memory-reclaim deadlock. | 
|  | 5536 | */ | 
|  | 5537 | str = kmalloc(len, GFP_KERNEL); | 
|  | 5538 | if (!str) | 
|  | 5539 | return -ENOMEM; | 
| Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5540 |  | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5541 | rcu_read_lock(); | 
| Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5542 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5543 | clp->cl_ipaddr, | 
|  | 5544 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), | 
|  | 5545 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5546 | rcu_read_unlock(); | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5547 |  | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5548 | clp->cl_owner_id = str; | 
|  | 5549 | return 0; | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5550 | } | 
|  | 5551 |  | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5552 | static int | 
|  | 5553 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5554 | { | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5555 | size_t len; | 
|  | 5556 | char *str; | 
|  | 5557 |  | 
|  | 5558 | len = 10 + 10 + 1 + 10 + 1 + | 
|  | 5559 | strlen(nfs4_client_id_uniquifier) + 1 + | 
|  | 5560 | strlen(clp->cl_rpcclient->cl_nodename) + 1; | 
|  | 5561 |  | 
|  | 5562 | if (len > NFS4_OPAQUE_LIMIT + 1) | 
|  | 5563 | return -EINVAL; | 
|  | 5564 |  | 
|  | 5565 | /* | 
|  | 5566 | * Since this string is allocated at mount time, and held until the | 
|  | 5567 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying | 
|  | 5568 | * about a memory-reclaim deadlock. | 
|  | 5569 | */ | 
|  | 5570 | str = kmalloc(len, GFP_KERNEL); | 
|  | 5571 | if (!str) | 
|  | 5572 | return -ENOMEM; | 
|  | 5573 |  | 
| Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5574 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5575 | clp->rpc_ops->version, clp->cl_minorversion, | 
|  | 5576 | nfs4_client_id_uniquifier, | 
|  | 5577 | clp->cl_rpcclient->cl_nodename); | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5578 | clp->cl_owner_id = str; | 
|  | 5579 | return 0; | 
|  | 5580 | } | 
|  | 5581 |  | 
|  | 5582 | static int | 
|  | 5583 | nfs4_init_uniform_client_string(struct nfs_client *clp) | 
|  | 5584 | { | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5585 | size_t len; | 
|  | 5586 | char *str; | 
| Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5587 |  | 
|  | 5588 | if (clp->cl_owner_id != NULL) | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5589 | return 0; | 
| Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5590 |  | 
|  | 5591 | if (nfs4_client_id_uniquifier[0] != '\0') | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5592 | return nfs4_init_uniquifier_client_string(clp); | 
|  | 5593 |  | 
|  | 5594 | len = 10 + 10 + 1 + 10 + 1 + | 
|  | 5595 | strlen(clp->cl_rpcclient->cl_nodename) + 1; | 
|  | 5596 |  | 
|  | 5597 | if (len > NFS4_OPAQUE_LIMIT + 1) | 
|  | 5598 | return -EINVAL; | 
|  | 5599 |  | 
|  | 5600 | /* | 
|  | 5601 | * Since this string is allocated at mount time, and held until the | 
|  | 5602 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying | 
|  | 5603 | * about a memory-reclaim deadlock. | 
|  | 5604 | */ | 
|  | 5605 | str = kmalloc(len, GFP_KERNEL); | 
|  | 5606 | if (!str) | 
|  | 5607 | return -ENOMEM; | 
|  | 5608 |  | 
| Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5609 | scnprintf(str, len, "Linux NFSv%u.%u %s", | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5610 | clp->rpc_ops->version, clp->cl_minorversion, | 
|  | 5611 | clp->cl_rpcclient->cl_nodename); | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5612 | clp->cl_owner_id = str; | 
|  | 5613 | return 0; | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5614 | } | 
|  | 5615 |  | 
| Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5616 | /* | 
|  | 5617 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback | 
|  | 5618 | * services.  Advertise one based on the address family of the | 
|  | 5619 | * clientaddr. | 
|  | 5620 | */ | 
|  | 5621 | static unsigned int | 
|  | 5622 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) | 
|  | 5623 | { | 
|  | 5624 | if (strchr(clp->cl_ipaddr, ':') != NULL) | 
|  | 5625 | return scnprintf(buf, len, "tcp6"); | 
|  | 5626 | else | 
|  | 5627 | return scnprintf(buf, len, "tcp"); | 
|  | 5628 | } | 
|  | 5629 |  | 
| Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5630 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) | 
|  | 5631 | { | 
|  | 5632 | struct nfs4_setclientid *sc = calldata; | 
|  | 5633 |  | 
|  | 5634 | if (task->tk_status == 0) | 
|  | 5635 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); | 
|  | 5636 | } | 
|  | 5637 |  | 
|  | 5638 | static const struct rpc_call_ops nfs4_setclientid_ops = { | 
|  | 5639 | .rpc_call_done = nfs4_setclientid_done, | 
|  | 5640 | }; | 
|  | 5641 |  | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5642 | /** | 
|  | 5643 | * nfs4_proc_setclientid - Negotiate client ID | 
|  | 5644 | * @clp: state data structure | 
|  | 5645 | * @program: RPC program for NFSv4 callback service | 
|  | 5646 | * @port: IP port number for NFS4 callback service | 
|  | 5647 | * @cred: RPC credential to use for this call | 
|  | 5648 | * @res: where to place the result | 
|  | 5649 | * | 
|  | 5650 | * Returns zero, a negative errno, or a negative NFS4ERR status code. | 
|  | 5651 | */ | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5652 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, | 
|  | 5653 | unsigned short port, struct rpc_cred *cred, | 
|  | 5654 | struct nfs4_setclientid_res *res) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5655 | { | 
|  | 5656 | nfs4_verifier sc_verifier; | 
|  | 5657 | struct nfs4_setclientid setclientid = { | 
|  | 5658 | .sc_verifier = &sc_verifier, | 
|  | 5659 | .sc_prog = program, | 
| Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5660 | .sc_clnt = clp, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | }; | 
|  | 5662 | struct rpc_message msg = { | 
|  | 5663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], | 
|  | 5664 | .rpc_argp = &setclientid, | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5665 | .rpc_resp = res, | 
| Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5666 | .rpc_cred = cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | }; | 
| Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5668 | struct rpc_task *task; | 
|  | 5669 | struct rpc_task_setup task_setup_data = { | 
|  | 5670 | .rpc_client = clp->cl_rpcclient, | 
|  | 5671 | .rpc_message = &msg, | 
|  | 5672 | .callback_ops = &nfs4_setclientid_ops, | 
|  | 5673 | .callback_data = &setclientid, | 
|  | 5674 | .flags = RPC_TASK_TIMEOUT, | 
|  | 5675 | }; | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5676 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 |  | 
| Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5678 | /* nfs_client_id4 */ | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5679 | nfs4_init_boot_verifier(clp, &sc_verifier); | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5680 |  | 
|  | 5681 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) | 
|  | 5682 | status = nfs4_init_uniform_client_string(clp); | 
|  | 5683 | else | 
| Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5684 | status = nfs4_init_nonuniform_client_string(clp); | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5685 |  | 
|  | 5686 | if (status) | 
|  | 5687 | goto out; | 
| Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5688 |  | 
| Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5689 | /* cb_client4 */ | 
| Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5690 | setclientid.sc_netid_len = | 
|  | 5691 | nfs4_init_callback_netid(clp, | 
|  | 5692 | setclientid.sc_netid, | 
|  | 5693 | sizeof(setclientid.sc_netid)); | 
| Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5694 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, | 
| Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5695 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | clp->cl_ipaddr, port >> 8, port & 255); | 
|  | 5697 |  | 
| Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5698 | dprintk("NFS call  setclientid auth=%s, '%s'\n", | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5699 | clp->cl_rpcclient->cl_auth->au_ops->au_name, | 
| Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5700 | clp->cl_owner_id); | 
| Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5701 | task = rpc_run_task(&task_setup_data); | 
|  | 5702 | if (IS_ERR(task)) { | 
|  | 5703 | status = PTR_ERR(task); | 
|  | 5704 | goto out; | 
|  | 5705 | } | 
|  | 5706 | status = task->tk_status; | 
|  | 5707 | if (setclientid.sc_cred) { | 
|  | 5708 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); | 
|  | 5709 | put_rpccred(setclientid.sc_cred); | 
|  | 5710 | } | 
|  | 5711 | rpc_put_task(task); | 
|  | 5712 | out: | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5713 | trace_nfs4_setclientid(clp, status); | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5714 | dprintk("NFS reply setclientid: %d\n", status); | 
|  | 5715 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | } | 
|  | 5717 |  | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5718 | /** | 
|  | 5719 | * nfs4_proc_setclientid_confirm - Confirm client ID | 
|  | 5720 | * @clp: state data structure | 
|  | 5721 | * @res: result of a previous SETCLIENTID | 
|  | 5722 | * @cred: RPC credential to use for this call | 
|  | 5723 | * | 
|  | 5724 | * Returns zero, a negative errno, or a negative NFS4ERR status code. | 
|  | 5725 | */ | 
| Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5726 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5727 | struct nfs4_setclientid_res *arg, | 
|  | 5728 | struct rpc_cred *cred) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5729 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | struct rpc_message msg = { | 
|  | 5731 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5732 | .rpc_argp = arg, | 
| Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5733 | .rpc_cred = cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | int status; | 
|  | 5736 |  | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5737 | dprintk("NFS call  setclientid_confirm auth=%s, (client ID %llx)\n", | 
|  | 5738 | clp->cl_rpcclient->cl_auth->au_ops->au_name, | 
|  | 5739 | clp->cl_clientid); | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5740 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5741 | trace_nfs4_setclientid_confirm(clp, status); | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5742 | dprintk("NFS reply setclientid_confirm: %d\n", status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5743 | return status; | 
|  | 5744 | } | 
|  | 5745 |  | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5746 | struct nfs4_delegreturndata { | 
|  | 5747 | struct nfs4_delegreturnargs args; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5748 | struct nfs4_delegreturnres res; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5749 | struct nfs_fh fh; | 
|  | 5750 | nfs4_stateid stateid; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5751 | unsigned long timestamp; | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5752 | struct { | 
|  | 5753 | struct nfs4_layoutreturn_args arg; | 
|  | 5754 | struct nfs4_layoutreturn_res res; | 
| Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5755 | struct nfs4_xdr_opaque_data ld_private; | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5756 | u32 roc_barrier; | 
|  | 5757 | bool roc; | 
|  | 5758 | } lr; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5759 | struct nfs_fattr fattr; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5760 | int rpc_status; | 
| Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5761 | struct inode *inode; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5762 | }; | 
|  | 5763 |  | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5764 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) | 
|  | 5765 | { | 
|  | 5766 | struct nfs4_delegreturndata *data = calldata; | 
| Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame^] | 5767 | struct nfs4_exception exception = { | 
|  | 5768 | .inode = data->inode, | 
|  | 5769 | .stateid = &data->stateid, | 
|  | 5770 | }; | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5771 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5772 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 5773 | return; | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5774 |  | 
| Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5775 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5776 |  | 
|  | 5777 | /* Handle Layoutreturn errors */ | 
|  | 5778 | if (data->args.lr_args && task->tk_status != 0) { | 
|  | 5779 | switch(data->res.lr_ret) { | 
|  | 5780 | default: | 
|  | 5781 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; | 
|  | 5782 | break; | 
|  | 5783 | case 0: | 
|  | 5784 | data->args.lr_args = NULL; | 
|  | 5785 | data->res.lr_res = NULL; | 
|  | 5786 | break; | 
| Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5787 | case -NFS4ERR_OLD_STATEID: | 
|  | 5788 | if (nfs4_refresh_layout_stateid(&data->args.lr_args->stateid, | 
| Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5789 | data->inode)) | 
|  | 5790 | goto lr_restart; | 
| Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5791 | /* Fallthrough */ | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5792 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 5793 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 5794 | case -NFS4ERR_EXPIRED: | 
|  | 5795 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5796 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: | 
|  | 5797 | case -NFS4ERR_WRONG_CRED: | 
|  | 5798 | data->args.lr_args = NULL; | 
|  | 5799 | data->res.lr_res = NULL; | 
| Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5800 | goto lr_restart; | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5801 | } | 
|  | 5802 | } | 
|  | 5803 |  | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5804 | switch (task->tk_status) { | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5805 | case 0: | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5806 | renew_lease(data->res.server, data->timestamp); | 
| Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5807 | break; | 
| Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5808 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 5809 | case -NFS4ERR_DELEG_REVOKED: | 
| Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5810 | case -NFS4ERR_EXPIRED: | 
|  | 5811 | nfs4_free_revoked_stateid(data->res.server, | 
|  | 5812 | data->args.stateid, | 
|  | 5813 | task->tk_msg.rpc_cred); | 
| Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5814 | /* Fallthrough */ | 
| Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5815 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5816 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5817 | task->tk_status = 0; | 
|  | 5818 | break; | 
| Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5819 | case -NFS4ERR_OLD_STATEID: | 
| Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5820 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) | 
|  | 5821 | goto out_restart; | 
| Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5822 | task->tk_status = 0; | 
|  | 5823 | break; | 
| Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5824 | case -NFS4ERR_ACCESS: | 
|  | 5825 | if (data->args.bitmask) { | 
|  | 5826 | data->args.bitmask = NULL; | 
|  | 5827 | data->res.fattr = NULL; | 
| Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5828 | goto out_restart; | 
| Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5829 | } | 
| Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5830 | /* Fallthrough */ | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5831 | default: | 
| Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame^] | 5832 | task->tk_status = nfs4_async_handle_exception(task, | 
|  | 5833 | data->res.server, task->tk_status, | 
|  | 5834 | &exception); | 
|  | 5835 | if (exception.retry) | 
| Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5836 | goto out_restart; | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5837 | } | 
|  | 5838 | data->rpc_status = task->tk_status; | 
| Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5839 | return; | 
|  | 5840 | lr_restart: | 
|  | 5841 | data->res.lr_ret = 0; | 
|  | 5842 | out_restart: | 
|  | 5843 | task->tk_status = 0; | 
|  | 5844 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5845 | } | 
|  | 5846 |  | 
|  | 5847 | static void nfs4_delegreturn_release(void *calldata) | 
|  | 5848 | { | 
| Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5849 | struct nfs4_delegreturndata *data = calldata; | 
| Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5850 | struct inode *inode = data->inode; | 
| Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5851 |  | 
| Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5852 | if (inode) { | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5853 | if (data->lr.roc) | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5854 | pnfs_roc_release(&data->lr.arg, &data->lr.res, | 
|  | 5855 | data->res.lr_ret); | 
| Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5856 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); | 
| Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5857 | nfs_iput_and_deactive(inode); | 
|  | 5858 | } | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5859 | kfree(calldata); | 
|  | 5860 | } | 
|  | 5861 |  | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5862 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) | 
|  | 5863 | { | 
|  | 5864 | struct nfs4_delegreturndata *d_data; | 
|  | 5865 |  | 
|  | 5866 | d_data = (struct nfs4_delegreturndata *)data; | 
|  | 5867 |  | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5868 | 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] | 5869 | return; | 
|  | 5870 |  | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5871 | nfs4_setup_sequence(d_data->res.server->nfs_client, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5872 | &d_data->args.seq_args, | 
|  | 5873 | &d_data->res.seq_res, | 
|  | 5874 | task); | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5875 | } | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5876 |  | 
| Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5877 | static const struct rpc_call_ops nfs4_delegreturn_ops = { | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5878 | .rpc_call_prepare = nfs4_delegreturn_prepare, | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5879 | .rpc_call_done = nfs4_delegreturn_done, | 
|  | 5880 | .rpc_release = nfs4_delegreturn_release, | 
|  | 5881 | }; | 
|  | 5882 |  | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5883 | 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] | 5884 | { | 
|  | 5885 | struct nfs4_delegreturndata *data; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5886 | struct nfs_server *server = NFS_SERVER(inode); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5887 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5888 | struct rpc_message msg = { | 
|  | 5889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], | 
|  | 5890 | .rpc_cred = cred, | 
|  | 5891 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5892 | struct rpc_task_setup task_setup_data = { | 
|  | 5893 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5894 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5895 | .callback_ops = &nfs4_delegreturn_ops, | 
|  | 5896 | .flags = RPC_TASK_ASYNC, | 
|  | 5897 | }; | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5898 | int status = 0; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5899 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5900 | data = kzalloc(sizeof(*data), GFP_NOFS); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5901 | if (data == NULL) | 
|  | 5902 | return -ENOMEM; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5903 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5904 |  | 
|  | 5905 | nfs4_state_protect(server->nfs_client, | 
|  | 5906 | NFS_SP4_MACH_CRED_CLEANUP, | 
|  | 5907 | &task_setup_data.rpc_client, &msg); | 
|  | 5908 |  | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5909 | data->args.fhandle = &data->fh; | 
|  | 5910 | data->args.stateid = &data->stateid; | 
| Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5911 | data->args.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5912 | nfs_copy_fh(&data->fh, NFS_FH(inode)); | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5913 | nfs4_stateid_copy(&data->stateid, stateid); | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5914 | data->res.fattr = &data->fattr; | 
|  | 5915 | data->res.server = server; | 
| Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5916 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; | 
| Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5917 | data->lr.arg.ld_private = &data->lr.ld_private; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5918 | nfs_fattr_init(data->res.fattr); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5919 | data->timestamp = jiffies; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5920 | data->rpc_status = 0; | 
| Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5921 | 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] | 5922 | data->inode = nfs_igrab_and_active(inode); | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5923 | if (data->inode) { | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5924 | if (data->lr.roc) { | 
|  | 5925 | data->args.lr_args = &data->lr.arg; | 
|  | 5926 | data->res.lr_res = &data->lr.res; | 
|  | 5927 | } | 
| Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5928 | } else if (data->lr.roc) { | 
|  | 5929 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); | 
|  | 5930 | data->lr.roc = false; | 
| Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5931 | } | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5932 |  | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5933 | task_setup_data.callback_data = data; | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5934 | msg.rpc_argp = &data->args; | 
|  | 5935 | msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5936 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5937 | if (IS_ERR(task)) | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5938 | return PTR_ERR(task); | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5939 | if (!issync) | 
|  | 5940 | goto out; | 
| Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5941 | status = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5942 | if (status != 0) | 
|  | 5943 | goto out; | 
|  | 5944 | status = data->rpc_status; | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5945 | out: | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5946 | rpc_put_task(task); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5947 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5948 | } | 
|  | 5949 |  | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5950 | 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] | 5951 | { | 
|  | 5952 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 5953 | struct nfs4_exception exception = { }; | 
|  | 5954 | int err; | 
|  | 5955 | do { | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5956 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); | 
| Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5957 | trace_nfs4_delegreturn(inode, stateid, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5958 | switch (err) { | 
|  | 5959 | case -NFS4ERR_STALE_STATEID: | 
|  | 5960 | case -NFS4ERR_EXPIRED: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5961 | case 0: | 
|  | 5962 | return 0; | 
|  | 5963 | } | 
|  | 5964 | err = nfs4_handle_exception(server, err, &exception); | 
|  | 5965 | } while (exception.retry); | 
|  | 5966 | return err; | 
|  | 5967 | } | 
|  | 5968 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 5970 | { | 
|  | 5971 | struct inode *inode = state->inode; | 
|  | 5972 | struct nfs_server *server = NFS_SERVER(inode); | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5973 | struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5974 | struct nfs_lockt_args arg = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5975 | .fh = NFS_FH(inode), | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5976 | .fl = request, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | }; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5978 | struct nfs_lockt_res res = { | 
|  | 5979 | .denied = request, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5980 | }; | 
|  | 5981 | struct rpc_message msg = { | 
|  | 5982 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_LOCKT], | 
| Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5983 | .rpc_argp	= &arg, | 
|  | 5984 | .rpc_resp	= &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5985 | .rpc_cred	= state->owner->so_cred, | 
|  | 5986 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | struct nfs4_lock_state *lsp; | 
|  | 5988 | int status; | 
|  | 5989 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5990 | arg.lock_owner.clientid = clp->cl_clientid; | 
| Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5991 | status = nfs4_set_lock_state(state, request); | 
|  | 5992 | if (status != 0) | 
|  | 5993 | goto out; | 
|  | 5994 | lsp = request->fl_u.nfs4_fl.owner; | 
| Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5995 | arg.lock_owner.id = lsp->ls_seqid.owner_id; | 
| Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5996 | arg.lock_owner.s_dev = server->s_dev; | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5997 | 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] | 5998 | switch (status) { | 
|  | 5999 | case 0: | 
|  | 6000 | request->fl_type = F_UNLCK; | 
|  | 6001 | break; | 
|  | 6002 | case -NFS4ERR_DENIED: | 
|  | 6003 | status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6004 | } | 
| J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6005 | request->fl_ops->fl_release_private(request); | 
| Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6006 | request->fl_ops = NULL; | 
| Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6007 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6008 | return status; | 
|  | 6009 | } | 
|  | 6010 |  | 
|  | 6011 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 6012 | { | 
|  | 6013 | struct nfs4_exception exception = { }; | 
|  | 6014 | int err; | 
|  | 6015 |  | 
|  | 6016 | do { | 
| Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6017 | err = _nfs4_proc_getlk(state, cmd, request); | 
|  | 6018 | trace_nfs4_get_lock(request, state, cmd, err); | 
|  | 6019 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | &exception); | 
|  | 6021 | } while (exception.retry); | 
|  | 6022 | return err; | 
|  | 6023 | } | 
|  | 6024 |  | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6025 | struct nfs4_unlockdata { | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6026 | struct nfs_locku_args arg; | 
|  | 6027 | struct nfs_locku_res res; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6028 | struct nfs4_lock_state *lsp; | 
|  | 6029 | struct nfs_open_context *ctx; | 
| Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6030 | struct nfs_lock_context *l_ctx; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6031 | struct file_lock fl; | 
| Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6032 | struct nfs_server *server; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6033 | unsigned long timestamp; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6034 | }; | 
|  | 6035 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6036 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, | 
|  | 6037 | struct nfs_open_context *ctx, | 
|  | 6038 | struct nfs4_lock_state *lsp, | 
|  | 6039 | struct nfs_seqid *seqid) | 
|  | 6040 | { | 
|  | 6041 | struct nfs4_unlockdata *p; | 
|  | 6042 | struct inode *inode = lsp->ls_state->inode; | 
|  | 6043 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6044 | p = kzalloc(sizeof(*p), GFP_NOFS); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6045 | if (p == NULL) | 
|  | 6046 | return NULL; | 
|  | 6047 | p->arg.fh = NFS_FH(inode); | 
|  | 6048 | p->arg.fl = &p->fl; | 
|  | 6049 | p->arg.seqid = seqid; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6050 | p->res.seqid = seqid; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6051 | p->lsp = lsp; | 
| Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6052 | refcount_inc(&lsp->ls_count); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6053 | /* Ensure we don't close file until we're done freeing locks! */ | 
|  | 6054 | p->ctx = get_nfs_open_context(ctx); | 
| Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6055 | p->l_ctx = nfs_get_lock_context(ctx); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6056 | memcpy(&p->fl, fl, sizeof(p->fl)); | 
|  | 6057 | p->server = NFS_SERVER(inode); | 
|  | 6058 | return p; | 
|  | 6059 | } | 
|  | 6060 |  | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6061 | static void nfs4_locku_release_calldata(void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6062 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6063 | struct nfs4_unlockdata *calldata = data; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6064 | nfs_free_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6065 | nfs4_put_lock_state(calldata->lsp); | 
| Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6066 | nfs_put_lock_context(calldata->l_ctx); | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6067 | put_nfs_open_context(calldata->ctx); | 
|  | 6068 | kfree(calldata); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6069 | } | 
|  | 6070 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6071 | static void nfs4_locku_done(struct rpc_task *task, void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6072 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6073 | struct nfs4_unlockdata *calldata = data; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6074 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6075 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) | 
|  | 6076 | return; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6077 | switch (task->tk_status) { | 
|  | 6078 | case 0: | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6079 | renew_lease(calldata->server, calldata->timestamp); | 
| Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6080 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); | 
| Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6081 | if (nfs4_update_lock_stateid(calldata->lsp, | 
|  | 6082 | &calldata->res.stateid)) | 
|  | 6083 | break; | 
| Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6084 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 6085 | case -NFS4ERR_EXPIRED: | 
|  | 6086 | nfs4_free_revoked_stateid(calldata->server, | 
|  | 6087 | &calldata->arg.stateid, | 
|  | 6088 | task->tk_msg.rpc_cred); | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6089 | case -NFS4ERR_BAD_STATEID: | 
|  | 6090 | case -NFS4ERR_OLD_STATEID: | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6091 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6092 | if (!nfs4_stateid_match(&calldata->arg.stateid, | 
|  | 6093 | &calldata->lsp->ls_stateid)) | 
|  | 6094 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6095 | break; | 
|  | 6096 | default: | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6097 | if (nfs4_async_handle_error(task, calldata->server, | 
|  | 6098 | NULL, NULL) == -EAGAIN) | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6099 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6100 | } | 
| Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6101 | nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6102 | } | 
|  | 6103 |  | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6104 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6105 | { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6106 | struct nfs4_unlockdata *calldata = data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6107 |  | 
| Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6108 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && | 
|  | 6109 | nfs_async_iocounter_wait(task, calldata->l_ctx)) | 
|  | 6110 | return; | 
|  | 6111 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6112 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6113 | goto out_wait; | 
| Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6114 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); | 
| Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6115 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6116 | /* Note: exit _without_ running nfs4_locku_done */ | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6117 | goto out_no_action; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6118 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6119 | calldata->timestamp = jiffies; | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6120 | if (nfs4_setup_sequence(calldata->server->nfs_client, | 
| Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6121 | &calldata->arg.seq_args, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6122 | &calldata->res.seq_res, | 
|  | 6123 | task) != 0) | 
|  | 6124 | nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6125 | return; | 
|  | 6126 | out_no_action: | 
|  | 6127 | task->tk_action = NULL; | 
|  | 6128 | out_wait: | 
|  | 6129 | nfs4_sequence_done(task, &calldata->res.seq_res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | } | 
|  | 6131 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6132 | static const struct rpc_call_ops nfs4_locku_ops = { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6133 | .rpc_call_prepare = nfs4_locku_prepare, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6134 | .rpc_call_done = nfs4_locku_done, | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6135 | .rpc_release = nfs4_locku_release_calldata, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6136 | }; | 
|  | 6137 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6138 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, | 
|  | 6139 | struct nfs_open_context *ctx, | 
|  | 6140 | struct nfs4_lock_state *lsp, | 
|  | 6141 | struct nfs_seqid *seqid) | 
|  | 6142 | { | 
|  | 6143 | struct nfs4_unlockdata *data; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6144 | struct rpc_message msg = { | 
|  | 6145 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], | 
|  | 6146 | .rpc_cred = ctx->cred, | 
|  | 6147 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6148 | struct rpc_task_setup task_setup_data = { | 
|  | 6149 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6150 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6151 | .callback_ops = &nfs4_locku_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6152 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6153 | .flags = RPC_TASK_ASYNC, | 
|  | 6154 | }; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6155 |  | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6156 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, | 
|  | 6157 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); | 
|  | 6158 |  | 
| Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6159 | /* Ensure this is an unlock - when canceling a lock, the | 
|  | 6160 | * canceled lock is passed in, and it won't be an unlock. | 
|  | 6161 | */ | 
|  | 6162 | fl->fl_type = F_UNLCK; | 
| Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6163 | if (fl->fl_flags & FL_CLOSE) | 
|  | 6164 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); | 
| Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6165 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6166 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); | 
|  | 6167 | if (data == NULL) { | 
|  | 6168 | nfs_free_seqid(seqid); | 
|  | 6169 | return ERR_PTR(-ENOMEM); | 
|  | 6170 | } | 
|  | 6171 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6172 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6173 | msg.rpc_argp = &data->arg; | 
|  | 6174 | msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6175 | task_setup_data.callback_data = data; | 
|  | 6176 | return rpc_run_task(&task_setup_data); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6177 | } | 
|  | 6178 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6179 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 6180 | { | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6181 | struct inode *inode = state->inode; | 
|  | 6182 | struct nfs4_state_owner *sp = state->owner; | 
|  | 6183 | struct nfs_inode *nfsi = NFS_I(inode); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6184 | struct nfs_seqid *seqid; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6185 | struct nfs4_lock_state *lsp; | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6186 | struct rpc_task *task; | 
| Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6187 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6188 | int status = 0; | 
| Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6189 | unsigned char fl_flags = request->fl_flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6190 |  | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6191 | status = nfs4_set_lock_state(state, request); | 
|  | 6192 | /* Unlock _before_ we do the RPC call */ | 
|  | 6193 | request->fl_flags |= FL_EXISTS; | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6194 | /* Exclude nfs_delegation_claim_locks() */ | 
|  | 6195 | mutex_lock(&sp->so_delegreturn_mutex); | 
|  | 6196 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6197 | down_read(&nfsi->rwsem); | 
| Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6198 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6199 | up_read(&nfsi->rwsem); | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6200 | mutex_unlock(&sp->so_delegreturn_mutex); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6201 | goto out; | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6202 | } | 
|  | 6203 | up_read(&nfsi->rwsem); | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6204 | mutex_unlock(&sp->so_delegreturn_mutex); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6205 | if (status != 0) | 
|  | 6206 | goto out; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6207 | /* Is this a delegated lock? */ | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6208 | lsp = request->fl_u.nfs4_fl.owner; | 
| Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6209 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) | 
|  | 6210 | goto out; | 
| Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6211 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; | 
|  | 6212 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6213 | status = -ENOMEM; | 
| Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6214 | if (IS_ERR(seqid)) | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6215 | goto out; | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6216 | 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] | 6217 | status = PTR_ERR(task); | 
|  | 6218 | if (IS_ERR(task)) | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6219 | goto out; | 
| Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6220 | status = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6221 | rpc_put_task(task); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6222 | out: | 
| Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6223 | request->fl_flags = fl_flags; | 
| Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6224 | trace_nfs4_unlock(request, state, F_SETLK, status); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6225 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | } | 
|  | 6227 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6228 | struct nfs4_lockdata { | 
|  | 6229 | struct nfs_lock_args arg; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6230 | struct nfs_lock_res res; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6231 | struct nfs4_lock_state *lsp; | 
|  | 6232 | struct nfs_open_context *ctx; | 
|  | 6233 | struct file_lock fl; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6234 | unsigned long timestamp; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6235 | int rpc_status; | 
|  | 6236 | int cancelled; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6237 | struct nfs_server *server; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6238 | }; | 
|  | 6239 |  | 
|  | 6240 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6241 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, | 
|  | 6242 | gfp_t gfp_mask) | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6243 | { | 
|  | 6244 | struct nfs4_lockdata *p; | 
|  | 6245 | struct inode *inode = lsp->ls_state->inode; | 
|  | 6246 | struct nfs_server *server = NFS_SERVER(inode); | 
| Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6247 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6248 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6249 | p = kzalloc(sizeof(*p), gfp_mask); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6250 | if (p == NULL) | 
|  | 6251 | return NULL; | 
|  | 6252 |  | 
|  | 6253 | p->arg.fh = NFS_FH(inode); | 
|  | 6254 | p->arg.fl = &p->fl; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6255 | 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] | 6256 | if (IS_ERR(p->arg.open_seqid)) | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6257 | goto out_free; | 
| Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6258 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; | 
|  | 6259 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); | 
| Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6260 | if (IS_ERR(p->arg.lock_seqid)) | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6261 | goto out_free_seqid; | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6262 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; | 
| Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6263 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; | 
| Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6264 | p->arg.lock_owner.s_dev = server->s_dev; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6265 | p->res.lock_seqid = p->arg.lock_seqid; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6266 | p->lsp = lsp; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6267 | p->server = server; | 
| Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6268 | refcount_inc(&lsp->ls_count); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6269 | p->ctx = get_nfs_open_context(ctx); | 
|  | 6270 | memcpy(&p->fl, fl, sizeof(p->fl)); | 
|  | 6271 | return p; | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6272 | out_free_seqid: | 
|  | 6273 | nfs_free_seqid(p->arg.open_seqid); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6274 | out_free: | 
|  | 6275 | kfree(p); | 
|  | 6276 | return NULL; | 
|  | 6277 | } | 
|  | 6278 |  | 
|  | 6279 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) | 
|  | 6280 | { | 
|  | 6281 | struct nfs4_lockdata *data = calldata; | 
|  | 6282 | struct nfs4_state *state = data->lsp->ls_state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6283 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6284 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6285 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6286 | goto out_wait; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6287 | /* Do we need to do an open_to_lock_owner? */ | 
| Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6288 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6289 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6290 | goto out_release_lock_seqid; | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6291 | } | 
| Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6292 | nfs4_stateid_copy(&data->arg.open_stateid, | 
|  | 6293 | &state->open_stateid); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6294 | data->arg.new_lock_owner = 1; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6295 | data->res.open_seqid = data->arg.open_seqid; | 
| Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6296 | } else { | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6297 | data->arg.new_lock_owner = 0; | 
| Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6298 | nfs4_stateid_copy(&data->arg.lock_stateid, | 
|  | 6299 | &data->lsp->ls_stateid); | 
|  | 6300 | } | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6301 | if (!nfs4_valid_open_stateid(state)) { | 
|  | 6302 | data->rpc_status = -EBADF; | 
|  | 6303 | task->tk_action = NULL; | 
|  | 6304 | goto out_release_open_seqid; | 
|  | 6305 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6306 | data->timestamp = jiffies; | 
| Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6307 | if (nfs4_setup_sequence(data->server->nfs_client, | 
| Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6308 | &data->arg.seq_args, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6309 | &data->res.seq_res, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6310 | task) == 0) | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6311 | return; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6312 | out_release_open_seqid: | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6313 | nfs_release_seqid(data->arg.open_seqid); | 
|  | 6314 | out_release_lock_seqid: | 
|  | 6315 | nfs_release_seqid(data->arg.lock_seqid); | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6316 | out_wait: | 
|  | 6317 | nfs4_sequence_done(task, &data->res.seq_res); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6318 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6319 | } | 
|  | 6320 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6321 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) | 
|  | 6322 | { | 
|  | 6323 | struct nfs4_lockdata *data = calldata; | 
| Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6324 | struct nfs4_lock_state *lsp = data->lsp; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6325 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6326 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6327 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6328 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 6329 | return; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6330 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6331 | data->rpc_status = task->tk_status; | 
| Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6332 | switch (task->tk_status) { | 
|  | 6333 | case 0: | 
| David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6334 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), | 
| Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6335 | data->timestamp); | 
| Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6336 | if (data->arg.new_lock) { | 
|  | 6337 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); | 
| Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6338 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { | 
| Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6339 | rpc_restart_call_prepare(task); | 
|  | 6340 | break; | 
|  | 6341 | } | 
|  | 6342 | } | 
| Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6343 | if (data->arg.new_lock_owner != 0) { | 
|  | 6344 | nfs_confirm_seqid(&lsp->ls_seqid, 0); | 
|  | 6345 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); | 
|  | 6346 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); | 
|  | 6347 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) | 
|  | 6348 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6349 | break; | 
|  | 6350 | case -NFS4ERR_BAD_STATEID: | 
|  | 6351 | case -NFS4ERR_OLD_STATEID: | 
|  | 6352 | case -NFS4ERR_STALE_STATEID: | 
|  | 6353 | case -NFS4ERR_EXPIRED: | 
|  | 6354 | if (data->arg.new_lock_owner != 0) { | 
|  | 6355 | if (!nfs4_stateid_match(&data->arg.open_stateid, | 
|  | 6356 | &lsp->ls_state->open_stateid)) | 
|  | 6357 | rpc_restart_call_prepare(task); | 
|  | 6358 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, | 
|  | 6359 | &lsp->ls_stateid)) | 
|  | 6360 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6361 | } | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6362 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6363 | } | 
|  | 6364 |  | 
|  | 6365 | static void nfs4_lock_release(void *calldata) | 
|  | 6366 | { | 
|  | 6367 | struct nfs4_lockdata *data = calldata; | 
|  | 6368 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6369 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6370 | nfs_free_seqid(data->arg.open_seqid); | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6371 | if (data->cancelled) { | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6372 | struct rpc_task *task; | 
|  | 6373 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, | 
|  | 6374 | data->arg.lock_seqid); | 
|  | 6375 | if (!IS_ERR(task)) | 
| Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6376 | rpc_put_task_async(task); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6377 | dprintk("%s: cancelling lock!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6378 | } else | 
|  | 6379 | nfs_free_seqid(data->arg.lock_seqid); | 
|  | 6380 | nfs4_put_lock_state(data->lsp); | 
|  | 6381 | put_nfs_open_context(data->ctx); | 
|  | 6382 | kfree(data); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6383 | dprintk("%s: done!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6384 | } | 
|  | 6385 |  | 
|  | 6386 | static const struct rpc_call_ops nfs4_lock_ops = { | 
|  | 6387 | .rpc_call_prepare = nfs4_lock_prepare, | 
|  | 6388 | .rpc_call_done = nfs4_lock_done, | 
|  | 6389 | .rpc_release = nfs4_lock_release, | 
|  | 6390 | }; | 
|  | 6391 |  | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6392 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) | 
|  | 6393 | { | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6394 | switch (error) { | 
|  | 6395 | case -NFS4ERR_ADMIN_REVOKED: | 
| Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6396 | case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6397 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6398 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6399 | if (new_lock_owner != 0 || | 
| Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6400 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) | 
| Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6401 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6402 | break; | 
|  | 6403 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6404 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; | 
| Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6405 | nfs4_schedule_lease_recovery(server->nfs_client); | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6406 | }; | 
|  | 6407 | } | 
|  | 6408 |  | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6409 | 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] | 6410 | { | 
|  | 6411 | struct nfs4_lockdata *data; | 
|  | 6412 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6413 | struct rpc_message msg = { | 
|  | 6414 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], | 
|  | 6415 | .rpc_cred = state->owner->so_cred, | 
|  | 6416 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6417 | struct rpc_task_setup task_setup_data = { | 
|  | 6418 | .rpc_client = NFS_CLIENT(state->inode), | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6419 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6420 | .callback_ops = &nfs4_lock_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6421 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6422 | .flags = RPC_TASK_ASYNC, | 
|  | 6423 | }; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6424 | int ret; | 
|  | 6425 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6426 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6427 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6428 | fl->fl_u.nfs4_fl.owner, | 
|  | 6429 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6430 | if (data == NULL) | 
|  | 6431 | return -ENOMEM; | 
|  | 6432 | if (IS_SETLKW(cmd)) | 
|  | 6433 | data->arg.block = 1; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6434 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6435 | msg.rpc_argp = &data->arg; | 
|  | 6436 | msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6437 | task_setup_data.callback_data = data; | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6438 | if (recovery_type > NFS_LOCK_NEW) { | 
|  | 6439 | if (recovery_type == NFS_LOCK_RECLAIM) | 
|  | 6440 | data->arg.reclaim = NFS_LOCK_RECLAIM; | 
|  | 6441 | nfs4_set_sequence_privileged(&data->arg.seq_args); | 
| Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6442 | } else | 
|  | 6443 | data->arg.new_lock = 1; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6444 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6445 | if (IS_ERR(task)) | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6446 | return PTR_ERR(task); | 
| Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6447 | ret = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6448 | if (ret == 0) { | 
|  | 6449 | ret = data->rpc_status; | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6450 | if (ret) | 
|  | 6451 | nfs4_handle_setlk_error(data->server, data->lsp, | 
|  | 6452 | data->arg.new_lock_owner, ret); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6453 | } else | 
| Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6454 | data->cancelled = true; | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6455 | rpc_put_task(task); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6456 | dprintk("%s: done, ret = %d!\n", __func__, ret); | 
| Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6457 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6458 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6459 | } | 
|  | 6460 |  | 
|  | 6461 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) | 
|  | 6462 | { | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6463 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6464 | struct nfs4_exception exception = { | 
|  | 6465 | .inode = state->inode, | 
|  | 6466 | }; | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6467 | int err; | 
|  | 6468 |  | 
|  | 6469 | do { | 
| Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6470 | /* Cache the lock if possible... */ | 
|  | 6471 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) | 
|  | 6472 | return 0; | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6473 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6474 | if (err != -NFS4ERR_DELAY) | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6475 | break; | 
|  | 6476 | nfs4_handle_exception(server, err, &exception); | 
|  | 6477 | } while (exception.retry); | 
|  | 6478 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6479 | } | 
|  | 6480 |  | 
|  | 6481 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) | 
|  | 6482 | { | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6483 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6484 | struct nfs4_exception exception = { | 
|  | 6485 | .inode = state->inode, | 
|  | 6486 | }; | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6487 | int err; | 
|  | 6488 |  | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6489 | err = nfs4_set_lock_state(state, request); | 
|  | 6490 | if (err != 0) | 
|  | 6491 | return err; | 
| Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6492 | if (!recover_lost_locks) { | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6493 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); | 
|  | 6494 | return 0; | 
|  | 6495 | } | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6496 | do { | 
| Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6497 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) | 
|  | 6498 | return 0; | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6499 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6500 | switch (err) { | 
|  | 6501 | default: | 
|  | 6502 | goto out; | 
|  | 6503 | case -NFS4ERR_GRACE: | 
|  | 6504 | case -NFS4ERR_DELAY: | 
|  | 6505 | nfs4_handle_exception(server, err, &exception); | 
|  | 6506 | err = 0; | 
|  | 6507 | } | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6508 | } while (exception.retry); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6509 | out: | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6510 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6511 | } | 
|  | 6512 |  | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6513 | #if defined(CONFIG_NFS_V4_1) | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6514 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) | 
|  | 6515 | { | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6516 | struct nfs4_lock_state *lsp; | 
|  | 6517 | int status; | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6518 |  | 
| Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6519 | status = nfs4_set_lock_state(state, request); | 
|  | 6520 | if (status != 0) | 
|  | 6521 | return status; | 
|  | 6522 | lsp = request->fl_u.nfs4_fl.owner; | 
|  | 6523 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || | 
|  | 6524 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) | 
|  | 6525 | return 0; | 
| Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6526 | return nfs4_lock_expired(state, request); | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6527 | } | 
|  | 6528 | #endif | 
|  | 6529 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6530 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 6531 | { | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6532 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
| Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6533 | struct nfs4_state_owner *sp = state->owner; | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6534 | unsigned char fl_flags = request->fl_flags; | 
| Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6535 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 |  | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6537 | request->fl_flags |= FL_ACCESS; | 
| Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6538 | status = locks_lock_inode_wait(state->inode, request); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6539 | if (status < 0) | 
|  | 6540 | goto out; | 
| Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6541 | mutex_lock(&sp->so_delegreturn_mutex); | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6542 | down_read(&nfsi->rwsem); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6543 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6544 | /* Yes: cache locks! */ | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6545 | /* ...but avoid races with delegation recall... */ | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6546 | request->fl_flags = fl_flags & ~FL_SLEEP; | 
| Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6547 | status = locks_lock_inode_wait(state->inode, request); | 
| Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6548 | up_read(&nfsi->rwsem); | 
| Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6549 | mutex_unlock(&sp->so_delegreturn_mutex); | 
| Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6550 | goto out; | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6551 | } | 
| Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6552 | up_read(&nfsi->rwsem); | 
| Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6553 | mutex_unlock(&sp->so_delegreturn_mutex); | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6554 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6555 | out: | 
|  | 6556 | request->fl_flags = fl_flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6557 | return status; | 
|  | 6558 | } | 
|  | 6559 |  | 
|  | 6560 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 6561 | { | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6562 | struct nfs4_exception exception = { | 
|  | 6563 | .state = state, | 
| Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6564 | .inode = state->inode, | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6565 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | int err; | 
|  | 6567 |  | 
|  | 6568 | do { | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6569 | err = _nfs4_proc_setlk(state, cmd, request); | 
|  | 6570 | if (err == -NFS4ERR_DENIED) | 
|  | 6571 | err = -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6572 | err = nfs4_handle_exception(NFS_SERVER(state->inode), | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6573 | err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6574 | } while (exception.retry); | 
|  | 6575 | return err; | 
|  | 6576 | } | 
|  | 6577 |  | 
| Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6578 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) | 
|  | 6579 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) | 
|  | 6580 |  | 
|  | 6581 | static int | 
| Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6582 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, | 
|  | 6583 | struct file_lock *request) | 
| Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6584 | { | 
|  | 6585 | int		status = -ERESTARTSYS; | 
|  | 6586 | unsigned long	timeout = NFS4_LOCK_MINTIMEOUT; | 
|  | 6587 |  | 
|  | 6588 | while(!signalled()) { | 
|  | 6589 | status = nfs4_proc_setlk(state, cmd, request); | 
|  | 6590 | if ((status != -EAGAIN) || IS_SETLK(cmd)) | 
|  | 6591 | break; | 
|  | 6592 | freezable_schedule_timeout_interruptible(timeout); | 
|  | 6593 | timeout *= 2; | 
|  | 6594 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); | 
|  | 6595 | status = -ERESTARTSYS; | 
|  | 6596 | } | 
|  | 6597 | return status; | 
|  | 6598 | } | 
|  | 6599 |  | 
| Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6600 | #ifdef CONFIG_NFS_V4_1 | 
|  | 6601 | struct nfs4_lock_waiter { | 
|  | 6602 | struct task_struct	*task; | 
|  | 6603 | struct inode		*inode; | 
|  | 6604 | struct nfs_lowner	*owner; | 
|  | 6605 | bool			notified; | 
|  | 6606 | }; | 
|  | 6607 |  | 
|  | 6608 | static int | 
| Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6609 | 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] | 6610 | { | 
|  | 6611 | int ret; | 
|  | 6612 | struct cb_notify_lock_args *cbnl = key; | 
|  | 6613 | struct nfs4_lock_waiter	*waiter	= wait->private; | 
|  | 6614 | struct nfs_lowner	*lowner = &cbnl->cbnl_owner, | 
|  | 6615 | *wowner = waiter->owner; | 
|  | 6616 |  | 
|  | 6617 | /* Only wake if the callback was for the same owner */ | 
|  | 6618 | if (lowner->clientid != wowner->clientid || | 
|  | 6619 | lowner->id != wowner->id		 || | 
|  | 6620 | lowner->s_dev != wowner->s_dev) | 
|  | 6621 | return 0; | 
|  | 6622 |  | 
|  | 6623 | /* Make sure it's for the right inode */ | 
|  | 6624 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) | 
|  | 6625 | return 0; | 
|  | 6626 |  | 
|  | 6627 | waiter->notified = true; | 
|  | 6628 |  | 
|  | 6629 | /* override "private" so we can use default_wake_function */ | 
|  | 6630 | wait->private = waiter->task; | 
|  | 6631 | ret = autoremove_wake_function(wait, mode, flags, key); | 
|  | 6632 | wait->private = waiter; | 
|  | 6633 | return ret; | 
|  | 6634 | } | 
|  | 6635 |  | 
|  | 6636 | static int | 
|  | 6637 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 6638 | { | 
|  | 6639 | int status = -ERESTARTSYS; | 
|  | 6640 | unsigned long flags; | 
|  | 6641 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; | 
|  | 6642 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 6643 | struct nfs_client *clp = server->nfs_client; | 
|  | 6644 | wait_queue_head_t *q = &clp->cl_lock_waitq; | 
|  | 6645 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, | 
|  | 6646 | .id = lsp->ls_seqid.owner_id, | 
|  | 6647 | .s_dev = server->s_dev }; | 
|  | 6648 | struct nfs4_lock_waiter waiter = { .task  = current, | 
|  | 6649 | .inode = state->inode, | 
|  | 6650 | .owner = &owner, | 
|  | 6651 | .notified = false }; | 
| Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6652 | wait_queue_entry_t wait; | 
| Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6653 |  | 
|  | 6654 | /* Don't bother with waitqueue if we don't expect a callback */ | 
|  | 6655 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) | 
|  | 6656 | return nfs4_retry_setlk_simple(state, cmd, request); | 
|  | 6657 |  | 
|  | 6658 | init_wait(&wait); | 
|  | 6659 | wait.private = &waiter; | 
|  | 6660 | wait.func = nfs4_wake_lock_waiter; | 
|  | 6661 | add_wait_queue(q, &wait); | 
|  | 6662 |  | 
|  | 6663 | while(!signalled()) { | 
|  | 6664 | status = nfs4_proc_setlk(state, cmd, request); | 
|  | 6665 | if ((status != -EAGAIN) || IS_SETLK(cmd)) | 
|  | 6666 | break; | 
|  | 6667 |  | 
|  | 6668 | status = -ERESTARTSYS; | 
|  | 6669 | spin_lock_irqsave(&q->lock, flags); | 
|  | 6670 | if (waiter.notified) { | 
|  | 6671 | spin_unlock_irqrestore(&q->lock, flags); | 
|  | 6672 | continue; | 
|  | 6673 | } | 
|  | 6674 | set_current_state(TASK_INTERRUPTIBLE); | 
|  | 6675 | spin_unlock_irqrestore(&q->lock, flags); | 
|  | 6676 |  | 
| Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6677 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); | 
| Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6678 | } | 
|  | 6679 |  | 
|  | 6680 | finish_wait(q, &wait); | 
|  | 6681 | return status; | 
|  | 6682 | } | 
|  | 6683 | #else /* !CONFIG_NFS_V4_1 */ | 
|  | 6684 | static inline int | 
|  | 6685 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 6686 | { | 
|  | 6687 | return nfs4_retry_setlk_simple(state, cmd, request); | 
|  | 6688 | } | 
|  | 6689 | #endif | 
|  | 6690 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6691 | static int | 
|  | 6692 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) | 
|  | 6693 | { | 
|  | 6694 | struct nfs_open_context *ctx; | 
|  | 6695 | struct nfs4_state *state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6696 | int status; | 
|  | 6697 |  | 
|  | 6698 | /* verify open state */ | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6699 | ctx = nfs_file_open_context(filp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6700 | state = ctx->state; | 
|  | 6701 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6702 | if (IS_GETLK(cmd)) { | 
|  | 6703 | if (state != NULL) | 
|  | 6704 | return nfs4_proc_getlk(state, F_GETLK, request); | 
|  | 6705 | return 0; | 
|  | 6706 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6707 |  | 
|  | 6708 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) | 
|  | 6709 | return -EINVAL; | 
|  | 6710 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6711 | if (request->fl_type == F_UNLCK) { | 
|  | 6712 | if (state != NULL) | 
|  | 6713 | return nfs4_proc_unlck(state, cmd, request); | 
|  | 6714 | return 0; | 
|  | 6715 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6716 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6717 | if (state == NULL) | 
|  | 6718 | return -ENOLCK; | 
| Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6719 |  | 
|  | 6720 | if ((request->fl_flags & FL_POSIX) && | 
|  | 6721 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) | 
|  | 6722 | return -ENOLCK; | 
|  | 6723 |  | 
| Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 6724 | /* | 
|  | 6725 | * Don't rely on the VFS having checked the file open mode, | 
|  | 6726 | * since it won't do this for flock() locks. | 
|  | 6727 | */ | 
|  | 6728 | switch (request->fl_type) { | 
|  | 6729 | case F_RDLCK: | 
|  | 6730 | if (!(filp->f_mode & FMODE_READ)) | 
|  | 6731 | return -EBADF; | 
|  | 6732 | break; | 
|  | 6733 | case F_WRLCK: | 
|  | 6734 | if (!(filp->f_mode & FMODE_WRITE)) | 
|  | 6735 | return -EBADF; | 
|  | 6736 | } | 
|  | 6737 |  | 
| Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6738 | status = nfs4_set_lock_state(state, request); | 
|  | 6739 | if (status != 0) | 
|  | 6740 | return status; | 
|  | 6741 |  | 
| Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6742 | return nfs4_retry_setlk(state, cmd, request); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6743 | } | 
|  | 6744 |  | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6745 | 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] | 6746 | { | 
|  | 6747 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6748 | int err; | 
|  | 6749 |  | 
|  | 6750 | err = nfs4_set_lock_state(state, fl); | 
|  | 6751 | if (err != 0) | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6752 | return err; | 
| Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6753 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); | 
| Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6754 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); | 
| Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6755 | } | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6756 |  | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6757 | struct nfs_release_lockowner_data { | 
|  | 6758 | struct nfs4_lock_state *lsp; | 
| Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6759 | struct nfs_server *server; | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6760 | struct nfs_release_lockowner_args args; | 
| Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6761 | struct nfs_release_lockowner_res res; | 
| Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6762 | unsigned long timestamp; | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6763 | }; | 
|  | 6764 |  | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6765 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) | 
|  | 6766 | { | 
|  | 6767 | struct nfs_release_lockowner_data *data = calldata; | 
| Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6768 | struct nfs_server *server = data->server; | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6769 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, | 
|  | 6770 | &data->res.seq_res, task); | 
| Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6771 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; | 
| Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6772 | data->timestamp = jiffies; | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6773 | } | 
|  | 6774 |  | 
|  | 6775 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) | 
|  | 6776 | { | 
|  | 6777 | struct nfs_release_lockowner_data *data = calldata; | 
| Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6778 | struct nfs_server *server = data->server; | 
|  | 6779 |  | 
| Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6780 | nfs40_sequence_done(task, &data->res.seq_res); | 
| Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6781 |  | 
|  | 6782 | switch (task->tk_status) { | 
|  | 6783 | case 0: | 
|  | 6784 | renew_lease(server, data->timestamp); | 
|  | 6785 | break; | 
|  | 6786 | case -NFS4ERR_STALE_CLIENTID: | 
|  | 6787 | case -NFS4ERR_EXPIRED: | 
| Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6788 | nfs4_schedule_lease_recovery(server->nfs_client); | 
|  | 6789 | break; | 
| Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6790 | case -NFS4ERR_LEASE_MOVED: | 
|  | 6791 | case -NFS4ERR_DELAY: | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6792 | if (nfs4_async_handle_error(task, server, | 
|  | 6793 | NULL, NULL) == -EAGAIN) | 
| Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6794 | rpc_restart_call_prepare(task); | 
|  | 6795 | } | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6796 | } | 
|  | 6797 |  | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6798 | static void nfs4_release_lockowner_release(void *calldata) | 
|  | 6799 | { | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6800 | struct nfs_release_lockowner_data *data = calldata; | 
| Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6801 | nfs4_free_lock_state(data->server, data->lsp); | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6802 | kfree(calldata); | 
|  | 6803 | } | 
|  | 6804 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6805 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6806 | .rpc_call_prepare = nfs4_release_lockowner_prepare, | 
|  | 6807 | .rpc_call_done = nfs4_release_lockowner_done, | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6808 | .rpc_release = nfs4_release_lockowner_release, | 
|  | 6809 | }; | 
|  | 6810 |  | 
| Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6811 | static void | 
|  | 6812 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6813 | { | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6814 | struct nfs_release_lockowner_data *data; | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6815 | struct rpc_message msg = { | 
|  | 6816 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], | 
|  | 6817 | }; | 
|  | 6818 |  | 
|  | 6819 | if (server->nfs_client->cl_mvops->minor_version != 0) | 
| Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6820 | return; | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6821 |  | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6822 | data = kmalloc(sizeof(*data), GFP_NOFS); | 
|  | 6823 | if (!data) | 
| Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6824 | return; | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6825 | data->lsp = lsp; | 
| Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6826 | data->server = server; | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6827 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; | 
|  | 6828 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; | 
|  | 6829 | data->args.lock_owner.s_dev = server->s_dev; | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6830 |  | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6831 | msg.rpc_argp = &data->args; | 
| Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6832 | msg.rpc_resp = &data->res; | 
|  | 6833 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6834 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6835 | } | 
|  | 6836 |  | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6837 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" | 
|  | 6838 |  | 
| Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6839 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, | 
| Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6840 | struct dentry *unused, struct inode *inode, | 
|  | 6841 | const char *key, const void *buf, | 
|  | 6842 | size_t buflen, int flags) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6843 | { | 
| Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6844 | return nfs4_proc_set_acl(inode, buf, buflen); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6845 | } | 
|  | 6846 |  | 
| Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6847 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, | 
| Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6848 | struct dentry *unused, struct inode *inode, | 
|  | 6849 | const char *key, void *buf, size_t buflen) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6850 | { | 
| Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6851 | return nfs4_proc_get_acl(inode, buf, buflen); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6852 | } | 
|  | 6853 |  | 
| Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6854 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6855 | { | 
| Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6856 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6857 | } | 
|  | 6858 |  | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6859 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6860 |  | 
| Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6861 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, | 
| Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6862 | struct dentry *unused, struct inode *inode, | 
|  | 6863 | const char *key, const void *buf, | 
|  | 6864 | size_t buflen, int flags) | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6865 | { | 
|  | 6866 | if (security_ismaclabel(key)) | 
| Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6867 | return nfs4_set_security_label(inode, buf, buflen); | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6868 |  | 
|  | 6869 | return -EOPNOTSUPP; | 
|  | 6870 | } | 
|  | 6871 |  | 
| Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6872 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, | 
| Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6873 | struct dentry *unused, struct inode *inode, | 
|  | 6874 | const char *key, void *buf, size_t buflen) | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6875 | { | 
|  | 6876 | if (security_ismaclabel(key)) | 
| Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6877 | return nfs4_get_security_label(inode, buf, buflen); | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6878 | return -EOPNOTSUPP; | 
|  | 6879 | } | 
|  | 6880 |  | 
| Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6881 | static ssize_t | 
|  | 6882 | 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] | 6883 | { | 
| Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6884 | int len = 0; | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6885 |  | 
| Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6886 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { | 
|  | 6887 | len = security_inode_listsecurity(inode, list, list_len); | 
|  | 6888 | if (list_len && len > list_len) | 
|  | 6889 | return -ERANGE; | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6890 | } | 
|  | 6891 | return len; | 
|  | 6892 | } | 
|  | 6893 |  | 
|  | 6894 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { | 
|  | 6895 | .prefix = XATTR_SECURITY_PREFIX, | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6896 | .get	= nfs4_xattr_get_nfs4_label, | 
|  | 6897 | .set	= nfs4_xattr_set_nfs4_label, | 
|  | 6898 | }; | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6899 |  | 
| Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6900 | #else | 
|  | 6901 |  | 
|  | 6902 | static ssize_t | 
|  | 6903 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) | 
|  | 6904 | { | 
|  | 6905 | return 0; | 
|  | 6906 | } | 
|  | 6907 |  | 
|  | 6908 | #endif | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6909 |  | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6910 | /* | 
|  | 6911 | * nfs_fhget will use either the mounted_on_fileid or the fileid | 
|  | 6912 | */ | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6913 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) | 
|  | 6914 | { | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6915 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || | 
|  | 6916 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && | 
|  | 6917 | (fattr->valid & NFS_ATTR_FATTR_FSID) && | 
| Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6918 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6919 | return; | 
|  | 6920 |  | 
|  | 6921 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | | 
| Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6922 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6923 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; | 
|  | 6924 | fattr->nlink = 2; | 
|  | 6925 | } | 
|  | 6926 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6927 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, | 
|  | 6928 | const struct qstr *name, | 
|  | 6929 | struct nfs4_fs_locations *fs_locations, | 
|  | 6930 | struct page *page) | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6931 | { | 
|  | 6932 | struct nfs_server *server = NFS_SERVER(dir); | 
| Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 6933 | u32 bitmask[3]; | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6934 | struct nfs4_fs_locations_arg args = { | 
|  | 6935 | .dir_fh = NFS_FH(dir), | 
| Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6936 | .name = name, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6937 | .page = page, | 
|  | 6938 | .bitmask = bitmask, | 
|  | 6939 | }; | 
| Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6940 | struct nfs4_fs_locations_res res = { | 
|  | 6941 | .fs_locations = fs_locations, | 
|  | 6942 | }; | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6943 | struct rpc_message msg = { | 
|  | 6944 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], | 
|  | 6945 | .rpc_argp = &args, | 
| Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6946 | .rpc_resp = &res, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6947 | }; | 
|  | 6948 | int status; | 
|  | 6949 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6950 | dprintk("%s: start\n", __func__); | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6951 |  | 
| Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 6952 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; | 
|  | 6953 | bitmask[1] = nfs4_fattr_bitmap[1]; | 
|  | 6954 |  | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6955 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid | 
|  | 6956 | * is not supported */ | 
|  | 6957 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) | 
| Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 6958 | bitmask[0] &= ~FATTR4_WORD0_FILEID; | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6959 | else | 
| Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 6960 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6961 |  | 
| Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6962 | nfs_fattr_init(&fs_locations->fattr); | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6963 | fs_locations->server = server; | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6964 | fs_locations->nlocations = 0; | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6965 | 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] | 6966 | dprintk("%s: returned status = %d\n", __func__, status); | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6967 | return status; | 
|  | 6968 | } | 
|  | 6969 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6970 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, | 
|  | 6971 | const struct qstr *name, | 
|  | 6972 | struct nfs4_fs_locations *fs_locations, | 
|  | 6973 | struct page *page) | 
| Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6974 | { | 
|  | 6975 | struct nfs4_exception exception = { }; | 
|  | 6976 | int err; | 
|  | 6977 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6978 | err = _nfs4_proc_fs_locations(client, dir, name, | 
|  | 6979 | fs_locations, page); | 
|  | 6980 | trace_nfs4_get_fs_locations(dir, name, err); | 
|  | 6981 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6982 | &exception); | 
|  | 6983 | } while (exception.retry); | 
|  | 6984 | return err; | 
|  | 6985 | } | 
|  | 6986 |  | 
| Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6987 | /* | 
|  | 6988 | * This operation also signals the server that this client is | 
|  | 6989 | * performing migration recovery.  The server can stop returning | 
|  | 6990 | * NFS4ERR_LEASE_MOVED to this client.  A RENEW operation is | 
|  | 6991 | * appended to this compound to identify the client ID which is | 
|  | 6992 | * performing recovery. | 
|  | 6993 | */ | 
|  | 6994 | static int _nfs40_proc_get_locations(struct inode *inode, | 
|  | 6995 | struct nfs4_fs_locations *locations, | 
|  | 6996 | struct page *page, struct rpc_cred *cred) | 
|  | 6997 | { | 
|  | 6998 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 6999 | struct rpc_clnt *clnt = server->client; | 
|  | 7000 | u32 bitmask[2] = { | 
|  | 7001 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, | 
|  | 7002 | }; | 
|  | 7003 | struct nfs4_fs_locations_arg args = { | 
|  | 7004 | .clientid	= server->nfs_client->cl_clientid, | 
|  | 7005 | .fh		= NFS_FH(inode), | 
|  | 7006 | .page		= page, | 
|  | 7007 | .bitmask	= bitmask, | 
|  | 7008 | .migration	= 1,		/* skip LOOKUP */ | 
|  | 7009 | .renew		= 1,		/* append RENEW */ | 
|  | 7010 | }; | 
|  | 7011 | struct nfs4_fs_locations_res res = { | 
|  | 7012 | .fs_locations	= locations, | 
|  | 7013 | .migration	= 1, | 
|  | 7014 | .renew		= 1, | 
|  | 7015 | }; | 
|  | 7016 | struct rpc_message msg = { | 
|  | 7017 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], | 
|  | 7018 | .rpc_argp	= &args, | 
|  | 7019 | .rpc_resp	= &res, | 
|  | 7020 | .rpc_cred	= cred, | 
|  | 7021 | }; | 
|  | 7022 | unsigned long now = jiffies; | 
|  | 7023 | int status; | 
|  | 7024 |  | 
|  | 7025 | nfs_fattr_init(&locations->fattr); | 
|  | 7026 | locations->server = server; | 
|  | 7027 | locations->nlocations = 0; | 
|  | 7028 |  | 
|  | 7029 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); | 
|  | 7030 | nfs4_set_sequence_privileged(&args.seq_args); | 
|  | 7031 | status = nfs4_call_sync_sequence(clnt, server, &msg, | 
|  | 7032 | &args.seq_args, &res.seq_res); | 
|  | 7033 | if (status) | 
|  | 7034 | return status; | 
|  | 7035 |  | 
|  | 7036 | renew_lease(server, now); | 
|  | 7037 | return 0; | 
|  | 7038 | } | 
|  | 7039 |  | 
|  | 7040 | #ifdef CONFIG_NFS_V4_1 | 
|  | 7041 |  | 
|  | 7042 | /* | 
|  | 7043 | * This operation also signals the server that this client is | 
|  | 7044 | * performing migration recovery.  The server can stop asserting | 
|  | 7045 | * SEQ4_STATUS_LEASE_MOVED for this client.  The client ID | 
|  | 7046 | * performing this operation is identified in the SEQUENCE | 
|  | 7047 | * operation in this compound. | 
|  | 7048 | * | 
|  | 7049 | * When the client supports GETATTR(fs_locations_info), it can | 
|  | 7050 | * be plumbed in here. | 
|  | 7051 | */ | 
|  | 7052 | static int _nfs41_proc_get_locations(struct inode *inode, | 
|  | 7053 | struct nfs4_fs_locations *locations, | 
|  | 7054 | struct page *page, struct rpc_cred *cred) | 
|  | 7055 | { | 
|  | 7056 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 7057 | struct rpc_clnt *clnt = server->client; | 
|  | 7058 | u32 bitmask[2] = { | 
|  | 7059 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, | 
|  | 7060 | }; | 
|  | 7061 | struct nfs4_fs_locations_arg args = { | 
|  | 7062 | .fh		= NFS_FH(inode), | 
|  | 7063 | .page		= page, | 
|  | 7064 | .bitmask	= bitmask, | 
|  | 7065 | .migration	= 1,		/* skip LOOKUP */ | 
|  | 7066 | }; | 
|  | 7067 | struct nfs4_fs_locations_res res = { | 
|  | 7068 | .fs_locations	= locations, | 
|  | 7069 | .migration	= 1, | 
|  | 7070 | }; | 
|  | 7071 | struct rpc_message msg = { | 
|  | 7072 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], | 
|  | 7073 | .rpc_argp	= &args, | 
|  | 7074 | .rpc_resp	= &res, | 
|  | 7075 | .rpc_cred	= cred, | 
|  | 7076 | }; | 
|  | 7077 | int status; | 
|  | 7078 |  | 
|  | 7079 | nfs_fattr_init(&locations->fattr); | 
|  | 7080 | locations->server = server; | 
|  | 7081 | locations->nlocations = 0; | 
|  | 7082 |  | 
|  | 7083 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); | 
|  | 7084 | nfs4_set_sequence_privileged(&args.seq_args); | 
|  | 7085 | status = nfs4_call_sync_sequence(clnt, server, &msg, | 
|  | 7086 | &args.seq_args, &res.seq_res); | 
|  | 7087 | if (status == NFS4_OK && | 
|  | 7088 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) | 
|  | 7089 | status = -NFS4ERR_LEASE_MOVED; | 
|  | 7090 | return status; | 
|  | 7091 | } | 
|  | 7092 |  | 
|  | 7093 | #endif	/* CONFIG_NFS_V4_1 */ | 
|  | 7094 |  | 
|  | 7095 | /** | 
|  | 7096 | * nfs4_proc_get_locations - discover locations for a migrated FSID | 
|  | 7097 | * @inode: inode on FSID that is migrating | 
|  | 7098 | * @locations: result of query | 
|  | 7099 | * @page: buffer | 
|  | 7100 | * @cred: credential to use for this operation | 
|  | 7101 | * | 
|  | 7102 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the | 
|  | 7103 | * operation failed, or a negative errno if a local error occurred. | 
|  | 7104 | * | 
|  | 7105 | * On success, "locations" is filled in, but if the server has | 
|  | 7106 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not | 
|  | 7107 | * asserted. | 
|  | 7108 | * | 
|  | 7109 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases | 
|  | 7110 | * from this client that require migration recovery. | 
|  | 7111 | */ | 
|  | 7112 | int nfs4_proc_get_locations(struct inode *inode, | 
|  | 7113 | struct nfs4_fs_locations *locations, | 
|  | 7114 | struct page *page, struct rpc_cred *cred) | 
|  | 7115 | { | 
|  | 7116 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 7117 | struct nfs_client *clp = server->nfs_client; | 
|  | 7118 | const struct nfs4_mig_recovery_ops *ops = | 
|  | 7119 | clp->cl_mvops->mig_recovery_ops; | 
|  | 7120 | struct nfs4_exception exception = { }; | 
|  | 7121 | int status; | 
|  | 7122 |  | 
|  | 7123 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, | 
|  | 7124 | (unsigned long long)server->fsid.major, | 
|  | 7125 | (unsigned long long)server->fsid.minor, | 
|  | 7126 | clp->cl_hostname); | 
|  | 7127 | nfs_display_fhandle(NFS_FH(inode), __func__); | 
|  | 7128 |  | 
|  | 7129 | do { | 
|  | 7130 | status = ops->get_locations(inode, locations, page, cred); | 
|  | 7131 | if (status != -NFS4ERR_DELAY) | 
|  | 7132 | break; | 
|  | 7133 | nfs4_handle_exception(server, status, &exception); | 
|  | 7134 | } while (exception.retry); | 
|  | 7135 | return status; | 
|  | 7136 | } | 
|  | 7137 |  | 
| Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7138 | /* | 
|  | 7139 | * This operation also signals the server that this client is | 
|  | 7140 | * performing "lease moved" recovery.  The server can stop | 
|  | 7141 | * returning NFS4ERR_LEASE_MOVED to this client.  A RENEW operation | 
|  | 7142 | * is appended to this compound to identify the client ID which is | 
|  | 7143 | * performing recovery. | 
|  | 7144 | */ | 
|  | 7145 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) | 
|  | 7146 | { | 
|  | 7147 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 7148 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; | 
|  | 7149 | struct rpc_clnt *clnt = server->client; | 
|  | 7150 | struct nfs4_fsid_present_arg args = { | 
|  | 7151 | .fh		= NFS_FH(inode), | 
|  | 7152 | .clientid	= clp->cl_clientid, | 
|  | 7153 | .renew		= 1,		/* append RENEW */ | 
|  | 7154 | }; | 
|  | 7155 | struct nfs4_fsid_present_res res = { | 
|  | 7156 | .renew		= 1, | 
|  | 7157 | }; | 
|  | 7158 | struct rpc_message msg = { | 
|  | 7159 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], | 
|  | 7160 | .rpc_argp	= &args, | 
|  | 7161 | .rpc_resp	= &res, | 
|  | 7162 | .rpc_cred	= cred, | 
|  | 7163 | }; | 
|  | 7164 | unsigned long now = jiffies; | 
|  | 7165 | int status; | 
|  | 7166 |  | 
|  | 7167 | res.fh = nfs_alloc_fhandle(); | 
|  | 7168 | if (res.fh == NULL) | 
|  | 7169 | return -ENOMEM; | 
|  | 7170 |  | 
|  | 7171 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); | 
|  | 7172 | nfs4_set_sequence_privileged(&args.seq_args); | 
|  | 7173 | status = nfs4_call_sync_sequence(clnt, server, &msg, | 
|  | 7174 | &args.seq_args, &res.seq_res); | 
|  | 7175 | nfs_free_fhandle(res.fh); | 
|  | 7176 | if (status) | 
|  | 7177 | return status; | 
|  | 7178 |  | 
|  | 7179 | do_renew_lease(clp, now); | 
|  | 7180 | return 0; | 
|  | 7181 | } | 
|  | 7182 |  | 
|  | 7183 | #ifdef CONFIG_NFS_V4_1 | 
|  | 7184 |  | 
|  | 7185 | /* | 
|  | 7186 | * This operation also signals the server that this client is | 
|  | 7187 | * performing "lease moved" recovery.  The server can stop asserting | 
|  | 7188 | * SEQ4_STATUS_LEASE_MOVED for this client.  The client ID performing | 
|  | 7189 | * this operation is identified in the SEQUENCE operation in this | 
|  | 7190 | * compound. | 
|  | 7191 | */ | 
|  | 7192 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) | 
|  | 7193 | { | 
|  | 7194 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 7195 | struct rpc_clnt *clnt = server->client; | 
|  | 7196 | struct nfs4_fsid_present_arg args = { | 
|  | 7197 | .fh		= NFS_FH(inode), | 
|  | 7198 | }; | 
|  | 7199 | struct nfs4_fsid_present_res res = { | 
|  | 7200 | }; | 
|  | 7201 | struct rpc_message msg = { | 
|  | 7202 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], | 
|  | 7203 | .rpc_argp	= &args, | 
|  | 7204 | .rpc_resp	= &res, | 
|  | 7205 | .rpc_cred	= cred, | 
|  | 7206 | }; | 
|  | 7207 | int status; | 
|  | 7208 |  | 
|  | 7209 | res.fh = nfs_alloc_fhandle(); | 
|  | 7210 | if (res.fh == NULL) | 
|  | 7211 | return -ENOMEM; | 
|  | 7212 |  | 
|  | 7213 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); | 
|  | 7214 | nfs4_set_sequence_privileged(&args.seq_args); | 
|  | 7215 | status = nfs4_call_sync_sequence(clnt, server, &msg, | 
|  | 7216 | &args.seq_args, &res.seq_res); | 
|  | 7217 | nfs_free_fhandle(res.fh); | 
|  | 7218 | if (status == NFS4_OK && | 
|  | 7219 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) | 
|  | 7220 | status = -NFS4ERR_LEASE_MOVED; | 
|  | 7221 | return status; | 
|  | 7222 | } | 
|  | 7223 |  | 
|  | 7224 | #endif	/* CONFIG_NFS_V4_1 */ | 
|  | 7225 |  | 
|  | 7226 | /** | 
|  | 7227 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? | 
|  | 7228 | * @inode: inode on FSID to check | 
|  | 7229 | * @cred: credential to use for this operation | 
|  | 7230 | * | 
|  | 7231 | * Server indicates whether the FSID is present, moved, or not | 
|  | 7232 | * recognized.  This operation is necessary to clear a LEASE_MOVED | 
|  | 7233 | * condition for this client ID. | 
|  | 7234 | * | 
|  | 7235 | * Returns NFS4_OK if the FSID is present on this server, | 
|  | 7236 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative | 
|  | 7237 | *  NFS4ERR code if some error occurred on the server, or a | 
|  | 7238 | *  negative errno if a local failure occurred. | 
|  | 7239 | */ | 
|  | 7240 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) | 
|  | 7241 | { | 
|  | 7242 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 7243 | struct nfs_client *clp = server->nfs_client; | 
|  | 7244 | const struct nfs4_mig_recovery_ops *ops = | 
|  | 7245 | clp->cl_mvops->mig_recovery_ops; | 
|  | 7246 | struct nfs4_exception exception = { }; | 
|  | 7247 | int status; | 
|  | 7248 |  | 
|  | 7249 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, | 
|  | 7250 | (unsigned long long)server->fsid.major, | 
|  | 7251 | (unsigned long long)server->fsid.minor, | 
|  | 7252 | clp->cl_hostname); | 
|  | 7253 | nfs_display_fhandle(NFS_FH(inode), __func__); | 
|  | 7254 |  | 
|  | 7255 | do { | 
|  | 7256 | status = ops->fsid_present(inode, cred); | 
|  | 7257 | if (status != -NFS4ERR_DELAY) | 
|  | 7258 | break; | 
|  | 7259 | nfs4_handle_exception(server, status, &exception); | 
|  | 7260 | } while (exception.retry); | 
|  | 7261 | return status; | 
|  | 7262 | } | 
|  | 7263 |  | 
| Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7264 | /** | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7265 | * If 'use_integrity' is true and the state managment nfs_client | 
|  | 7266 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient | 
|  | 7267 | * and the machine credential as per RFC3530bis and RFC5661 Security | 
|  | 7268 | * Considerations sections. Otherwise, just use the user cred with the | 
|  | 7269 | * filesystem's rpc_client. | 
| Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7270 | */ | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7271 | 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] | 7272 | { | 
|  | 7273 | int status; | 
|  | 7274 | struct nfs4_secinfo_arg args = { | 
|  | 7275 | .dir_fh = NFS_FH(dir), | 
|  | 7276 | .name   = name, | 
|  | 7277 | }; | 
|  | 7278 | struct nfs4_secinfo_res res = { | 
|  | 7279 | .flavors     = flavors, | 
|  | 7280 | }; | 
|  | 7281 | struct rpc_message msg = { | 
|  | 7282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], | 
|  | 7283 | .rpc_argp = &args, | 
|  | 7284 | .rpc_resp = &res, | 
|  | 7285 | }; | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7286 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7287 | struct rpc_cred *cred = NULL; | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7288 |  | 
|  | 7289 | if (use_integrity) { | 
|  | 7290 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7291 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); | 
|  | 7292 | msg.rpc_cred = cred; | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7293 | } | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7294 |  | 
|  | 7295 | dprintk("NFS call  secinfo %s\n", name->name); | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7296 |  | 
|  | 7297 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, | 
|  | 7298 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); | 
|  | 7299 |  | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7300 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, | 
|  | 7301 | &res.seq_res, 0); | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7302 | dprintk("NFS reply  secinfo: %d\n", status); | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7303 |  | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7304 | if (cred) | 
|  | 7305 | put_rpccred(cred); | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7306 |  | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7307 | return status; | 
|  | 7308 | } | 
|  | 7309 |  | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7310 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, | 
|  | 7311 | struct nfs4_secinfo_flavors *flavors) | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7312 | { | 
|  | 7313 | struct nfs4_exception exception = { }; | 
|  | 7314 | int err; | 
|  | 7315 | do { | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7316 | err = -NFS4ERR_WRONGSEC; | 
|  | 7317 |  | 
|  | 7318 | /* try to use integrity protection with machine cred */ | 
|  | 7319 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) | 
|  | 7320 | err = _nfs4_proc_secinfo(dir, name, flavors, true); | 
|  | 7321 |  | 
|  | 7322 | /* | 
|  | 7323 | * if unable to use integrity protection, or SECINFO with | 
|  | 7324 | * integrity protection returns NFS4ERR_WRONGSEC (which is | 
|  | 7325 | * disallowed by spec, but exists in deployed servers) use | 
|  | 7326 | * the current filesystem's rpc_client and the user cred. | 
|  | 7327 | */ | 
|  | 7328 | if (err == -NFS4ERR_WRONGSEC) | 
|  | 7329 | err = _nfs4_proc_secinfo(dir, name, flavors, false); | 
|  | 7330 |  | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7331 | trace_nfs4_secinfo(dir, name, err); | 
|  | 7332 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7333 | &exception); | 
|  | 7334 | } while (exception.retry); | 
|  | 7335 | return err; | 
|  | 7336 | } | 
|  | 7337 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7338 | #ifdef CONFIG_NFS_V4_1 | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7339 | /* | 
| Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7340 | * Check the exchange flags returned by the server for invalid flags, having | 
|  | 7341 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or | 
|  | 7342 | * DS flags set. | 
|  | 7343 | */ | 
|  | 7344 | static int nfs4_check_cl_exchange_flags(u32 flags) | 
|  | 7345 | { | 
|  | 7346 | if (flags & ~EXCHGID4_FLAG_MASK_R) | 
|  | 7347 | goto out_inval; | 
|  | 7348 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && | 
|  | 7349 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) | 
|  | 7350 | goto out_inval; | 
|  | 7351 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) | 
|  | 7352 | goto out_inval; | 
|  | 7353 | return NFS_OK; | 
|  | 7354 | out_inval: | 
|  | 7355 | return -NFS4ERR_INVAL; | 
|  | 7356 | } | 
|  | 7357 |  | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7358 | static bool | 
| Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7359 | nfs41_same_server_scope(struct nfs41_server_scope *a, | 
|  | 7360 | struct nfs41_server_scope *b) | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7361 | { | 
| Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7362 | if (a->server_scope_sz != b->server_scope_sz) | 
|  | 7363 | return false; | 
|  | 7364 | 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] | 7365 | } | 
|  | 7366 |  | 
| Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7367 | static void | 
|  | 7368 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) | 
|  | 7369 | { | 
|  | 7370 | } | 
|  | 7371 |  | 
|  | 7372 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { | 
|  | 7373 | .rpc_call_done =  &nfs4_bind_one_conn_to_session_done, | 
|  | 7374 | }; | 
|  | 7375 |  | 
| Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7376 | /* | 
| Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7377 | * nfs4_proc_bind_one_conn_to_session() | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7378 | * | 
|  | 7379 | * The 4.1 client currently uses the same TCP connection for the | 
|  | 7380 | * fore and backchannel. | 
|  | 7381 | */ | 
| Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7382 | static | 
|  | 7383 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, | 
|  | 7384 | struct rpc_xprt *xprt, | 
|  | 7385 | struct nfs_client *clp, | 
|  | 7386 | struct rpc_cred *cred) | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7387 | { | 
|  | 7388 | int status; | 
| Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7389 | struct nfs41_bind_conn_to_session_args args = { | 
|  | 7390 | .client = clp, | 
|  | 7391 | .dir = NFS4_CDFC4_FORE_OR_BOTH, | 
|  | 7392 | }; | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7393 | struct nfs41_bind_conn_to_session_res res; | 
|  | 7394 | struct rpc_message msg = { | 
|  | 7395 | .rpc_proc = | 
|  | 7396 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], | 
| Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7397 | .rpc_argp = &args, | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7398 | .rpc_resp = &res, | 
| Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7399 | .rpc_cred = cred, | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7400 | }; | 
| Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7401 | struct rpc_task_setup task_setup_data = { | 
|  | 7402 | .rpc_client = clnt, | 
|  | 7403 | .rpc_xprt = xprt, | 
| Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7404 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, | 
| Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7405 | .rpc_message = &msg, | 
|  | 7406 | .flags = RPC_TASK_TIMEOUT, | 
|  | 7407 | }; | 
|  | 7408 | struct rpc_task *task; | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7409 |  | 
| Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7410 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); | 
|  | 7411 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) | 
|  | 7412 | args.dir = NFS4_CDFC4_FORE; | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7413 |  | 
| Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7414 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ | 
|  | 7415 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) | 
|  | 7416 | args.dir = NFS4_CDFC4_FORE; | 
|  | 7417 |  | 
|  | 7418 | task = rpc_run_task(&task_setup_data); | 
|  | 7419 | if (!IS_ERR(task)) { | 
|  | 7420 | status = task->tk_status; | 
|  | 7421 | rpc_put_task(task); | 
|  | 7422 | } else | 
|  | 7423 | status = PTR_ERR(task); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7424 | trace_nfs4_bind_conn_to_session(clp, status); | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7425 | if (status == 0) { | 
| Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7426 | if (memcmp(res.sessionid.data, | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7427 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { | 
|  | 7428 | dprintk("NFS: %s: Session ID mismatch\n", __func__); | 
| Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7429 | return -EIO; | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7430 | } | 
| Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7431 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7432 | dprintk("NFS: %s: Unexpected direction from server\n", | 
|  | 7433 | __func__); | 
| Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7434 | return -EIO; | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7435 | } | 
| Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7436 | 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] | 7437 | dprintk("NFS: %s: Server returned RDMA mode = true\n", | 
|  | 7438 | __func__); | 
| Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7439 | return -EIO; | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7440 | } | 
|  | 7441 | } | 
| Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7442 |  | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7443 | return status; | 
|  | 7444 | } | 
|  | 7445 |  | 
| Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7446 | struct rpc_bind_conn_calldata { | 
|  | 7447 | struct nfs_client *clp; | 
|  | 7448 | struct rpc_cred *cred; | 
|  | 7449 | }; | 
|  | 7450 |  | 
|  | 7451 | static int | 
|  | 7452 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, | 
|  | 7453 | struct rpc_xprt *xprt, | 
|  | 7454 | void *calldata) | 
|  | 7455 | { | 
|  | 7456 | struct rpc_bind_conn_calldata *p = calldata; | 
|  | 7457 |  | 
|  | 7458 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); | 
|  | 7459 | } | 
|  | 7460 |  | 
|  | 7461 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) | 
|  | 7462 | { | 
|  | 7463 | struct rpc_bind_conn_calldata data = { | 
|  | 7464 | .clp = clp, | 
|  | 7465 | .cred = cred, | 
|  | 7466 | }; | 
|  | 7467 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, | 
|  | 7468 | nfs4_proc_bind_conn_to_session_callback, &data); | 
|  | 7469 | } | 
|  | 7470 |  | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7471 | /* | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7472 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map | 
|  | 7473 | * 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] | 7474 | */ | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7475 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { | 
|  | 7476 | .how = SP4_MACH_CRED, | 
|  | 7477 | .enforce.u.words = { | 
|  | 7478 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | | 
|  | 7479 | 1 << (OP_EXCHANGE_ID - 32) | | 
|  | 7480 | 1 << (OP_CREATE_SESSION - 32) | | 
|  | 7481 | 1 << (OP_DESTROY_SESSION - 32) | | 
|  | 7482 | 1 << (OP_DESTROY_CLIENTID - 32) | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7483 | }, | 
|  | 7484 | .allow.u.words = { | 
|  | 7485 | [0] = 1 << (OP_CLOSE) | | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7486 | 1 << (OP_OPEN_DOWNGRADE) | | 
| Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7487 | 1 << (OP_LOCKU) | | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7488 | 1 << (OP_DELEGRETURN) | | 
| Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7489 | 1 << (OP_COMMIT), | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7490 | [1] = 1 << (OP_SECINFO - 32) | | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7491 | 1 << (OP_SECINFO_NO_NAME - 32) | | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7492 | 1 << (OP_LAYOUTRETURN - 32) | | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7493 | 1 << (OP_TEST_STATEID - 32) | | 
| Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7494 | 1 << (OP_FREE_STATEID - 32) | | 
|  | 7495 | 1 << (OP_WRITE - 32) | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7496 | } | 
|  | 7497 | }; | 
|  | 7498 |  | 
|  | 7499 | /* | 
|  | 7500 | * Select the state protection mode for client `clp' given the server results | 
|  | 7501 | * from exchange_id in `sp'. | 
|  | 7502 | * | 
|  | 7503 | * Returns 0 on success, negative errno otherwise. | 
|  | 7504 | */ | 
|  | 7505 | static int nfs4_sp4_select_mode(struct nfs_client *clp, | 
|  | 7506 | struct nfs41_state_protection *sp) | 
|  | 7507 | { | 
|  | 7508 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { | 
|  | 7509 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | | 
|  | 7510 | 1 << (OP_EXCHANGE_ID - 32) | | 
|  | 7511 | 1 << (OP_CREATE_SESSION - 32) | | 
|  | 7512 | 1 << (OP_DESTROY_SESSION - 32) | | 
|  | 7513 | 1 << (OP_DESTROY_CLIENTID - 32) | 
|  | 7514 | }; | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7515 | unsigned long flags = 0; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7516 | unsigned int i; | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7517 | int ret = 0; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7518 |  | 
|  | 7519 | if (sp->how == SP4_MACH_CRED) { | 
|  | 7520 | /* Print state protect result */ | 
|  | 7521 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); | 
|  | 7522 | for (i = 0; i <= LAST_NFS4_OP; i++) { | 
|  | 7523 | if (test_bit(i, sp->enforce.u.longs)) | 
|  | 7524 | dfprintk(MOUNT, "  enforce op %d\n", i); | 
|  | 7525 | if (test_bit(i, sp->allow.u.longs)) | 
|  | 7526 | dfprintk(MOUNT, "  allow op %d\n", i); | 
|  | 7527 | } | 
|  | 7528 |  | 
|  | 7529 | /* make sure nothing is on enforce list that isn't supported */ | 
|  | 7530 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { | 
|  | 7531 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { | 
|  | 7532 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7533 | ret = -EINVAL; | 
|  | 7534 | goto out; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7535 | } | 
|  | 7536 | } | 
|  | 7537 |  | 
|  | 7538 | /* | 
|  | 7539 | * Minimal mode - state operations are allowed to use machine | 
|  | 7540 | * credential.  Note this already happens by default, so the | 
|  | 7541 | * client doesn't have to do anything more than the negotiation. | 
|  | 7542 | * | 
|  | 7543 | * NOTE: we don't care if EXCHANGE_ID is in the list - | 
|  | 7544 | *       we're already using the machine cred for exchange_id | 
|  | 7545 | *       and will never use a different cred. | 
|  | 7546 | */ | 
|  | 7547 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && | 
|  | 7548 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && | 
|  | 7549 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && | 
|  | 7550 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { | 
|  | 7551 | dfprintk(MOUNT, "sp4_mach_cred:\n"); | 
|  | 7552 | dfprintk(MOUNT, "  minimal mode enabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7553 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7554 | } else { | 
|  | 7555 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7556 | ret = -EINVAL; | 
|  | 7557 | goto out; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7558 | } | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7559 |  | 
|  | 7560 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7561 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && | 
|  | 7562 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7563 | test_bit(OP_LOCKU, sp->allow.u.longs)) { | 
|  | 7564 | dfprintk(MOUNT, "  cleanup mode enabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7565 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7566 | } | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7567 |  | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7568 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { | 
|  | 7569 | dfprintk(MOUNT, "  pnfs cleanup mode enabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7570 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7571 | } | 
|  | 7572 |  | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7573 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && | 
|  | 7574 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { | 
|  | 7575 | dfprintk(MOUNT, "  secinfo mode enabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7576 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7577 | } | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7578 |  | 
|  | 7579 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && | 
|  | 7580 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { | 
|  | 7581 | dfprintk(MOUNT, "  stateid mode enabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7582 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7583 | } | 
| Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7584 |  | 
|  | 7585 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { | 
|  | 7586 | dfprintk(MOUNT, "  write mode enabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7587 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); | 
| Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7588 | } | 
|  | 7589 |  | 
|  | 7590 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { | 
|  | 7591 | dfprintk(MOUNT, "  commit mode enabled\n"); | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7592 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); | 
| Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7593 | } | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7594 | } | 
| Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7595 | out: | 
|  | 7596 | clp->cl_sp4_flags = flags; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7597 | return 0; | 
|  | 7598 | } | 
|  | 7599 |  | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7600 | struct nfs41_exchange_id_data { | 
|  | 7601 | struct nfs41_exchange_id_res res; | 
|  | 7602 | struct nfs41_exchange_id_args args; | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7603 | }; | 
|  | 7604 |  | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7605 | static void nfs4_exchange_id_release(void *data) | 
|  | 7606 | { | 
|  | 7607 | struct nfs41_exchange_id_data *cdata = | 
|  | 7608 | (struct nfs41_exchange_id_data *)data; | 
|  | 7609 |  | 
| Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7610 | nfs_put_client(cdata->args.client); | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7611 | kfree(cdata->res.impl_id); | 
|  | 7612 | kfree(cdata->res.server_scope); | 
|  | 7613 | kfree(cdata->res.server_owner); | 
|  | 7614 | kfree(cdata); | 
|  | 7615 | } | 
|  | 7616 |  | 
|  | 7617 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7618 | .rpc_release = nfs4_exchange_id_release, | 
|  | 7619 | }; | 
|  | 7620 |  | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7621 | /* | 
|  | 7622 | * _nfs4_proc_exchange_id() | 
|  | 7623 | * | 
|  | 7624 | * Wrapper for EXCHANGE_ID operation. | 
|  | 7625 | */ | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7626 | static struct rpc_task * | 
|  | 7627 | nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, | 
| Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7628 | u32 sp4_how, struct rpc_xprt *xprt) | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7629 | { | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7630 | struct rpc_message msg = { | 
|  | 7631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7632 | .rpc_cred = cred, | 
|  | 7633 | }; | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7634 | struct rpc_task_setup task_setup_data = { | 
|  | 7635 | .rpc_client = clp->cl_rpcclient, | 
|  | 7636 | .callback_ops = &nfs4_exchange_id_call_ops, | 
|  | 7637 | .rpc_message = &msg, | 
| Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7638 | .flags = RPC_TASK_TIMEOUT, | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7639 | }; | 
|  | 7640 | struct nfs41_exchange_id_data *calldata; | 
| Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7641 | int status; | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7642 |  | 
| Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 7643 | if (!refcount_inc_not_zero(&clp->cl_count)) | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7644 | return ERR_PTR(-EIO); | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7645 |  | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7646 | status = -ENOMEM; | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7647 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7648 | if (!calldata) | 
|  | 7649 | goto out; | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7650 |  | 
| Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7651 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); | 
| Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7652 |  | 
|  | 7653 | status = nfs4_init_uniform_client_string(clp); | 
|  | 7654 | if (status) | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7655 | goto out_calldata; | 
| Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7656 |  | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7657 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), | 
|  | 7658 | GFP_NOFS); | 
|  | 7659 | status = -ENOMEM; | 
|  | 7660 | if (unlikely(calldata->res.server_owner == NULL)) | 
|  | 7661 | goto out_calldata; | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7662 |  | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7663 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), | 
| Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7664 | GFP_NOFS); | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7665 | if (unlikely(calldata->res.server_scope == NULL)) | 
| Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7666 | goto out_server_owner; | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7667 |  | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7668 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); | 
|  | 7669 | if (unlikely(calldata->res.impl_id == NULL)) | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7670 | goto out_server_scope; | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7671 |  | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7672 | switch (sp4_how) { | 
|  | 7673 | case SP4_NONE: | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7674 | calldata->args.state_protect.how = SP4_NONE; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7675 | break; | 
|  | 7676 |  | 
|  | 7677 | case SP4_MACH_CRED: | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7678 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7679 | break; | 
|  | 7680 |  | 
|  | 7681 | default: | 
|  | 7682 | /* unsupported! */ | 
|  | 7683 | WARN_ON_ONCE(1); | 
|  | 7684 | status = -EINVAL; | 
| Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7685 | goto out_impl_id; | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7686 | } | 
| Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7687 | if (xprt) { | 
| Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7688 | task_setup_data.rpc_xprt = xprt; | 
| Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7689 | task_setup_data.flags |= RPC_TASK_SOFTCONN; | 
| Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7690 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, | 
|  | 7691 | sizeof(calldata->args.verifier.data)); | 
| Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7692 | } | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7693 | calldata->args.client = clp; | 
| Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7694 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | | 
|  | 7695 | EXCHGID4_FLAG_BIND_PRINC_STATEID; | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7696 | #ifdef CONFIG_NFS_V4_1_MIGRATION | 
| Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7697 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7698 | #endif | 
|  | 7699 | msg.rpc_argp = &calldata->args; | 
|  | 7700 | msg.rpc_resp = &calldata->res; | 
|  | 7701 | task_setup_data.callback_data = calldata; | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7702 |  | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7703 | return rpc_run_task(&task_setup_data); | 
| Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7704 |  | 
|  | 7705 | out_impl_id: | 
|  | 7706 | kfree(calldata->res.impl_id); | 
|  | 7707 | out_server_scope: | 
|  | 7708 | kfree(calldata->res.server_scope); | 
|  | 7709 | out_server_owner: | 
|  | 7710 | kfree(calldata->res.server_owner); | 
|  | 7711 | out_calldata: | 
|  | 7712 | kfree(calldata); | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7713 | out: | 
| Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7714 | nfs_put_client(clp); | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7715 | return ERR_PTR(status); | 
|  | 7716 | } | 
|  | 7717 |  | 
|  | 7718 | /* | 
|  | 7719 | * _nfs4_proc_exchange_id() | 
|  | 7720 | * | 
|  | 7721 | * Wrapper for EXCHANGE_ID operation. | 
|  | 7722 | */ | 
|  | 7723 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, | 
|  | 7724 | u32 sp4_how) | 
|  | 7725 | { | 
|  | 7726 | struct rpc_task *task; | 
|  | 7727 | struct nfs41_exchange_id_args *argp; | 
|  | 7728 | struct nfs41_exchange_id_res *resp; | 
|  | 7729 | int status; | 
|  | 7730 |  | 
|  | 7731 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); | 
|  | 7732 | if (IS_ERR(task)) | 
|  | 7733 | return PTR_ERR(task); | 
|  | 7734 |  | 
|  | 7735 | argp = task->tk_msg.rpc_argp; | 
|  | 7736 | resp = task->tk_msg.rpc_resp; | 
|  | 7737 | status = task->tk_status; | 
|  | 7738 | if (status  != 0) | 
|  | 7739 | goto out; | 
|  | 7740 |  | 
|  | 7741 | status = nfs4_check_cl_exchange_flags(resp->flags); | 
|  | 7742 | if (status  != 0) | 
|  | 7743 | goto out; | 
|  | 7744 |  | 
|  | 7745 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); | 
|  | 7746 | if (status != 0) | 
|  | 7747 | goto out; | 
|  | 7748 |  | 
|  | 7749 | clp->cl_clientid = resp->clientid; | 
|  | 7750 | clp->cl_exchange_flags = resp->flags; | 
|  | 7751 | clp->cl_seqid = resp->seqid; | 
|  | 7752 | /* Client ID is not confirmed */ | 
|  | 7753 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) | 
|  | 7754 | clear_bit(NFS4_SESSION_ESTABLISHED, | 
|  | 7755 | &clp->cl_session->session_state); | 
|  | 7756 |  | 
|  | 7757 | if (clp->cl_serverscope != NULL && | 
|  | 7758 | !nfs41_same_server_scope(clp->cl_serverscope, | 
|  | 7759 | resp->server_scope)) { | 
|  | 7760 | dprintk("%s: server_scope mismatch detected\n", | 
|  | 7761 | __func__); | 
|  | 7762 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); | 
|  | 7763 | } | 
|  | 7764 |  | 
|  | 7765 | swap(clp->cl_serverowner, resp->server_owner); | 
|  | 7766 | swap(clp->cl_serverscope, resp->server_scope); | 
|  | 7767 | swap(clp->cl_implid, resp->impl_id); | 
|  | 7768 |  | 
|  | 7769 | /* Save the EXCHANGE_ID verifier session trunk tests */ | 
|  | 7770 | memcpy(clp->cl_confirm.data, argp->verifier.data, | 
|  | 7771 | sizeof(clp->cl_confirm.data)); | 
|  | 7772 | out: | 
|  | 7773 | trace_nfs4_exchange_id(clp, status); | 
|  | 7774 | rpc_put_task(task); | 
|  | 7775 | return status; | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7776 | } | 
|  | 7777 |  | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7778 | /* | 
|  | 7779 | * nfs4_proc_exchange_id() | 
|  | 7780 | * | 
|  | 7781 | * Returns zero, a negative errno, or a negative NFS4ERR status code. | 
|  | 7782 | * | 
|  | 7783 | * Since the clientid has expired, all compounds using sessions | 
|  | 7784 | * associated with the stale clientid will be returning | 
|  | 7785 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore | 
|  | 7786 | * be in some phase of session reset. | 
|  | 7787 | * | 
|  | 7788 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. | 
|  | 7789 | */ | 
|  | 7790 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) | 
|  | 7791 | { | 
|  | 7792 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; | 
|  | 7793 | int status; | 
|  | 7794 |  | 
|  | 7795 | /* try SP4_MACH_CRED if krb5i/p	*/ | 
|  | 7796 | if (authflavor == RPC_AUTH_GSS_KRB5I || | 
|  | 7797 | authflavor == RPC_AUTH_GSS_KRB5P) { | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7798 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7799 | if (!status) | 
|  | 7800 | return 0; | 
|  | 7801 | } | 
|  | 7802 |  | 
|  | 7803 | /* try SP4_NONE */ | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7804 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7805 | } | 
|  | 7806 |  | 
| Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7807 | /** | 
|  | 7808 | * nfs4_test_session_trunk | 
|  | 7809 | * | 
|  | 7810 | * This is an add_xprt_test() test function called from | 
|  | 7811 | * rpc_clnt_setup_test_and_add_xprt. | 
|  | 7812 | * | 
|  | 7813 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt | 
|  | 7814 | * and is dereferrenced in nfs4_exchange_id_release | 
|  | 7815 | * | 
|  | 7816 | * Upon success, add the new transport to the rpc_clnt | 
|  | 7817 | * | 
|  | 7818 | * @clnt: struct rpc_clnt to get new transport | 
|  | 7819 | * @xprt: the rpc_xprt to test | 
|  | 7820 | * @data: call data for _nfs4_proc_exchange_id. | 
|  | 7821 | */ | 
|  | 7822 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, | 
|  | 7823 | void *data) | 
|  | 7824 | { | 
|  | 7825 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7826 | struct rpc_task *task; | 
|  | 7827 | int status; | 
|  | 7828 |  | 
| Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7829 | u32 sp4_how; | 
|  | 7830 |  | 
|  | 7831 | dprintk("--> %s try %s\n", __func__, | 
|  | 7832 | xprt->address_strings[RPC_DISPLAY_ADDR]); | 
|  | 7833 |  | 
|  | 7834 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); | 
|  | 7835 |  | 
|  | 7836 | /* Test connection for session trunking. Async exchange_id call */ | 
| Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7837 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); | 
|  | 7838 | if (IS_ERR(task)) | 
|  | 7839 | return PTR_ERR(task); | 
|  | 7840 |  | 
|  | 7841 | status = task->tk_status; | 
|  | 7842 | if (status == 0) | 
|  | 7843 | status = nfs4_detect_session_trunking(adata->clp, | 
|  | 7844 | task->tk_msg.rpc_resp, xprt); | 
|  | 7845 |  | 
|  | 7846 | rpc_put_task(task); | 
|  | 7847 | return status; | 
| Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7848 | } | 
|  | 7849 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); | 
|  | 7850 |  | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7851 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, | 
|  | 7852 | struct rpc_cred *cred) | 
|  | 7853 | { | 
|  | 7854 | struct rpc_message msg = { | 
|  | 7855 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], | 
|  | 7856 | .rpc_argp = clp, | 
|  | 7857 | .rpc_cred = cred, | 
|  | 7858 | }; | 
|  | 7859 | int status; | 
|  | 7860 |  | 
|  | 7861 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7862 | trace_nfs4_destroy_clientid(clp, status); | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7863 | if (status) | 
| Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7864 | dprintk("NFS: Got error %d from the server %s on " | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7865 | "DESTROY_CLIENTID.", status, clp->cl_hostname); | 
|  | 7866 | return status; | 
|  | 7867 | } | 
|  | 7868 |  | 
|  | 7869 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, | 
|  | 7870 | struct rpc_cred *cred) | 
|  | 7871 | { | 
|  | 7872 | unsigned int loop; | 
|  | 7873 | int ret; | 
|  | 7874 |  | 
|  | 7875 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { | 
|  | 7876 | ret = _nfs4_proc_destroy_clientid(clp, cred); | 
|  | 7877 | switch (ret) { | 
|  | 7878 | case -NFS4ERR_DELAY: | 
|  | 7879 | case -NFS4ERR_CLIENTID_BUSY: | 
|  | 7880 | ssleep(1); | 
|  | 7881 | break; | 
|  | 7882 | default: | 
|  | 7883 | return ret; | 
|  | 7884 | } | 
|  | 7885 | } | 
|  | 7886 | return 0; | 
|  | 7887 | } | 
|  | 7888 |  | 
|  | 7889 | int nfs4_destroy_clientid(struct nfs_client *clp) | 
|  | 7890 | { | 
|  | 7891 | struct rpc_cred *cred; | 
|  | 7892 | int ret = 0; | 
|  | 7893 |  | 
|  | 7894 | if (clp->cl_mvops->minor_version < 1) | 
|  | 7895 | goto out; | 
|  | 7896 | if (clp->cl_exchange_flags == 0) | 
|  | 7897 | goto out; | 
| Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7898 | if (clp->cl_preserve_clid) | 
|  | 7899 | goto out; | 
| Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7900 | cred = nfs4_get_clid_cred(clp); | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7901 | ret = nfs4_proc_destroy_clientid(clp, cred); | 
|  | 7902 | if (cred) | 
|  | 7903 | put_rpccred(cred); | 
|  | 7904 | switch (ret) { | 
|  | 7905 | case 0: | 
|  | 7906 | case -NFS4ERR_STALE_CLIENTID: | 
|  | 7907 | clp->cl_exchange_flags = 0; | 
|  | 7908 | } | 
|  | 7909 | out: | 
|  | 7910 | return ret; | 
|  | 7911 | } | 
|  | 7912 |  | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7913 | struct nfs4_get_lease_time_data { | 
|  | 7914 | struct nfs4_get_lease_time_args *args; | 
|  | 7915 | struct nfs4_get_lease_time_res *res; | 
|  | 7916 | struct nfs_client *clp; | 
|  | 7917 | }; | 
|  | 7918 |  | 
|  | 7919 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, | 
|  | 7920 | void *calldata) | 
|  | 7921 | { | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7922 | struct nfs4_get_lease_time_data *data = | 
|  | 7923 | (struct nfs4_get_lease_time_data *)calldata; | 
|  | 7924 |  | 
|  | 7925 | dprintk("--> %s\n", __func__); | 
|  | 7926 | /* just setup sequence, do not trigger session recovery | 
|  | 7927 | since we're invoked within one */ | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7928 | nfs4_setup_sequence(data->clp, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7929 | &data->args->la_seq_args, | 
|  | 7930 | &data->res->lr_seq_res, | 
|  | 7931 | task); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7932 | dprintk("<-- %s\n", __func__); | 
|  | 7933 | } | 
|  | 7934 |  | 
|  | 7935 | /* | 
|  | 7936 | * Called from nfs4_state_manager thread for session setup, so don't recover | 
|  | 7937 | * from sequence operation or clientid errors. | 
|  | 7938 | */ | 
|  | 7939 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) | 
|  | 7940 | { | 
|  | 7941 | struct nfs4_get_lease_time_data *data = | 
|  | 7942 | (struct nfs4_get_lease_time_data *)calldata; | 
|  | 7943 |  | 
|  | 7944 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7945 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) | 
|  | 7946 | return; | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7947 | switch (task->tk_status) { | 
|  | 7948 | case -NFS4ERR_DELAY: | 
|  | 7949 | case -NFS4ERR_GRACE: | 
|  | 7950 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); | 
|  | 7951 | rpc_delay(task, NFS4_POLL_RETRY_MIN); | 
|  | 7952 | task->tk_status = 0; | 
| Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7953 | /* fall through */ | 
|  | 7954 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7955 | rpc_restart_call_prepare(task); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7956 | return; | 
|  | 7957 | } | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7958 | dprintk("<-- %s\n", __func__); | 
|  | 7959 | } | 
|  | 7960 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7961 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7962 | .rpc_call_prepare = nfs4_get_lease_time_prepare, | 
|  | 7963 | .rpc_call_done = nfs4_get_lease_time_done, | 
|  | 7964 | }; | 
|  | 7965 |  | 
|  | 7966 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) | 
|  | 7967 | { | 
|  | 7968 | struct rpc_task *task; | 
|  | 7969 | struct nfs4_get_lease_time_args args; | 
|  | 7970 | struct nfs4_get_lease_time_res res = { | 
|  | 7971 | .lr_fsinfo = fsinfo, | 
|  | 7972 | }; | 
|  | 7973 | struct nfs4_get_lease_time_data data = { | 
|  | 7974 | .args = &args, | 
|  | 7975 | .res = &res, | 
|  | 7976 | .clp = clp, | 
|  | 7977 | }; | 
|  | 7978 | struct rpc_message msg = { | 
|  | 7979 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], | 
|  | 7980 | .rpc_argp = &args, | 
|  | 7981 | .rpc_resp = &res, | 
|  | 7982 | }; | 
|  | 7983 | struct rpc_task_setup task_setup = { | 
|  | 7984 | .rpc_client = clp->cl_rpcclient, | 
|  | 7985 | .rpc_message = &msg, | 
|  | 7986 | .callback_ops = &nfs4_get_lease_time_ops, | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7987 | .callback_data = &data, | 
|  | 7988 | .flags = RPC_TASK_TIMEOUT, | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7989 | }; | 
|  | 7990 | int status; | 
|  | 7991 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7992 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7993 | nfs4_set_sequence_privileged(&args.la_seq_args); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7994 | task = rpc_run_task(&task_setup); | 
|  | 7995 |  | 
|  | 7996 | if (IS_ERR(task)) | 
| Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7997 | return PTR_ERR(task); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7998 |  | 
| Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7999 | status = task->tk_status; | 
|  | 8000 | rpc_put_task(task); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8001 | return status; | 
|  | 8002 | } | 
|  | 8003 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8004 | /* | 
|  | 8005 | * Initialize the values to be used by the client in CREATE_SESSION | 
|  | 8006 | * If nfs4_init_session set the fore channel request and response sizes, | 
|  | 8007 | * use them. | 
|  | 8008 | * | 
|  | 8009 | * Set the back channel max_resp_sz_cached to zero to force the client to | 
|  | 8010 | * always set csa_cachethis to FALSE because the current implementation | 
|  | 8011 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. | 
|  | 8012 | */ | 
| Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8013 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, | 
|  | 8014 | struct rpc_clnt *clnt) | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8015 | { | 
| Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8016 | unsigned int max_rqst_sz, max_resp_sz; | 
| Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8017 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8018 |  | 
| Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8019 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; | 
|  | 8020 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; | 
|  | 8021 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8022 | /* Fore channel attributes */ | 
| Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8023 | args->fc_attrs.max_rqst_sz = max_rqst_sz; | 
|  | 8024 | args->fc_attrs.max_resp_sz = max_resp_sz; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8025 | args->fc_attrs.max_ops = NFS4_MAX_OPS; | 
| Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8026 | args->fc_attrs.max_reqs = max_session_slots; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8027 |  | 
|  | 8028 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " | 
| Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8029 | "max_ops=%u max_reqs=%u\n", | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8030 | __func__, | 
|  | 8031 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, | 
| Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8032 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8033 |  | 
|  | 8034 | /* Back channel attributes */ | 
| Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8035 | args->bc_attrs.max_rqst_sz = max_bc_payload; | 
|  | 8036 | args->bc_attrs.max_resp_sz = max_bc_payload; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8037 | args->bc_attrs.max_resp_sz_cached = 0; | 
|  | 8038 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; | 
| Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8039 | 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] | 8040 |  | 
|  | 8041 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " | 
|  | 8042 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", | 
|  | 8043 | __func__, | 
|  | 8044 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, | 
|  | 8045 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, | 
|  | 8046 | args->bc_attrs.max_reqs); | 
|  | 8047 | } | 
|  | 8048 |  | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8049 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, | 
|  | 8050 | struct nfs41_create_session_res *res) | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8051 | { | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8052 | struct nfs4_channel_attrs *sent = &args->fc_attrs; | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8053 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8054 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8055 | if (rcvd->max_resp_sz > sent->max_resp_sz) | 
|  | 8056 | return -EINVAL; | 
|  | 8057 | /* | 
|  | 8058 | * Our requested max_ops is the minimum we need; we're not | 
|  | 8059 | * prepared to break up compounds into smaller pieces than that. | 
|  | 8060 | * So, no point even trying to continue if the server won't | 
|  | 8061 | * cooperate: | 
|  | 8062 | */ | 
|  | 8063 | if (rcvd->max_ops < sent->max_ops) | 
|  | 8064 | return -EINVAL; | 
|  | 8065 | if (rcvd->max_reqs == 0) | 
|  | 8066 | return -EINVAL; | 
| Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8067 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) | 
|  | 8068 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8069 | return 0; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8070 | } | 
|  | 8071 |  | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8072 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, | 
|  | 8073 | struct nfs41_create_session_res *res) | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8074 | { | 
|  | 8075 | struct nfs4_channel_attrs *sent = &args->bc_attrs; | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8076 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8077 |  | 
| Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8078 | if (!(res->flags & SESSION4_BACK_CHAN)) | 
|  | 8079 | goto out; | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8080 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) | 
|  | 8081 | return -EINVAL; | 
|  | 8082 | if (rcvd->max_resp_sz < sent->max_resp_sz) | 
|  | 8083 | return -EINVAL; | 
|  | 8084 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) | 
|  | 8085 | return -EINVAL; | 
| Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8086 | if (rcvd->max_ops > sent->max_ops) | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8087 | return -EINVAL; | 
| Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8088 | if (rcvd->max_reqs > sent->max_reqs) | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8089 | return -EINVAL; | 
| Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8090 | out: | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8091 | return 0; | 
|  | 8092 | } | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8093 |  | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8094 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8095 | struct nfs41_create_session_res *res) | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8096 | { | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8097 | int ret; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8098 |  | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8099 | ret = nfs4_verify_fore_channel_attrs(args, res); | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8100 | if (ret) | 
|  | 8101 | return ret; | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8102 | return nfs4_verify_back_channel_attrs(args, res); | 
|  | 8103 | } | 
|  | 8104 |  | 
|  | 8105 | static void nfs4_update_session(struct nfs4_session *session, | 
|  | 8106 | struct nfs41_create_session_res *res) | 
|  | 8107 | { | 
|  | 8108 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); | 
| Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8109 | /* Mark client id and session as being confirmed */ | 
|  | 8110 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; | 
|  | 8111 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8112 | session->flags = res->flags; | 
|  | 8113 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); | 
| Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8114 | if (res->flags & SESSION4_BACK_CHAN) | 
|  | 8115 | memcpy(&session->bc_attrs, &res->bc_attrs, | 
|  | 8116 | sizeof(session->bc_attrs)); | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8117 | } | 
|  | 8118 |  | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8119 | static int _nfs4_proc_create_session(struct nfs_client *clp, | 
|  | 8120 | struct rpc_cred *cred) | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8121 | { | 
|  | 8122 | struct nfs4_session *session = clp->cl_session; | 
|  | 8123 | struct nfs41_create_session_args args = { | 
|  | 8124 | .client = clp, | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8125 | .clientid = clp->cl_clientid, | 
|  | 8126 | .seqid = clp->cl_seqid, | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8127 | .cb_program = NFS4_CALLBACK, | 
|  | 8128 | }; | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8129 | struct nfs41_create_session_res res; | 
|  | 8130 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8131 | struct rpc_message msg = { | 
|  | 8132 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], | 
|  | 8133 | .rpc_argp = &args, | 
|  | 8134 | .rpc_resp = &res, | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8135 | .rpc_cred = cred, | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8136 | }; | 
|  | 8137 | int status; | 
|  | 8138 |  | 
| Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8139 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); | 
| Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8140 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8141 |  | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8142 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8143 | trace_nfs4_create_session(clp, status); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8144 |  | 
| Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8145 | switch (status) { | 
|  | 8146 | case -NFS4ERR_STALE_CLIENTID: | 
|  | 8147 | case -NFS4ERR_DELAY: | 
|  | 8148 | case -ETIMEDOUT: | 
|  | 8149 | case -EACCES: | 
|  | 8150 | case -EAGAIN: | 
|  | 8151 | goto out; | 
|  | 8152 | }; | 
|  | 8153 |  | 
|  | 8154 | clp->cl_seqid++; | 
| Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8155 | if (!status) { | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8156 | /* Verify the session's negotiated channel_attrs values */ | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8157 | status = nfs4_verify_channel_attrs(&args, &res); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8158 | /* Increment the clientid slot sequence id */ | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8159 | if (status) | 
|  | 8160 | goto out; | 
|  | 8161 | nfs4_update_session(session, &res); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8162 | } | 
| Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8163 | out: | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8164 | return status; | 
|  | 8165 | } | 
|  | 8166 |  | 
|  | 8167 | /* | 
|  | 8168 | * Issues a CREATE_SESSION operation to the server. | 
|  | 8169 | * It is the responsibility of the caller to verify the session is | 
|  | 8170 | * expired before calling this routine. | 
|  | 8171 | */ | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8172 | 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] | 8173 | { | 
|  | 8174 | int status; | 
|  | 8175 | unsigned *ptr; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8176 | struct nfs4_session *session = clp->cl_session; | 
|  | 8177 |  | 
|  | 8178 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); | 
|  | 8179 |  | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8180 | status = _nfs4_proc_create_session(clp, cred); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8181 | if (status) | 
|  | 8182 | goto out; | 
|  | 8183 |  | 
| Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8184 | /* Init or reset the session slot tables */ | 
|  | 8185 | status = nfs4_setup_session_slot_tables(session); | 
|  | 8186 | dprintk("slot table setup returned %d\n", status); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8187 | if (status) | 
|  | 8188 | goto out; | 
|  | 8189 |  | 
|  | 8190 | ptr = (unsigned *)&session->sess_id.data[0]; | 
|  | 8191 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, | 
|  | 8192 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8193 | out: | 
|  | 8194 | dprintk("<-- %s\n", __func__); | 
|  | 8195 | return status; | 
|  | 8196 | } | 
|  | 8197 |  | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8198 | /* | 
|  | 8199 | * Issue the over-the-wire RPC DESTROY_SESSION. | 
|  | 8200 | * The caller must serialize access to this routine. | 
|  | 8201 | */ | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8202 | int nfs4_proc_destroy_session(struct nfs4_session *session, | 
|  | 8203 | struct rpc_cred *cred) | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8204 | { | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8205 | struct rpc_message msg = { | 
|  | 8206 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], | 
|  | 8207 | .rpc_argp = session, | 
|  | 8208 | .rpc_cred = cred, | 
|  | 8209 | }; | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8210 | int status = 0; | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8211 |  | 
|  | 8212 | dprintk("--> nfs4_proc_destroy_session\n"); | 
|  | 8213 |  | 
|  | 8214 | /* session is still being setup */ | 
| Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8215 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) | 
|  | 8216 | return 0; | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8217 |  | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8218 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8219 | trace_nfs4_destroy_session(session->clp, status); | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8220 |  | 
|  | 8221 | if (status) | 
| Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8222 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8223 | "Session has been destroyed regardless...\n", status); | 
|  | 8224 |  | 
|  | 8225 | dprintk("<-- nfs4_proc_destroy_session\n"); | 
|  | 8226 | return status; | 
|  | 8227 | } | 
|  | 8228 |  | 
| Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8229 | /* | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8230 | * Renew the cl_session lease. | 
|  | 8231 | */ | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8232 | struct nfs4_sequence_data { | 
|  | 8233 | struct nfs_client *clp; | 
|  | 8234 | struct nfs4_sequence_args args; | 
|  | 8235 | struct nfs4_sequence_res res; | 
|  | 8236 | }; | 
|  | 8237 |  | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8238 | static void nfs41_sequence_release(void *data) | 
|  | 8239 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8240 | struct nfs4_sequence_data *calldata = data; | 
|  | 8241 | struct nfs_client *clp = calldata->clp; | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8242 |  | 
| Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8243 | if (refcount_read(&clp->cl_count) > 1) | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8244 | nfs4_schedule_state_renewal(clp); | 
|  | 8245 | nfs_put_client(clp); | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8246 | kfree(calldata); | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8247 | } | 
|  | 8248 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8249 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) | 
|  | 8250 | { | 
|  | 8251 | switch(task->tk_status) { | 
|  | 8252 | case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8253 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
|  | 8254 | return -EAGAIN; | 
|  | 8255 | default: | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8256 | nfs4_schedule_lease_recovery(clp); | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8257 | } | 
|  | 8258 | return 0; | 
|  | 8259 | } | 
|  | 8260 |  | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8261 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8262 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8263 | struct nfs4_sequence_data *calldata = data; | 
|  | 8264 | struct nfs_client *clp = calldata->clp; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8265 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8266 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) | 
|  | 8267 | return; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8268 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8269 | trace_nfs4_sequence(clp, task->tk_status); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8270 | if (task->tk_status < 0) { | 
|  | 8271 | dprintk("%s ERROR %d\n", __func__, task->tk_status); | 
| Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8272 | if (refcount_read(&clp->cl_count) == 1) | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8273 | goto out; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8274 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8275 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { | 
|  | 8276 | rpc_restart_call_prepare(task); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8277 | return; | 
|  | 8278 | } | 
|  | 8279 | } | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8280 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8281 | out: | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8282 | dprintk("<-- %s\n", __func__); | 
|  | 8283 | } | 
|  | 8284 |  | 
|  | 8285 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) | 
|  | 8286 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8287 | struct nfs4_sequence_data *calldata = data; | 
|  | 8288 | struct nfs_client *clp = calldata->clp; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8289 | struct nfs4_sequence_args *args; | 
|  | 8290 | struct nfs4_sequence_res *res; | 
|  | 8291 |  | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8292 | args = task->tk_msg.rpc_argp; | 
|  | 8293 | res = task->tk_msg.rpc_resp; | 
|  | 8294 |  | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8295 | nfs4_setup_sequence(clp, args, res, task); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8296 | } | 
|  | 8297 |  | 
|  | 8298 | static const struct rpc_call_ops nfs41_sequence_ops = { | 
|  | 8299 | .rpc_call_done = nfs41_sequence_call_done, | 
|  | 8300 | .rpc_call_prepare = nfs41_sequence_prepare, | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8301 | .rpc_release = nfs41_sequence_release, | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8302 | }; | 
|  | 8303 |  | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8304 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, | 
|  | 8305 | struct rpc_cred *cred, | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8306 | struct nfs4_slot *slot, | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8307 | bool is_privileged) | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8308 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8309 | struct nfs4_sequence_data *calldata; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8310 | struct rpc_message msg = { | 
|  | 8311 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], | 
|  | 8312 | .rpc_cred = cred, | 
|  | 8313 | }; | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8314 | struct rpc_task_setup task_setup_data = { | 
|  | 8315 | .rpc_client = clp->cl_rpcclient, | 
|  | 8316 | .rpc_message = &msg, | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8317 | .callback_ops = &nfs41_sequence_ops, | 
| Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8318 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8319 | }; | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8320 | struct rpc_task *ret; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8321 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8322 | ret = ERR_PTR(-EIO); | 
| Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8323 | if (!refcount_inc_not_zero(&clp->cl_count)) | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8324 | goto out_err; | 
|  | 8325 |  | 
|  | 8326 | ret = ERR_PTR(-ENOMEM); | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8327 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8328 | if (calldata == NULL) | 
|  | 8329 | goto out_put_clp; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8330 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8331 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8332 | if (is_privileged) | 
|  | 8333 | nfs4_set_sequence_privileged(&calldata->args); | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8334 | msg.rpc_argp = &calldata->args; | 
|  | 8335 | msg.rpc_resp = &calldata->res; | 
|  | 8336 | calldata->clp = clp; | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8337 | task_setup_data.callback_data = calldata; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8338 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8339 | ret = rpc_run_task(&task_setup_data); | 
|  | 8340 | if (IS_ERR(ret)) | 
|  | 8341 | goto out_err; | 
|  | 8342 | return ret; | 
|  | 8343 | out_put_clp: | 
|  | 8344 | nfs_put_client(clp); | 
|  | 8345 | out_err: | 
|  | 8346 | nfs41_release_slot(slot); | 
|  | 8347 | return ret; | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8348 | } | 
|  | 8349 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8350 | 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] | 8351 | { | 
|  | 8352 | struct rpc_task *task; | 
|  | 8353 | int ret = 0; | 
|  | 8354 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8355 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) | 
| Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8356 | return -EAGAIN; | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8357 | task = _nfs41_proc_sequence(clp, cred, NULL, false); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8358 | if (IS_ERR(task)) | 
|  | 8359 | ret = PTR_ERR(task); | 
|  | 8360 | else | 
| Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8361 | rpc_put_task_async(task); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8362 | dprintk("<-- %s status=%d\n", __func__, ret); | 
|  | 8363 | return ret; | 
|  | 8364 | } | 
|  | 8365 |  | 
|  | 8366 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) | 
|  | 8367 | { | 
|  | 8368 | struct rpc_task *task; | 
|  | 8369 | int ret; | 
|  | 8370 |  | 
| Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8371 | task = _nfs41_proc_sequence(clp, cred, NULL, true); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8372 | if (IS_ERR(task)) { | 
|  | 8373 | ret = PTR_ERR(task); | 
|  | 8374 | goto out; | 
|  | 8375 | } | 
|  | 8376 | ret = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8377 | if (!ret) | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8378 | ret = task->tk_status; | 
|  | 8379 | rpc_put_task(task); | 
|  | 8380 | out: | 
|  | 8381 | dprintk("<-- %s status=%d\n", __func__, ret); | 
|  | 8382 | return ret; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8383 | } | 
|  | 8384 |  | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8385 | struct nfs4_reclaim_complete_data { | 
|  | 8386 | struct nfs_client *clp; | 
|  | 8387 | struct nfs41_reclaim_complete_args arg; | 
|  | 8388 | struct nfs41_reclaim_complete_res res; | 
|  | 8389 | }; | 
|  | 8390 |  | 
|  | 8391 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) | 
|  | 8392 | { | 
|  | 8393 | struct nfs4_reclaim_complete_data *calldata = data; | 
|  | 8394 |  | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8395 | nfs4_setup_sequence(calldata->clp, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8396 | &calldata->arg.seq_args, | 
|  | 8397 | &calldata->res.seq_res, | 
|  | 8398 | task); | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8399 | } | 
|  | 8400 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8401 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) | 
|  | 8402 | { | 
|  | 8403 | switch(task->tk_status) { | 
|  | 8404 | case 0: | 
|  | 8405 | case -NFS4ERR_COMPLETE_ALREADY: | 
|  | 8406 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ | 
|  | 8407 | break; | 
|  | 8408 | case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8409 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
| Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8410 | /* fall through */ | 
|  | 8411 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8412 | return -EAGAIN; | 
| Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8413 | case -NFS4ERR_BADSESSION: | 
|  | 8414 | case -NFS4ERR_DEADSESSION: | 
|  | 8415 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|  | 8416 | nfs4_schedule_session_recovery(clp->cl_session, | 
|  | 8417 | task->tk_status); | 
|  | 8418 | break; | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8419 | default: | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8420 | nfs4_schedule_lease_recovery(clp); | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8421 | } | 
|  | 8422 | return 0; | 
|  | 8423 | } | 
|  | 8424 |  | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8425 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) | 
|  | 8426 | { | 
|  | 8427 | struct nfs4_reclaim_complete_data *calldata = data; | 
|  | 8428 | struct nfs_client *clp = calldata->clp; | 
|  | 8429 | struct nfs4_sequence_res *res = &calldata->res.seq_res; | 
|  | 8430 |  | 
|  | 8431 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8432 | if (!nfs41_sequence_done(task, res)) | 
|  | 8433 | return; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8434 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8435 | trace_nfs4_reclaim_complete(clp, task->tk_status); | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8436 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { | 
|  | 8437 | rpc_restart_call_prepare(task); | 
|  | 8438 | return; | 
|  | 8439 | } | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8440 | dprintk("<-- %s\n", __func__); | 
|  | 8441 | } | 
|  | 8442 |  | 
|  | 8443 | static void nfs4_free_reclaim_complete_data(void *data) | 
|  | 8444 | { | 
|  | 8445 | struct nfs4_reclaim_complete_data *calldata = data; | 
|  | 8446 |  | 
|  | 8447 | kfree(calldata); | 
|  | 8448 | } | 
|  | 8449 |  | 
|  | 8450 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { | 
|  | 8451 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, | 
|  | 8452 | .rpc_call_done = nfs4_reclaim_complete_done, | 
|  | 8453 | .rpc_release = nfs4_free_reclaim_complete_data, | 
|  | 8454 | }; | 
|  | 8455 |  | 
|  | 8456 | /* | 
|  | 8457 | * Issue a global reclaim complete. | 
|  | 8458 | */ | 
| Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8459 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, | 
|  | 8460 | struct rpc_cred *cred) | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8461 | { | 
|  | 8462 | struct nfs4_reclaim_complete_data *calldata; | 
|  | 8463 | struct rpc_task *task; | 
|  | 8464 | struct rpc_message msg = { | 
|  | 8465 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], | 
| Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8466 | .rpc_cred = cred, | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8467 | }; | 
|  | 8468 | struct rpc_task_setup task_setup_data = { | 
|  | 8469 | .rpc_client = clp->cl_rpcclient, | 
|  | 8470 | .rpc_message = &msg, | 
|  | 8471 | .callback_ops = &nfs4_reclaim_complete_call_ops, | 
|  | 8472 | .flags = RPC_TASK_ASYNC, | 
|  | 8473 | }; | 
|  | 8474 | int status = -ENOMEM; | 
|  | 8475 |  | 
|  | 8476 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8477 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8478 | if (calldata == NULL) | 
|  | 8479 | goto out; | 
|  | 8480 | calldata->clp = clp; | 
|  | 8481 | calldata->arg.one_fs = 0; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8482 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8483 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8484 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8485 | msg.rpc_argp = &calldata->arg; | 
|  | 8486 | msg.rpc_resp = &calldata->res; | 
|  | 8487 | task_setup_data.callback_data = calldata; | 
|  | 8488 | task = rpc_run_task(&task_setup_data); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8489 | if (IS_ERR(task)) { | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8490 | status = PTR_ERR(task); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8491 | goto out; | 
|  | 8492 | } | 
| Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8493 | status = rpc_wait_for_completion_task(task); | 
| Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8494 | if (status == 0) | 
|  | 8495 | status = task->tk_status; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8496 | rpc_put_task(task); | 
|  | 8497 | out: | 
|  | 8498 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 8499 | return status; | 
|  | 8500 | } | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8501 |  | 
|  | 8502 | static void | 
|  | 8503 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) | 
|  | 8504 | { | 
|  | 8505 | struct nfs4_layoutget *lgp = calldata; | 
| Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8506 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8507 |  | 
|  | 8508 | dprintk("--> %s\n", __func__); | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8509 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8510 | &lgp->res.seq_res, task); | 
|  | 8511 | dprintk("<-- %s\n", __func__); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8512 | } | 
|  | 8513 |  | 
|  | 8514 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) | 
|  | 8515 | { | 
|  | 8516 | struct nfs4_layoutget *lgp = calldata; | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8517 |  | 
|  | 8518 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8519 | nfs41_sequence_process(task, &lgp->res.seq_res); | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8520 | dprintk("<-- %s\n", __func__); | 
|  | 8521 | } | 
|  | 8522 |  | 
|  | 8523 | static int | 
|  | 8524 | nfs4_layoutget_handle_exception(struct rpc_task *task, | 
|  | 8525 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) | 
|  | 8526 | { | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8527 | struct inode *inode = lgp->args.inode; | 
|  | 8528 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 8529 | struct pnfs_layout_hdr *lo; | 
| Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8530 | int nfs4err = task->tk_status; | 
|  | 8531 | int err, status = 0; | 
| Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8532 | LIST_HEAD(head); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8533 |  | 
| Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8534 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8535 |  | 
| Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8536 | switch (nfs4err) { | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8537 | case 0: | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8538 | goto out; | 
| Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8539 |  | 
|  | 8540 | /* | 
|  | 8541 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs | 
|  | 8542 | * on the file. set tk_status to -ENODATA to tell upper layer to | 
|  | 8543 | * retry go inband. | 
|  | 8544 | */ | 
|  | 8545 | case -NFS4ERR_LAYOUTUNAVAILABLE: | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8546 | status = -ENODATA; | 
| Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8547 | goto out; | 
| Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8548 | /* | 
| Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8549 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of | 
|  | 8550 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). | 
|  | 8551 | */ | 
|  | 8552 | case -NFS4ERR_BADLAYOUT: | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8553 | status = -EOVERFLOW; | 
|  | 8554 | goto out; | 
| Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8555 | /* | 
| Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8556 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client | 
| Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8557 | * (or clients) writing to the same RAID stripe except when | 
|  | 8558 | * the minlength argument is 0 (see RFC5661 section 18.43.3). | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8559 | * | 
|  | 8560 | * Treat it like we would RECALLCONFLICT -- we retry for a little | 
|  | 8561 | * while, and then eventually give up. | 
| Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8562 | */ | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8563 | case -NFS4ERR_LAYOUTTRYLATER: | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8564 | if (lgp->args.minlength == 0) { | 
|  | 8565 | status = -EOVERFLOW; | 
|  | 8566 | goto out; | 
| Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8567 | } | 
| Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8568 | status = -EBUSY; | 
|  | 8569 | break; | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8570 | case -NFS4ERR_RECALLCONFLICT: | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8571 | status = -ERECALLCONFLICT; | 
| Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8572 | break; | 
| Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8573 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 8574 | case -NFS4ERR_ADMIN_REVOKED: | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8575 | case -NFS4ERR_EXPIRED: | 
|  | 8576 | case -NFS4ERR_BAD_STATEID: | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8577 | exception->timeout = 0; | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8578 | spin_lock(&inode->i_lock); | 
| Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8579 | lo = NFS_I(inode)->layout; | 
|  | 8580 | /* If the open stateid was bad, then recover it. */ | 
|  | 8581 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || | 
| Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8582 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8583 | spin_unlock(&inode->i_lock); | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8584 | exception->state = lgp->args.ctx->state; | 
| Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8585 | exception->stateid = &lgp->args.stateid; | 
| Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8586 | break; | 
|  | 8587 | } | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8588 |  | 
| Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8589 | /* | 
|  | 8590 | * Mark the bad layout state as invalid, then retry | 
|  | 8591 | */ | 
| Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8592 | pnfs_mark_layout_stateid_invalid(lo, &head); | 
| Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8593 | spin_unlock(&inode->i_lock); | 
| Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8594 | nfs_commit_inode(inode, 0); | 
| Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8595 | pnfs_free_lseg_list(&head); | 
|  | 8596 | status = -EAGAIN; | 
|  | 8597 | goto out; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8598 | } | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8599 |  | 
| Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8600 | nfs4_sequence_free_slot(&lgp->res.seq_res); | 
| Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8601 | err = nfs4_handle_exception(server, nfs4err, exception); | 
|  | 8602 | if (!status) { | 
|  | 8603 | if (exception->retry) | 
|  | 8604 | status = -EAGAIN; | 
|  | 8605 | else | 
|  | 8606 | status = err; | 
|  | 8607 | } | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8608 | out: | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8609 | dprintk("<-- %s\n", __func__); | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8610 | return status; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8611 | } | 
|  | 8612 |  | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8613 | static size_t max_response_pages(struct nfs_server *server) | 
|  | 8614 | { | 
|  | 8615 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; | 
|  | 8616 | return nfs_page_array_len(0, max_resp_sz); | 
|  | 8617 | } | 
|  | 8618 |  | 
|  | 8619 | static void nfs4_free_pages(struct page **pages, size_t size) | 
|  | 8620 | { | 
|  | 8621 | int i; | 
|  | 8622 |  | 
|  | 8623 | if (!pages) | 
|  | 8624 | return; | 
|  | 8625 |  | 
|  | 8626 | for (i = 0; i < size; i++) { | 
|  | 8627 | if (!pages[i]) | 
|  | 8628 | break; | 
|  | 8629 | __free_page(pages[i]); | 
|  | 8630 | } | 
|  | 8631 | kfree(pages); | 
|  | 8632 | } | 
|  | 8633 |  | 
|  | 8634 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) | 
|  | 8635 | { | 
|  | 8636 | struct page **pages; | 
|  | 8637 | int i; | 
|  | 8638 |  | 
|  | 8639 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); | 
|  | 8640 | if (!pages) { | 
|  | 8641 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); | 
|  | 8642 | return NULL; | 
|  | 8643 | } | 
|  | 8644 |  | 
|  | 8645 | for (i = 0; i < size; i++) { | 
|  | 8646 | pages[i] = alloc_page(gfp_flags); | 
|  | 8647 | if (!pages[i]) { | 
|  | 8648 | dprintk("%s: failed to allocate page\n", __func__); | 
|  | 8649 | nfs4_free_pages(pages, size); | 
|  | 8650 | return NULL; | 
|  | 8651 | } | 
|  | 8652 | } | 
|  | 8653 |  | 
|  | 8654 | return pages; | 
|  | 8655 | } | 
|  | 8656 |  | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8657 | static void nfs4_layoutget_release(void *calldata) | 
|  | 8658 | { | 
|  | 8659 | struct nfs4_layoutget *lgp = calldata; | 
| Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8660 | struct inode *inode = lgp->args.inode; | 
|  | 8661 | struct nfs_server *server = NFS_SERVER(inode); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8662 | size_t max_pages = max_response_pages(server); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8663 |  | 
|  | 8664 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8665 | nfs4_sequence_free_slot(&lgp->res.seq_res); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8666 | nfs4_free_pages(lgp->args.layout.pages, max_pages); | 
| Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8667 | pnfs_put_layout_hdr(NFS_I(inode)->layout); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8668 | put_nfs_open_context(lgp->args.ctx); | 
|  | 8669 | kfree(calldata); | 
|  | 8670 | dprintk("<-- %s\n", __func__); | 
|  | 8671 | } | 
|  | 8672 |  | 
|  | 8673 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { | 
|  | 8674 | .rpc_call_prepare = nfs4_layoutget_prepare, | 
|  | 8675 | .rpc_call_done = nfs4_layoutget_done, | 
|  | 8676 | .rpc_release = nfs4_layoutget_release, | 
|  | 8677 | }; | 
|  | 8678 |  | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8679 | struct pnfs_layout_segment * | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8680 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout, gfp_t gfp_flags) | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8681 | { | 
| Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8682 | struct inode *inode = lgp->args.inode; | 
|  | 8683 | struct nfs_server *server = NFS_SERVER(inode); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8684 | size_t max_pages = max_response_pages(server); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8685 | struct rpc_task *task; | 
|  | 8686 | struct rpc_message msg = { | 
|  | 8687 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], | 
|  | 8688 | .rpc_argp = &lgp->args, | 
|  | 8689 | .rpc_resp = &lgp->res, | 
| Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8690 | .rpc_cred = lgp->cred, | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8691 | }; | 
|  | 8692 | struct rpc_task_setup task_setup_data = { | 
|  | 8693 | .rpc_client = server->client, | 
|  | 8694 | .rpc_message = &msg, | 
|  | 8695 | .callback_ops = &nfs4_layoutget_call_ops, | 
|  | 8696 | .callback_data = lgp, | 
|  | 8697 | .flags = RPC_TASK_ASYNC, | 
|  | 8698 | }; | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8699 | struct pnfs_layout_segment *lseg = NULL; | 
| Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8700 | struct nfs4_exception exception = { | 
|  | 8701 | .inode = inode, | 
|  | 8702 | .timeout = *timeout, | 
|  | 8703 | }; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8704 | int status = 0; | 
|  | 8705 |  | 
|  | 8706 | dprintk("--> %s\n", __func__); | 
|  | 8707 |  | 
| Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8708 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ | 
|  | 8709 | pnfs_get_layout_hdr(NFS_I(inode)->layout); | 
|  | 8710 |  | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8711 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); | 
|  | 8712 | if (!lgp->args.layout.pages) { | 
|  | 8713 | nfs4_layoutget_release(lgp); | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8714 | return ERR_PTR(-ENOMEM); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8715 | } | 
|  | 8716 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; | 
|  | 8717 |  | 
| Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8718 | lgp->res.layoutp = &lgp->args.layout; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8719 | lgp->res.seq_res.sr_slot = NULL; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8720 | nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); | 
| Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8721 |  | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8722 | task = rpc_run_task(&task_setup_data); | 
|  | 8723 | if (IS_ERR(task)) | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8724 | return ERR_CAST(task); | 
| Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8725 | status = rpc_wait_for_completion_task(task); | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8726 | if (status == 0) { | 
|  | 8727 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); | 
|  | 8728 | *timeout = exception.timeout; | 
|  | 8729 | } | 
|  | 8730 |  | 
| Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8731 | trace_nfs4_layoutget(lgp->args.ctx, | 
|  | 8732 | &lgp->args.range, | 
|  | 8733 | &lgp->res.range, | 
| Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8734 | &lgp->res.stateid, | 
| Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8735 | status); | 
| Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8736 |  | 
| Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8737 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ | 
|  | 8738 | if (status == 0 && lgp->res.layoutp->len) | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8739 | lseg = pnfs_layout_process(lgp); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8740 | rpc_put_task(task); | 
|  | 8741 | dprintk("<-- %s status=%d\n", __func__, status); | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8742 | if (status) | 
|  | 8743 | return ERR_PTR(status); | 
|  | 8744 | return lseg; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8745 | } | 
|  | 8746 |  | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8747 | static void | 
|  | 8748 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) | 
|  | 8749 | { | 
|  | 8750 | struct nfs4_layoutreturn *lrp = calldata; | 
|  | 8751 |  | 
|  | 8752 | dprintk("--> %s\n", __func__); | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8753 | nfs4_setup_sequence(lrp->clp, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8754 | &lrp->args.seq_args, | 
|  | 8755 | &lrp->res.seq_res, | 
|  | 8756 | task); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8757 | } | 
|  | 8758 |  | 
|  | 8759 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) | 
|  | 8760 | { | 
|  | 8761 | struct nfs4_layoutreturn *lrp = calldata; | 
|  | 8762 | struct nfs_server *server; | 
|  | 8763 |  | 
|  | 8764 | dprintk("--> %s\n", __func__); | 
|  | 8765 |  | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8766 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8767 | return; | 
|  | 8768 |  | 
|  | 8769 | server = NFS_SERVER(lrp->args.inode); | 
| Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8770 | switch (task->tk_status) { | 
| Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8771 | case -NFS4ERR_OLD_STATEID: | 
|  | 8772 | if (nfs4_refresh_layout_stateid(&lrp->args.stateid, | 
|  | 8773 | lrp->args.inode)) | 
|  | 8774 | goto out_restart; | 
|  | 8775 | /* Fallthrough */ | 
| Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8776 | default: | 
|  | 8777 | task->tk_status = 0; | 
| Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8778 | /* Fallthrough */ | 
| Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8779 | case 0: | 
|  | 8780 | break; | 
|  | 8781 | case -NFS4ERR_DELAY: | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8782 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) | 
| Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8783 | break; | 
| Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8784 | goto out_restart; | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8785 | } | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8786 | dprintk("<-- %s\n", __func__); | 
| Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8787 | return; | 
|  | 8788 | out_restart: | 
|  | 8789 | task->tk_status = 0; | 
|  | 8790 | nfs4_sequence_free_slot(&lrp->res.seq_res); | 
|  | 8791 | rpc_restart_call_prepare(task); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8792 | } | 
|  | 8793 |  | 
|  | 8794 | static void nfs4_layoutreturn_release(void *calldata) | 
|  | 8795 | { | 
|  | 8796 | struct nfs4_layoutreturn *lrp = calldata; | 
| Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8797 | struct pnfs_layout_hdr *lo = lrp->args.layout; | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8798 |  | 
|  | 8799 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8800 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, | 
| Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8801 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); | 
| Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8802 | nfs4_sequence_free_slot(&lrp->res.seq_res); | 
| Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8803 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) | 
|  | 8804 | lrp->ld_private.ops->free(&lrp->ld_private); | 
| Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8805 | pnfs_put_layout_hdr(lrp->args.layout); | 
|  | 8806 | nfs_iput_and_deactive(lrp->inode); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8807 | kfree(calldata); | 
|  | 8808 | dprintk("<-- %s\n", __func__); | 
|  | 8809 | } | 
|  | 8810 |  | 
|  | 8811 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { | 
|  | 8812 | .rpc_call_prepare = nfs4_layoutreturn_prepare, | 
|  | 8813 | .rpc_call_done = nfs4_layoutreturn_done, | 
|  | 8814 | .rpc_release = nfs4_layoutreturn_release, | 
|  | 8815 | }; | 
|  | 8816 |  | 
| Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8817 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8818 | { | 
|  | 8819 | struct rpc_task *task; | 
|  | 8820 | struct rpc_message msg = { | 
|  | 8821 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], | 
|  | 8822 | .rpc_argp = &lrp->args, | 
|  | 8823 | .rpc_resp = &lrp->res, | 
| Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8824 | .rpc_cred = lrp->cred, | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8825 | }; | 
|  | 8826 | struct rpc_task_setup task_setup_data = { | 
| Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8827 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8828 | .rpc_message = &msg, | 
|  | 8829 | .callback_ops = &nfs4_layoutreturn_call_ops, | 
|  | 8830 | .callback_data = lrp, | 
|  | 8831 | }; | 
| Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8832 | int status = 0; | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8833 |  | 
| Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8834 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, | 
|  | 8835 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, | 
|  | 8836 | &task_setup_data.rpc_client, &msg); | 
|  | 8837 |  | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8838 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8839 | if (!sync) { | 
|  | 8840 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); | 
|  | 8841 | if (!lrp->inode) { | 
|  | 8842 | nfs4_layoutreturn_release(lrp); | 
|  | 8843 | return -EAGAIN; | 
|  | 8844 | } | 
|  | 8845 | task_setup_data.flags |= RPC_TASK_ASYNC; | 
|  | 8846 | } | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8847 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8848 | task = rpc_run_task(&task_setup_data); | 
|  | 8849 | if (IS_ERR(task)) | 
|  | 8850 | return PTR_ERR(task); | 
| Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8851 | if (sync) | 
|  | 8852 | status = task->tk_status; | 
| Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8853 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8854 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 8855 | rpc_put_task(task); | 
|  | 8856 | return status; | 
|  | 8857 | } | 
|  | 8858 |  | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8859 | static int | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8860 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, | 
|  | 8861 | struct pnfs_device *pdev, | 
|  | 8862 | struct rpc_cred *cred) | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8863 | { | 
|  | 8864 | struct nfs4_getdeviceinfo_args args = { | 
|  | 8865 | .pdev = pdev, | 
| Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8866 | .notify_types = NOTIFY_DEVICEID4_CHANGE | | 
|  | 8867 | NOTIFY_DEVICEID4_DELETE, | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8868 | }; | 
|  | 8869 | struct nfs4_getdeviceinfo_res res = { | 
|  | 8870 | .pdev = pdev, | 
|  | 8871 | }; | 
|  | 8872 | struct rpc_message msg = { | 
|  | 8873 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], | 
|  | 8874 | .rpc_argp = &args, | 
|  | 8875 | .rpc_resp = &res, | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8876 | .rpc_cred = cred, | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8877 | }; | 
|  | 8878 | int status; | 
|  | 8879 |  | 
|  | 8880 | dprintk("--> %s\n", __func__); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8881 | 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] | 8882 | if (res.notification & ~args.notify_types) | 
|  | 8883 | dprintk("%s: unsupported notification\n", __func__); | 
| Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8884 | if (res.notification != args.notify_types) | 
|  | 8885 | pdev->nocache = 1; | 
| Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8886 |  | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8887 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 8888 |  | 
|  | 8889 | return status; | 
|  | 8890 | } | 
|  | 8891 |  | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8892 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, | 
|  | 8893 | struct pnfs_device *pdev, | 
|  | 8894 | struct rpc_cred *cred) | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8895 | { | 
|  | 8896 | struct nfs4_exception exception = { }; | 
|  | 8897 | int err; | 
|  | 8898 |  | 
|  | 8899 | do { | 
|  | 8900 | err = nfs4_handle_exception(server, | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8901 | _nfs4_proc_getdeviceinfo(server, pdev, cred), | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8902 | &exception); | 
|  | 8903 | } while (exception.retry); | 
|  | 8904 | return err; | 
|  | 8905 | } | 
|  | 8906 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); | 
|  | 8907 |  | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8908 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) | 
|  | 8909 | { | 
|  | 8910 | struct nfs4_layoutcommit_data *data = calldata; | 
|  | 8911 | struct nfs_server *server = NFS_SERVER(data->args.inode); | 
|  | 8912 |  | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8913 | nfs4_setup_sequence(server->nfs_client, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8914 | &data->args.seq_args, | 
|  | 8915 | &data->res.seq_res, | 
|  | 8916 | task); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8917 | } | 
|  | 8918 |  | 
|  | 8919 | static void | 
|  | 8920 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) | 
|  | 8921 | { | 
|  | 8922 | struct nfs4_layoutcommit_data *data = calldata; | 
|  | 8923 | struct nfs_server *server = NFS_SERVER(data->args.inode); | 
|  | 8924 |  | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8925 | if (!nfs41_sequence_done(task, &data->res.seq_res)) | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8926 | return; | 
|  | 8927 |  | 
|  | 8928 | switch (task->tk_status) { /* Just ignore these failures */ | 
| Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8929 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ | 
|  | 8930 | case -NFS4ERR_BADIOMODE:     /* no IOMODE_RW layout for range */ | 
|  | 8931 | case -NFS4ERR_BADLAYOUT:     /* no layout */ | 
|  | 8932 | case -NFS4ERR_GRACE:	    /* loca_recalim always false */ | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8933 | task->tk_status = 0; | 
| Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8934 | case 0: | 
| Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8935 | break; | 
|  | 8936 | default: | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8937 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { | 
| Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8938 | rpc_restart_call_prepare(task); | 
|  | 8939 | return; | 
|  | 8940 | } | 
|  | 8941 | } | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8942 | } | 
|  | 8943 |  | 
|  | 8944 | static void nfs4_layoutcommit_release(void *calldata) | 
|  | 8945 | { | 
|  | 8946 | struct nfs4_layoutcommit_data *data = calldata; | 
|  | 8947 |  | 
| Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8948 | pnfs_cleanup_layoutcommit(data); | 
| Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8949 | nfs_post_op_update_inode_force_wcc(data->args.inode, | 
|  | 8950 | data->res.fattr); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8951 | put_rpccred(data->cred); | 
| Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8952 | nfs_iput_and_deactive(data->inode); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8953 | kfree(data); | 
|  | 8954 | } | 
|  | 8955 |  | 
|  | 8956 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { | 
|  | 8957 | .rpc_call_prepare = nfs4_layoutcommit_prepare, | 
|  | 8958 | .rpc_call_done = nfs4_layoutcommit_done, | 
|  | 8959 | .rpc_release = nfs4_layoutcommit_release, | 
|  | 8960 | }; | 
|  | 8961 |  | 
|  | 8962 | int | 
| Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8963 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8964 | { | 
|  | 8965 | struct rpc_message msg = { | 
|  | 8966 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], | 
|  | 8967 | .rpc_argp = &data->args, | 
|  | 8968 | .rpc_resp = &data->res, | 
|  | 8969 | .rpc_cred = data->cred, | 
|  | 8970 | }; | 
|  | 8971 | struct rpc_task_setup task_setup_data = { | 
|  | 8972 | .task = &data->task, | 
|  | 8973 | .rpc_client = NFS_CLIENT(data->args.inode), | 
|  | 8974 | .rpc_message = &msg, | 
|  | 8975 | .callback_ops = &nfs4_layoutcommit_ops, | 
|  | 8976 | .callback_data = data, | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8977 | }; | 
|  | 8978 | struct rpc_task *task; | 
|  | 8979 | int status = 0; | 
|  | 8980 |  | 
| Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8981 | dprintk("NFS: initiating layoutcommit call. sync %d " | 
|  | 8982 | "lbw: %llu inode %lu\n", sync, | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8983 | data->args.lastbytewritten, | 
|  | 8984 | data->args.inode->i_ino); | 
|  | 8985 |  | 
| Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8986 | if (!sync) { | 
|  | 8987 | data->inode = nfs_igrab_and_active(data->args.inode); | 
|  | 8988 | if (data->inode == NULL) { | 
|  | 8989 | nfs4_layoutcommit_release(data); | 
|  | 8990 | return -EAGAIN; | 
|  | 8991 | } | 
|  | 8992 | task_setup_data.flags = RPC_TASK_ASYNC; | 
|  | 8993 | } | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8994 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8995 | task = rpc_run_task(&task_setup_data); | 
|  | 8996 | if (IS_ERR(task)) | 
|  | 8997 | return PTR_ERR(task); | 
| Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8998 | if (sync) | 
|  | 8999 | status = task->tk_status; | 
| Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9000 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9001 | dprintk("%s: status %d\n", __func__, status); | 
|  | 9002 | rpc_put_task(task); | 
|  | 9003 | return status; | 
|  | 9004 | } | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9005 |  | 
| Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9006 | /** | 
|  | 9007 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if | 
|  | 9008 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections | 
|  | 9009 | */ | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9010 | static int | 
|  | 9011 | _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] | 9012 | struct nfs_fsinfo *info, | 
|  | 9013 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9014 | { | 
|  | 9015 | struct nfs41_secinfo_no_name_args args = { | 
|  | 9016 | .style = SECINFO_STYLE_CURRENT_FH, | 
|  | 9017 | }; | 
|  | 9018 | struct nfs4_secinfo_res res = { | 
|  | 9019 | .flavors = flavors, | 
|  | 9020 | }; | 
|  | 9021 | struct rpc_message msg = { | 
|  | 9022 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], | 
|  | 9023 | .rpc_argp = &args, | 
|  | 9024 | .rpc_resp = &res, | 
|  | 9025 | }; | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9026 | struct rpc_clnt *clnt = server->client; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9027 | struct rpc_cred *cred = NULL; | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9028 | int status; | 
|  | 9029 |  | 
|  | 9030 | if (use_integrity) { | 
|  | 9031 | clnt = server->nfs_client->cl_rpcclient; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9032 | cred = nfs4_get_clid_cred(server->nfs_client); | 
|  | 9033 | msg.rpc_cred = cred; | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9034 | } | 
|  | 9035 |  | 
|  | 9036 | dprintk("--> %s\n", __func__); | 
|  | 9037 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, | 
|  | 9038 | &res.seq_res, 0); | 
|  | 9039 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 9040 |  | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9041 | if (cred) | 
|  | 9042 | put_rpccred(cred); | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9043 |  | 
|  | 9044 | return status; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9045 | } | 
|  | 9046 |  | 
|  | 9047 | static int | 
|  | 9048 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 9049 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) | 
|  | 9050 | { | 
|  | 9051 | struct nfs4_exception exception = { }; | 
|  | 9052 | int err; | 
|  | 9053 | do { | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9054 | /* first try using integrity protection */ | 
|  | 9055 | err = -NFS4ERR_WRONGSEC; | 
|  | 9056 |  | 
|  | 9057 | /* try to use integrity protection with machine cred */ | 
|  | 9058 | if (_nfs4_is_integrity_protected(server->nfs_client)) | 
|  | 9059 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, | 
|  | 9060 | flavors, true); | 
|  | 9061 |  | 
|  | 9062 | /* | 
|  | 9063 | * if unable to use integrity protection, or SECINFO with | 
|  | 9064 | * integrity protection returns NFS4ERR_WRONGSEC (which is | 
|  | 9065 | * disallowed by spec, but exists in deployed servers) use | 
|  | 9066 | * the current filesystem's rpc_client and the user cred. | 
|  | 9067 | */ | 
|  | 9068 | if (err == -NFS4ERR_WRONGSEC) | 
|  | 9069 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, | 
|  | 9070 | flavors, false); | 
|  | 9071 |  | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9072 | switch (err) { | 
|  | 9073 | case 0: | 
|  | 9074 | case -NFS4ERR_WRONGSEC: | 
| Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9075 | case -ENOTSUPP: | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9076 | goto out; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9077 | default: | 
|  | 9078 | err = nfs4_handle_exception(server, err, &exception); | 
|  | 9079 | } | 
|  | 9080 | } while (exception.retry); | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9081 | out: | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9082 | return err; | 
|  | 9083 | } | 
|  | 9084 |  | 
|  | 9085 | static int | 
|  | 9086 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 9087 | struct nfs_fsinfo *info) | 
|  | 9088 | { | 
|  | 9089 | int err; | 
|  | 9090 | struct page *page; | 
| Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9091 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9092 | struct nfs4_secinfo_flavors *flavors; | 
| Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9093 | struct nfs4_secinfo4 *secinfo; | 
|  | 9094 | int i; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9095 |  | 
|  | 9096 | page = alloc_page(GFP_KERNEL); | 
|  | 9097 | if (!page) { | 
|  | 9098 | err = -ENOMEM; | 
|  | 9099 | goto out; | 
|  | 9100 | } | 
|  | 9101 |  | 
|  | 9102 | flavors = page_address(page); | 
|  | 9103 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); | 
|  | 9104 |  | 
|  | 9105 | /* | 
|  | 9106 | * Fall back on "guess and check" method if | 
|  | 9107 | * the server doesn't support SECINFO_NO_NAME | 
|  | 9108 | */ | 
| Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9109 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9110 | err = nfs4_find_root_sec(server, fhandle, info); | 
|  | 9111 | goto out_freepage; | 
|  | 9112 | } | 
|  | 9113 | if (err) | 
|  | 9114 | goto out_freepage; | 
|  | 9115 |  | 
| Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9116 | for (i = 0; i < flavors->num_flavors; i++) { | 
|  | 9117 | secinfo = &flavors->flavors[i]; | 
|  | 9118 |  | 
|  | 9119 | switch (secinfo->flavor) { | 
|  | 9120 | case RPC_AUTH_NULL: | 
|  | 9121 | case RPC_AUTH_UNIX: | 
|  | 9122 | case RPC_AUTH_GSS: | 
|  | 9123 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, | 
|  | 9124 | &secinfo->flavor_info); | 
|  | 9125 | break; | 
|  | 9126 | default: | 
|  | 9127 | flavor = RPC_AUTH_MAXFLAVOR; | 
|  | 9128 | break; | 
|  | 9129 | } | 
|  | 9130 |  | 
| Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9131 | if (!nfs_auth_info_match(&server->auth_info, flavor)) | 
|  | 9132 | flavor = RPC_AUTH_MAXFLAVOR; | 
|  | 9133 |  | 
| Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9134 | if (flavor != RPC_AUTH_MAXFLAVOR) { | 
|  | 9135 | err = nfs4_lookup_root_sec(server, fhandle, | 
|  | 9136 | info, flavor); | 
|  | 9137 | if (!err) | 
|  | 9138 | break; | 
|  | 9139 | } | 
|  | 9140 | } | 
|  | 9141 |  | 
|  | 9142 | if (flavor == RPC_AUTH_MAXFLAVOR) | 
|  | 9143 | err = -EPERM; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9144 |  | 
|  | 9145 | out_freepage: | 
|  | 9146 | put_page(page); | 
|  | 9147 | if (err == -EACCES) | 
|  | 9148 | return -EPERM; | 
|  | 9149 | out: | 
|  | 9150 | return err; | 
|  | 9151 | } | 
| Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9152 |  | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9153 | static int _nfs41_test_stateid(struct nfs_server *server, | 
|  | 9154 | nfs4_stateid *stateid, | 
|  | 9155 | struct rpc_cred *cred) | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9156 | { | 
|  | 9157 | int status; | 
|  | 9158 | struct nfs41_test_stateid_args args = { | 
| Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9159 | .stateid = stateid, | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9160 | }; | 
|  | 9161 | struct nfs41_test_stateid_res res; | 
|  | 9162 | struct rpc_message msg = { | 
|  | 9163 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], | 
|  | 9164 | .rpc_argp = &args, | 
|  | 9165 | .rpc_resp = &res, | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9166 | .rpc_cred = cred, | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9167 | }; | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9168 | struct rpc_clnt *rpc_client = server->client; | 
|  | 9169 |  | 
|  | 9170 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, | 
|  | 9171 | &rpc_client, &msg); | 
| Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9172 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9173 | dprintk("NFS call  test_stateid %p\n", stateid); | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9174 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9175 | nfs4_set_sequence_privileged(&args.seq_args); | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9176 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9177 | &args.seq_args, &res.seq_res); | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9178 | if (status != NFS_OK) { | 
|  | 9179 | dprintk("NFS reply test_stateid: failed, %d\n", status); | 
| Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9180 | return status; | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9181 | } | 
|  | 9182 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); | 
| Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9183 | return -res.status; | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9184 | } | 
|  | 9185 |  | 
| Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9186 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, | 
|  | 9187 | int err, struct nfs4_exception *exception) | 
|  | 9188 | { | 
|  | 9189 | exception->retry = 0; | 
|  | 9190 | switch(err) { | 
|  | 9191 | case -NFS4ERR_DELAY: | 
| Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9192 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9193 | nfs4_handle_exception(server, err, exception); | 
|  | 9194 | break; | 
|  | 9195 | case -NFS4ERR_BADSESSION: | 
|  | 9196 | case -NFS4ERR_BADSLOT: | 
|  | 9197 | case -NFS4ERR_BAD_HIGH_SLOT: | 
|  | 9198 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|  | 9199 | case -NFS4ERR_DEADSESSION: | 
|  | 9200 | nfs4_do_handle_exception(server, err, exception); | 
|  | 9201 | } | 
|  | 9202 | } | 
|  | 9203 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9204 | /** | 
|  | 9205 | * nfs41_test_stateid - perform a TEST_STATEID operation | 
|  | 9206 | * | 
|  | 9207 | * @server: server / transport on which to perform the operation | 
|  | 9208 | * @stateid: state ID to test | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9209 | * @cred: credential | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9210 | * | 
|  | 9211 | * Returns NFS_OK if the server recognizes that "stateid" is valid. | 
|  | 9212 | * Otherwise a negative NFS4ERR value is returned if the operation | 
|  | 9213 | * failed or the state ID is not currently valid. | 
|  | 9214 | */ | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9215 | static int nfs41_test_stateid(struct nfs_server *server, | 
|  | 9216 | nfs4_stateid *stateid, | 
|  | 9217 | struct rpc_cred *cred) | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9218 | { | 
|  | 9219 | struct nfs4_exception exception = { }; | 
|  | 9220 | int err; | 
|  | 9221 | do { | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9222 | err = _nfs41_test_stateid(server, stateid, cred); | 
| Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9223 | nfs4_handle_delay_or_session_error(server, err, &exception); | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9224 | } while (exception.retry); | 
|  | 9225 | return err; | 
|  | 9226 | } | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9227 |  | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9228 | struct nfs_free_stateid_data { | 
|  | 9229 | struct nfs_server *server; | 
|  | 9230 | struct nfs41_free_stateid_args args; | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9231 | struct nfs41_free_stateid_res res; | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9232 | }; | 
|  | 9233 |  | 
|  | 9234 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) | 
|  | 9235 | { | 
|  | 9236 | struct nfs_free_stateid_data *data = calldata; | 
| Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9237 | nfs4_setup_sequence(data->server->nfs_client, | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9238 | &data->args.seq_args, | 
|  | 9239 | &data->res.seq_res, | 
|  | 9240 | task); | 
|  | 9241 | } | 
|  | 9242 |  | 
|  | 9243 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) | 
|  | 9244 | { | 
|  | 9245 | struct nfs_free_stateid_data *data = calldata; | 
|  | 9246 |  | 
|  | 9247 | nfs41_sequence_done(task, &data->res.seq_res); | 
|  | 9248 |  | 
|  | 9249 | switch (task->tk_status) { | 
|  | 9250 | case -NFS4ERR_DELAY: | 
| NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9251 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9252 | rpc_restart_call_prepare(task); | 
|  | 9253 | } | 
|  | 9254 | } | 
|  | 9255 |  | 
|  | 9256 | static void nfs41_free_stateid_release(void *calldata) | 
|  | 9257 | { | 
|  | 9258 | kfree(calldata); | 
|  | 9259 | } | 
|  | 9260 |  | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9261 | static const struct rpc_call_ops nfs41_free_stateid_ops = { | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9262 | .rpc_call_prepare = nfs41_free_stateid_prepare, | 
|  | 9263 | .rpc_call_done = nfs41_free_stateid_done, | 
|  | 9264 | .rpc_release = nfs41_free_stateid_release, | 
|  | 9265 | }; | 
|  | 9266 |  | 
|  | 9267 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9268 | const nfs4_stateid *stateid, | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9269 | struct rpc_cred *cred, | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9270 | bool privileged) | 
|  | 9271 | { | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9272 | struct rpc_message msg = { | 
|  | 9273 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9274 | .rpc_cred = cred, | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9275 | }; | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9276 | struct rpc_task_setup task_setup = { | 
|  | 9277 | .rpc_client = server->client, | 
|  | 9278 | .rpc_message = &msg, | 
|  | 9279 | .callback_ops = &nfs41_free_stateid_ops, | 
|  | 9280 | .flags = RPC_TASK_ASYNC, | 
|  | 9281 | }; | 
|  | 9282 | struct nfs_free_stateid_data *data; | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9283 |  | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9284 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, | 
|  | 9285 | &task_setup.rpc_client, &msg); | 
|  | 9286 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9287 | dprintk("NFS call  free_stateid %p\n", stateid); | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9288 | data = kmalloc(sizeof(*data), GFP_NOFS); | 
|  | 9289 | if (!data) | 
|  | 9290 | return ERR_PTR(-ENOMEM); | 
|  | 9291 | data->server = server; | 
|  | 9292 | nfs4_stateid_copy(&data->args.stateid, stateid); | 
|  | 9293 |  | 
|  | 9294 | task_setup.callback_data = data; | 
|  | 9295 |  | 
|  | 9296 | msg.rpc_argp = &data->args; | 
|  | 9297 | msg.rpc_resp = &data->res; | 
| Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9298 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9299 | if (privileged) | 
|  | 9300 | nfs4_set_sequence_privileged(&data->args.seq_args); | 
|  | 9301 |  | 
|  | 9302 | return rpc_run_task(&task_setup); | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9303 | } | 
|  | 9304 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9305 | /** | 
|  | 9306 | * nfs41_free_stateid - perform a FREE_STATEID operation | 
|  | 9307 | * | 
|  | 9308 | * @server: server / transport on which to perform the operation | 
|  | 9309 | * @stateid: state ID to release | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9310 | * @cred: credential | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9311 | * @is_recovery: set to true if this call needs to be privileged | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9312 | * | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9313 | * Note: this function is always asynchronous. | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9314 | */ | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9315 | static int nfs41_free_stateid(struct nfs_server *server, | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9316 | const nfs4_stateid *stateid, | 
|  | 9317 | struct rpc_cred *cred, | 
|  | 9318 | bool is_recovery) | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9319 | { | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9320 | struct rpc_task *task; | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9321 |  | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9322 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9323 | if (IS_ERR(task)) | 
|  | 9324 | return PTR_ERR(task); | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9325 | rpc_put_task(task); | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9326 | return 0; | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9327 | } | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9328 |  | 
| Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9329 | static void | 
|  | 9330 | 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] | 9331 | { | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9332 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9333 |  | 
| Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9334 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9335 | nfs4_free_lock_state(server, lsp); | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9336 | } | 
|  | 9337 |  | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9338 | static bool nfs41_match_stateid(const nfs4_stateid *s1, | 
|  | 9339 | const nfs4_stateid *s2) | 
|  | 9340 | { | 
| Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9341 | if (s1->type != s2->type) | 
|  | 9342 | return false; | 
|  | 9343 |  | 
| Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9344 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9345 | return false; | 
|  | 9346 |  | 
| Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9347 | if (s1->seqid == s2->seqid) | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9348 | return true; | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9349 |  | 
| Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9350 | return s1->seqid == 0 || s2->seqid == 0; | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9351 | } | 
|  | 9352 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9353 | #endif /* CONFIG_NFS_V4_1 */ | 
|  | 9354 |  | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9355 | static bool nfs4_match_stateid(const nfs4_stateid *s1, | 
|  | 9356 | const nfs4_stateid *s2) | 
|  | 9357 | { | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9358 | return nfs4_stateid_match(s1, s2); | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9359 | } | 
|  | 9360 |  | 
|  | 9361 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9362 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { | 
| Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9363 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, | 
| Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9364 | .state_flag_bit	= NFS_STATE_RECLAIM_REBOOT, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9365 | .recover_open	= nfs4_open_reclaim, | 
|  | 9366 | .recover_lock	= nfs4_lock_reclaim, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9367 | .establish_clid = nfs4_init_clientid, | 
| Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9368 | .detect_trunking = nfs40_discover_server_trunking, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9369 | }; | 
|  | 9370 |  | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9371 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9372 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9373 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, | 
|  | 9374 | .state_flag_bit	= NFS_STATE_RECLAIM_REBOOT, | 
|  | 9375 | .recover_open	= nfs4_open_reclaim, | 
|  | 9376 | .recover_lock	= nfs4_lock_reclaim, | 
| Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9377 | .establish_clid = nfs41_init_clientid, | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9378 | .reclaim_complete = nfs41_proc_reclaim_complete, | 
| Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9379 | .detect_trunking = nfs41_discover_server_trunking, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9380 | }; | 
|  | 9381 | #endif /* CONFIG_NFS_V4_1 */ | 
|  | 9382 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9383 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { | 
| Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9384 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, | 
| Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9385 | .state_flag_bit	= NFS_STATE_RECLAIM_NOGRACE, | 
| Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9386 | .recover_open	= nfs40_open_expired, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9387 | .recover_lock	= nfs4_lock_expired, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9388 | .establish_clid = nfs4_init_clientid, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9389 | }; | 
|  | 9390 |  | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9391 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9392 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9393 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, | 
|  | 9394 | .state_flag_bit	= NFS_STATE_RECLAIM_NOGRACE, | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9395 | .recover_open	= nfs41_open_expired, | 
|  | 9396 | .recover_lock	= nfs41_lock_expired, | 
| Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9397 | .establish_clid = nfs41_init_clientid, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9398 | }; | 
|  | 9399 | #endif /* CONFIG_NFS_V4_1 */ | 
|  | 9400 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9401 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9402 | .sched_state_renewal = nfs4_proc_async_renew, | 
| Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9403 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, | 
| Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9404 | .renew_lease = nfs4_proc_renew, | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9405 | }; | 
|  | 9406 |  | 
|  | 9407 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9408 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9409 | .sched_state_renewal = nfs41_proc_async_sequence, | 
| Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9410 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, | 
| Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9411 | .renew_lease = nfs4_proc_sequence, | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9412 | }; | 
|  | 9413 | #endif | 
|  | 9414 |  | 
| Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9415 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { | 
| Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9416 | .get_locations = _nfs40_proc_get_locations, | 
| Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9417 | .fsid_present = _nfs40_proc_fsid_present, | 
| Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9418 | }; | 
|  | 9419 |  | 
|  | 9420 | #if defined(CONFIG_NFS_V4_1) | 
|  | 9421 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { | 
| Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9422 | .get_locations = _nfs41_proc_get_locations, | 
| Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9423 | .fsid_present = _nfs41_proc_fsid_present, | 
| Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9424 | }; | 
|  | 9425 | #endif	/* CONFIG_NFS_V4_1 */ | 
|  | 9426 |  | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9427 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { | 
|  | 9428 | .minor_version = 0, | 
| Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9429 | .init_caps = NFS_CAP_READDIRPLUS | 
|  | 9430 | | NFS_CAP_ATOMIC_OPEN | 
| Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9431 | | NFS_CAP_POSIX_LOCK, | 
| Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9432 | .init_client = nfs40_init_client, | 
|  | 9433 | .shutdown_client = nfs40_shutdown_client, | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9434 | .match_stateid = nfs4_match_stateid, | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9435 | .find_root_sec = nfs4_find_root_sec, | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9436 | .free_lock_state = nfs4_release_lockowner, | 
| Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9437 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9438 | .alloc_seqid = nfs_alloc_seqid, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9439 | .call_sync_ops = &nfs40_call_sync_ops, | 
| Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9440 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, | 
|  | 9441 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, | 
|  | 9442 | .state_renewal_ops = &nfs40_state_renewal_ops, | 
| Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9443 | .mig_recovery_ops = &nfs40_mig_recovery_ops, | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9444 | }; | 
|  | 9445 |  | 
|  | 9446 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9447 | static struct nfs_seqid * | 
|  | 9448 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) | 
|  | 9449 | { | 
|  | 9450 | return NULL; | 
|  | 9451 | } | 
|  | 9452 |  | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9453 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { | 
|  | 9454 | .minor_version = 1, | 
| Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9455 | .init_caps = NFS_CAP_READDIRPLUS | 
|  | 9456 | | NFS_CAP_ATOMIC_OPEN | 
| Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9457 | | NFS_CAP_POSIX_LOCK | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9458 | | NFS_CAP_STATEID_NFSV41 | 
| Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9459 | | NFS_CAP_ATOMIC_OPEN_V1, | 
| Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9460 | .init_client = nfs41_init_client, | 
|  | 9461 | .shutdown_client = nfs41_shutdown_client, | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9462 | .match_stateid = nfs41_match_stateid, | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9463 | .find_root_sec = nfs41_find_root_sec, | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9464 | .free_lock_state = nfs41_free_lock_state, | 
| Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9465 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9466 | .alloc_seqid = nfs_alloc_no_seqid, | 
| Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9467 | .session_trunk = nfs4_test_session_trunk, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9468 | .call_sync_ops = &nfs41_call_sync_ops, | 
| Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9469 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, | 
|  | 9470 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, | 
|  | 9471 | .state_renewal_ops = &nfs41_state_renewal_ops, | 
| Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9472 | .mig_recovery_ops = &nfs41_mig_recovery_ops, | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9473 | }; | 
|  | 9474 | #endif | 
|  | 9475 |  | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9476 | #if defined(CONFIG_NFS_V4_2) | 
|  | 9477 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { | 
|  | 9478 | .minor_version = 2, | 
| Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9479 | .init_caps = NFS_CAP_READDIRPLUS | 
|  | 9480 | | NFS_CAP_ATOMIC_OPEN | 
| Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9481 | | NFS_CAP_POSIX_LOCK | 
|  | 9482 | | NFS_CAP_STATEID_NFSV41 | 
| Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9483 | | NFS_CAP_ATOMIC_OPEN_V1 | 
| Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9484 | | NFS_CAP_ALLOCATE | 
| Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9485 | | NFS_CAP_COPY | 
| Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9486 | | NFS_CAP_DEALLOCATE | 
| Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9487 | | NFS_CAP_SEEK | 
| Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9488 | | NFS_CAP_LAYOUTSTATS | 
|  | 9489 | | NFS_CAP_CLONE, | 
| Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9490 | .init_client = nfs41_init_client, | 
|  | 9491 | .shutdown_client = nfs41_shutdown_client, | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9492 | .match_stateid = nfs41_match_stateid, | 
|  | 9493 | .find_root_sec = nfs41_find_root_sec, | 
| Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9494 | .free_lock_state = nfs41_free_lock_state, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9495 | .call_sync_ops = &nfs41_call_sync_ops, | 
| Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9496 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, | 
| Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9497 | .alloc_seqid = nfs_alloc_no_seqid, | 
| Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9498 | .session_trunk = nfs4_test_session_trunk, | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9499 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, | 
|  | 9500 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, | 
|  | 9501 | .state_renewal_ops = &nfs41_state_renewal_ops, | 
| Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9502 | .mig_recovery_ops = &nfs41_mig_recovery_ops, | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9503 | }; | 
|  | 9504 | #endif | 
|  | 9505 |  | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9506 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { | 
|  | 9507 | [0] = &nfs_v4_0_minor_ops, | 
|  | 9508 | #if defined(CONFIG_NFS_V4_1) | 
|  | 9509 | [1] = &nfs_v4_1_minor_ops, | 
|  | 9510 | #endif | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9511 | #if defined(CONFIG_NFS_V4_2) | 
|  | 9512 | [2] = &nfs_v4_2_minor_ops, | 
|  | 9513 | #endif | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9514 | }; | 
|  | 9515 |  | 
| Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9516 | 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] | 9517 | { | 
|  | 9518 | ssize_t error, error2; | 
|  | 9519 |  | 
|  | 9520 | error = generic_listxattr(dentry, list, size); | 
|  | 9521 | if (error < 0) | 
|  | 9522 | return error; | 
|  | 9523 | if (list) { | 
|  | 9524 | list += error; | 
|  | 9525 | size -= error; | 
|  | 9526 | } | 
|  | 9527 |  | 
|  | 9528 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); | 
|  | 9529 | if (error2 < 0) | 
|  | 9530 | return error2; | 
|  | 9531 | return error + error2; | 
|  | 9532 | } | 
|  | 9533 |  | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9534 | static const struct inode_operations nfs4_dir_inode_operations = { | 
| Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9535 | .create		= nfs_create, | 
|  | 9536 | .lookup		= nfs_lookup, | 
|  | 9537 | .atomic_open	= nfs_atomic_open, | 
|  | 9538 | .link		= nfs_link, | 
|  | 9539 | .unlink		= nfs_unlink, | 
|  | 9540 | .symlink	= nfs_symlink, | 
|  | 9541 | .mkdir		= nfs_mkdir, | 
|  | 9542 | .rmdir		= nfs_rmdir, | 
|  | 9543 | .mknod		= nfs_mknod, | 
|  | 9544 | .rename		= nfs_rename, | 
|  | 9545 | .permission	= nfs_permission, | 
|  | 9546 | .getattr	= nfs_getattr, | 
|  | 9547 | .setattr	= nfs_setattr, | 
| Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9548 | .listxattr	= nfs4_listxattr, | 
| Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9549 | }; | 
|  | 9550 |  | 
| Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9551 | static const struct inode_operations nfs4_file_inode_operations = { | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9552 | .permission	= nfs_permission, | 
|  | 9553 | .getattr	= nfs_getattr, | 
|  | 9554 | .setattr	= nfs_setattr, | 
| Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9555 | .listxattr	= nfs4_listxattr, | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9556 | }; | 
|  | 9557 |  | 
| David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9558 | const struct nfs_rpc_ops nfs_v4_clientops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9559 | .version	= 4,			/* protocol version */ | 
|  | 9560 | .dentry_ops	= &nfs4_dentry_operations, | 
|  | 9561 | .dir_inode_ops	= &nfs4_dir_inode_operations, | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9562 | .file_inode_ops	= &nfs4_file_inode_operations, | 
| Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9563 | .file_ops	= &nfs4_file_operations, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9564 | .getroot	= nfs4_proc_get_root, | 
| Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9565 | .submount	= nfs4_submount, | 
| Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9566 | .try_mount	= nfs4_try_mount, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9567 | .getattr	= nfs4_proc_getattr, | 
|  | 9568 | .setattr	= nfs4_proc_setattr, | 
|  | 9569 | .lookup		= nfs4_proc_lookup, | 
| Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9570 | .lookupp	= nfs4_proc_lookupp, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9571 | .access		= nfs4_proc_access, | 
|  | 9572 | .readlink	= nfs4_proc_readlink, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9573 | .create		= nfs4_proc_create, | 
|  | 9574 | .remove		= nfs4_proc_remove, | 
|  | 9575 | .unlink_setup	= nfs4_proc_unlink_setup, | 
| Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9576 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9577 | .unlink_done	= nfs4_proc_unlink_done, | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9578 | .rename_setup	= nfs4_proc_rename_setup, | 
| Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9579 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9580 | .rename_done	= nfs4_proc_rename_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9581 | .link		= nfs4_proc_link, | 
|  | 9582 | .symlink	= nfs4_proc_symlink, | 
|  | 9583 | .mkdir		= nfs4_proc_mkdir, | 
|  | 9584 | .rmdir		= nfs4_proc_remove, | 
|  | 9585 | .readdir	= nfs4_proc_readdir, | 
|  | 9586 | .mknod		= nfs4_proc_mknod, | 
|  | 9587 | .statfs		= nfs4_proc_statfs, | 
|  | 9588 | .fsinfo		= nfs4_proc_fsinfo, | 
|  | 9589 | .pathconf	= nfs4_proc_pathconf, | 
| David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9590 | .set_capabilities = nfs4_server_capabilities, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9591 | .decode_dirent	= nfs4_decode_dirent, | 
| Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9592 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9593 | .read_setup	= nfs4_proc_read_setup, | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9594 | .read_done	= nfs4_read_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9595 | .write_setup	= nfs4_proc_write_setup, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9596 | .write_done	= nfs4_write_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9597 | .commit_setup	= nfs4_proc_commit_setup, | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9598 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9599 | .commit_done	= nfs4_commit_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9600 | .lock		= nfs4_proc_lock, | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9601 | .clear_acl_cache = nfs4_zap_acl_attr, | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9602 | .close_context  = nfs4_close_context, | 
| Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9603 | .open_context	= nfs4_atomic_open, | 
| Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9604 | .have_delegation = nfs4_have_delegation, | 
| Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9605 | .return_delegation = nfs4_inode_return_delegation, | 
| Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9606 | .alloc_client	= nfs4_alloc_client, | 
| Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9607 | .init_client	= nfs4_init_client, | 
| Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9608 | .free_client	= nfs4_free_client, | 
| Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9609 | .create_server	= nfs4_create_server, | 
|  | 9610 | .clone_server	= nfs_clone_server, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9611 | }; | 
|  | 9612 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9613 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { | 
| Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9614 | .name	= XATTR_NAME_NFSV4_ACL, | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9615 | .list	= nfs4_xattr_list_nfs4_acl, | 
|  | 9616 | .get	= nfs4_xattr_get_nfs4_acl, | 
|  | 9617 | .set	= nfs4_xattr_set_nfs4_acl, | 
|  | 9618 | }; | 
|  | 9619 |  | 
|  | 9620 | const struct xattr_handler *nfs4_xattr_handlers[] = { | 
|  | 9621 | &nfs4_xattr_nfs4_acl_handler, | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9622 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 9623 | &nfs4_xattr_nfs4_label_handler, | 
|  | 9624 | #endif | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9625 | NULL | 
|  | 9626 | }; | 
|  | 9627 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9628 | /* | 
|  | 9629 | * Local variables: | 
|  | 9630 | *  c-basic-offset: 8 | 
|  | 9631 | * End: | 
|  | 9632 | */ |