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 | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 99 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 100 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 101 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 102 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 103 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 106 | static inline struct nfs4_label * |
| 107 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 108 | struct iattr *sattr, struct nfs4_label *label) |
| 109 | { |
| 110 | int err; |
| 111 | |
| 112 | if (label == NULL) |
| 113 | return NULL; |
| 114 | |
| 115 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 116 | return NULL; |
| 117 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 118 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 119 | &dentry->d_name, (void **)&label->label, &label->len); |
| 120 | if (err == 0) |
| 121 | return label; |
| 122 | |
| 123 | return NULL; |
| 124 | } |
| 125 | static inline void |
| 126 | nfs4_label_release_security(struct nfs4_label *label) |
| 127 | { |
| 128 | if (label) |
| 129 | security_release_secctx(label->label, label->len); |
| 130 | } |
| 131 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 132 | { |
| 133 | if (label) |
| 134 | return server->attr_bitmask; |
| 135 | |
| 136 | return server->attr_bitmask_nl; |
| 137 | } |
| 138 | #else |
| 139 | static inline struct nfs4_label * |
| 140 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 141 | struct iattr *sattr, struct nfs4_label *l) |
| 142 | { return NULL; } |
| 143 | static inline void |
| 144 | nfs4_label_release_security(struct nfs4_label *label) |
| 145 | { return; } |
| 146 | static inline u32 * |
| 147 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 148 | { return server->attr_bitmask; } |
| 149 | #endif |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 152 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 154 | if (err >= -1000) |
| 155 | return err; |
| 156 | switch (err) { |
| 157 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 158 | case -NFS4ERR_LAYOUTTRYLATER: |
| 159 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 160 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 161 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 162 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 163 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 164 | case -NFS4ERR_BADOWNER: |
| 165 | case -NFS4ERR_BADNAME: |
| 166 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 167 | case -NFS4ERR_SHARE_DENIED: |
| 168 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 169 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 170 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 171 | case -NFS4ERR_FILE_OPEN: |
| 172 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 173 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 175 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 176 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 178 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This is our standard bitmap for GETATTR requests. |
| 183 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 184 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | FATTR4_WORD0_TYPE |
| 186 | | FATTR4_WORD0_CHANGE |
| 187 | | FATTR4_WORD0_SIZE |
| 188 | | FATTR4_WORD0_FSID |
| 189 | | FATTR4_WORD0_FILEID, |
| 190 | FATTR4_WORD1_MODE |
| 191 | | FATTR4_WORD1_NUMLINKS |
| 192 | | FATTR4_WORD1_OWNER |
| 193 | | FATTR4_WORD1_OWNER_GROUP |
| 194 | | FATTR4_WORD1_RAWDEV |
| 195 | | FATTR4_WORD1_SPACE_USED |
| 196 | | FATTR4_WORD1_TIME_ACCESS |
| 197 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 198 | | FATTR4_WORD1_TIME_MODIFY |
| 199 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 200 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 201 | FATTR4_WORD2_SECURITY_LABEL |
| 202 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 205 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 206 | FATTR4_WORD0_TYPE |
| 207 | | FATTR4_WORD0_CHANGE |
| 208 | | FATTR4_WORD0_SIZE |
| 209 | | FATTR4_WORD0_FSID |
| 210 | | FATTR4_WORD0_FILEID, |
| 211 | FATTR4_WORD1_MODE |
| 212 | | FATTR4_WORD1_NUMLINKS |
| 213 | | FATTR4_WORD1_OWNER |
| 214 | | FATTR4_WORD1_OWNER_GROUP |
| 215 | | FATTR4_WORD1_RAWDEV |
| 216 | | FATTR4_WORD1_SPACE_USED |
| 217 | | FATTR4_WORD1_TIME_ACCESS |
| 218 | | FATTR4_WORD1_TIME_METADATA |
| 219 | | FATTR4_WORD1_TIME_MODIFY, |
| 220 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 221 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 222 | | FATTR4_WORD2_SECURITY_LABEL |
| 223 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 224 | }; |
| 225 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 226 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 227 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 228 | | FATTR4_WORD0_FILEID, |
| 229 | }; |
| 230 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 231 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | FATTR4_WORD0_FILES_AVAIL |
| 233 | | FATTR4_WORD0_FILES_FREE |
| 234 | | FATTR4_WORD0_FILES_TOTAL, |
| 235 | FATTR4_WORD1_SPACE_AVAIL |
| 236 | | FATTR4_WORD1_SPACE_FREE |
| 237 | | FATTR4_WORD1_SPACE_TOTAL |
| 238 | }; |
| 239 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 240 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | FATTR4_WORD0_MAXLINK |
| 242 | | FATTR4_WORD0_MAXNAME, |
| 243 | 0 |
| 244 | }; |
| 245 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 246 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | | FATTR4_WORD0_MAXREAD |
| 248 | | FATTR4_WORD0_MAXWRITE |
| 249 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 250 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 251 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 252 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 253 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 256 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 257 | FATTR4_WORD0_TYPE |
| 258 | | FATTR4_WORD0_CHANGE |
| 259 | | FATTR4_WORD0_SIZE |
| 260 | | FATTR4_WORD0_FSID |
| 261 | | FATTR4_WORD0_FILEID |
| 262 | | FATTR4_WORD0_FS_LOCATIONS, |
| 263 | FATTR4_WORD1_MODE |
| 264 | | FATTR4_WORD1_NUMLINKS |
| 265 | | FATTR4_WORD1_OWNER |
| 266 | | FATTR4_WORD1_OWNER_GROUP |
| 267 | | FATTR4_WORD1_RAWDEV |
| 268 | | FATTR4_WORD1_SPACE_USED |
| 269 | | FATTR4_WORD1_TIME_ACCESS |
| 270 | | FATTR4_WORD1_TIME_METADATA |
| 271 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 272 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 273 | }; |
| 274 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 275 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | struct nfs4_readdir_arg *readdir) |
| 277 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 278 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 279 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 282 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | readdir->cookie = 0; |
| 288 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 289 | if (cookie == 2) |
| 290 | return; |
| 291 | |
| 292 | /* |
| 293 | * NFSv4 servers do not return entries for '.' and '..' |
| 294 | * Therefore, we fake these entries here. We let '.' |
| 295 | * have cookie 0 and '..' have cookie 1. Note that |
| 296 | * when talking to the server, we always send cookie 0 |
| 297 | * instead of 1 or 2. |
| 298 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 299 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | if (cookie == 0) { |
| 302 | *p++ = xdr_one; /* next */ |
| 303 | *p++ = xdr_zero; /* cookie, first word */ |
| 304 | *p++ = xdr_one; /* cookie, second word */ |
| 305 | *p++ = xdr_one; /* entry len */ |
| 306 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 307 | p++; |
| 308 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 309 | *p++ = htonl(attrs); /* bitmap */ |
| 310 | *p++ = htonl(12); /* attribute buffer length */ |
| 311 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | *p++ = xdr_one; /* next */ |
| 316 | *p++ = xdr_zero; /* cookie, first word */ |
| 317 | *p++ = xdr_two; /* cookie, second word */ |
| 318 | *p++ = xdr_two; /* entry len */ |
| 319 | memcpy(p, "..\0\0", 4); /* entry */ |
| 320 | p++; |
| 321 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 322 | *p++ = htonl(attrs); /* bitmap */ |
| 323 | *p++ = htonl(12); /* attribute buffer length */ |
| 324 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 325 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | readdir->pgbase = (char *)p - (char *)start; |
| 328 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 329 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 332 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 333 | nfs4_stateid *stateid, |
| 334 | struct rpc_cred *cred) |
| 335 | { |
| 336 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 337 | |
| 338 | ops->test_and_free_expired(server, stateid, cred); |
| 339 | } |
| 340 | |
| 341 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 342 | nfs4_stateid *stateid, |
| 343 | struct rpc_cred *cred) |
| 344 | { |
| 345 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 346 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 347 | } |
| 348 | |
| 349 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 350 | const nfs4_stateid *stateid, |
| 351 | struct rpc_cred *cred) |
| 352 | { |
| 353 | nfs4_stateid tmp; |
| 354 | |
| 355 | nfs4_stateid_copy(&tmp, stateid); |
| 356 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 357 | } |
| 358 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 359 | static long nfs4_update_delay(long *timeout) |
| 360 | { |
| 361 | long ret; |
| 362 | if (!timeout) |
| 363 | return NFS4_POLL_RETRY_MAX; |
| 364 | if (*timeout <= 0) |
| 365 | *timeout = NFS4_POLL_RETRY_MIN; |
| 366 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 367 | *timeout = NFS4_POLL_RETRY_MAX; |
| 368 | ret = *timeout; |
| 369 | *timeout <<= 1; |
| 370 | return ret; |
| 371 | } |
| 372 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 373 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 374 | { |
| 375 | int res = 0; |
| 376 | |
| 377 | might_sleep(); |
| 378 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 379 | freezable_schedule_timeout_killable_unsafe( |
| 380 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 381 | if (fatal_signal_pending(current)) |
| 382 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 383 | return res; |
| 384 | } |
| 385 | |
| 386 | /* This is the error handling routine for processes that are allowed |
| 387 | * to sleep. |
| 388 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 389 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 390 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 391 | { |
| 392 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 393 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 394 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 395 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 396 | int ret = errorcode; |
| 397 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 398 | exception->delay = 0; |
| 399 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 400 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 401 | |
| 402 | if (stateid == NULL && state != NULL) |
| 403 | stateid = &state->stateid; |
| 404 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 405 | switch(errorcode) { |
| 406 | case 0: |
| 407 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 408 | case -NFS4ERR_DELEG_REVOKED: |
| 409 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 410 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 411 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 412 | if (inode != NULL && stateid != NULL) { |
| 413 | nfs_inode_find_state_and_recover(inode, |
| 414 | stateid); |
| 415 | goto wait_on_recovery; |
| 416 | } |
| 417 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 418 | if (inode) { |
| 419 | int err; |
| 420 | |
| 421 | err = nfs_async_inode_return_delegation(inode, |
| 422 | stateid); |
| 423 | if (err == 0) |
| 424 | goto wait_on_recovery; |
| 425 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 426 | exception->retry = 1; |
| 427 | break; |
| 428 | } |
| 429 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 430 | if (state == NULL) |
| 431 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 432 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 433 | if (ret < 0) |
| 434 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 435 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 436 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 437 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 438 | nfs4_schedule_lease_recovery(clp); |
| 439 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 440 | case -NFS4ERR_MOVED: |
| 441 | ret = nfs4_schedule_migration_recovery(server); |
| 442 | if (ret < 0) |
| 443 | break; |
| 444 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 445 | case -NFS4ERR_LEASE_MOVED: |
| 446 | nfs4_schedule_lease_moved_recovery(clp); |
| 447 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 448 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 449 | case -NFS4ERR_BADSESSION: |
| 450 | case -NFS4ERR_BADSLOT: |
| 451 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 452 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 453 | case -NFS4ERR_DEADSESSION: |
| 454 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 455 | case -NFS4ERR_SEQ_MISORDERED: |
| 456 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 457 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 458 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 459 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 460 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 462 | if (exception->timeout > HZ) { |
| 463 | /* We have retried a decent amount, time to |
| 464 | * fail |
| 465 | */ |
| 466 | ret = -EBUSY; |
| 467 | break; |
| 468 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 469 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 470 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 471 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 472 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 473 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 474 | exception->delay = 1; |
| 475 | return 0; |
| 476 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 477 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 478 | case -NFS4ERR_OLD_STATEID: |
| 479 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 480 | break; |
| 481 | case -NFS4ERR_BADOWNER: |
| 482 | /* The following works around a Linux server bug! */ |
| 483 | case -NFS4ERR_BADNAME: |
| 484 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 485 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 486 | exception->retry = 1; |
| 487 | printk(KERN_WARNING "NFS: v4 server %s " |
| 488 | "does not accept raw " |
| 489 | "uid/gids. " |
| 490 | "Reenabling the idmapper.\n", |
| 491 | server->nfs_client->cl_hostname); |
| 492 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 493 | } |
| 494 | /* We failed to handle the error */ |
| 495 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 496 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 497 | exception->recovering = 1; |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /* This is the error handling routine for processes that are allowed |
| 502 | * to sleep. |
| 503 | */ |
| 504 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 505 | { |
| 506 | struct nfs_client *clp = server->nfs_client; |
| 507 | int ret; |
| 508 | |
| 509 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 510 | if (exception->delay) { |
| 511 | ret = nfs4_delay(server->client, &exception->timeout); |
| 512 | goto out_retry; |
| 513 | } |
| 514 | if (exception->recovering) { |
| 515 | ret = nfs4_wait_clnt_recover(clp); |
| 516 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 517 | return -EIO; |
| 518 | goto out_retry; |
| 519 | } |
| 520 | return ret; |
| 521 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 522 | if (ret == 0) |
| 523 | exception->retry = 1; |
| 524 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 525 | } |
| 526 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 527 | static int |
| 528 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 529 | int errorcode, struct nfs4_exception *exception) |
| 530 | { |
| 531 | struct nfs_client *clp = server->nfs_client; |
| 532 | int ret; |
| 533 | |
| 534 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 535 | if (exception->delay) { |
| 536 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 537 | goto out_retry; |
| 538 | } |
| 539 | if (exception->recovering) { |
| 540 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 541 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 542 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 543 | goto out_retry; |
| 544 | } |
| 545 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 546 | ret = -EIO; |
| 547 | return ret; |
| 548 | out_retry: |
| 549 | if (ret == 0) |
| 550 | exception->retry = 1; |
| 551 | return ret; |
| 552 | } |
| 553 | |
| 554 | static int |
| 555 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 556 | struct nfs4_state *state, long *timeout) |
| 557 | { |
| 558 | struct nfs4_exception exception = { |
| 559 | .state = state, |
| 560 | }; |
| 561 | |
| 562 | if (task->tk_status >= 0) |
| 563 | return 0; |
| 564 | if (timeout) |
| 565 | exception.timeout = *timeout; |
| 566 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 567 | task->tk_status, |
| 568 | &exception); |
| 569 | if (exception.delay && timeout) |
| 570 | *timeout = exception.timeout; |
| 571 | if (exception.retry) |
| 572 | return -EAGAIN; |
| 573 | return 0; |
| 574 | } |
| 575 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 576 | /* |
| 577 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 578 | * or 'false' otherwise. |
| 579 | */ |
| 580 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 581 | { |
| 582 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 583 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 584 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 585 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 586 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | spin_lock(&clp->cl_lock); |
| 589 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 590 | clp->cl_last_renewal = timestamp; |
| 591 | spin_unlock(&clp->cl_lock); |
| 592 | } |
| 593 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 594 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 595 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 596 | struct nfs_client *clp = server->nfs_client; |
| 597 | |
| 598 | if (!nfs4_has_session(clp)) |
| 599 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 602 | struct nfs4_call_sync_data { |
| 603 | const struct nfs_server *seq_server; |
| 604 | struct nfs4_sequence_args *seq_args; |
| 605 | struct nfs4_sequence_res *seq_res; |
| 606 | }; |
| 607 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 608 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 609 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 610 | { |
| 611 | args->sa_slot = NULL; |
| 612 | args->sa_cache_this = cache_reply; |
| 613 | args->sa_privileged = 0; |
| 614 | |
| 615 | res->sr_slot = NULL; |
| 616 | } |
| 617 | |
| 618 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 619 | { |
| 620 | args->sa_privileged = 1; |
| 621 | } |
| 622 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 623 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 624 | { |
| 625 | struct nfs4_slot *slot = res->sr_slot; |
| 626 | struct nfs4_slot_table *tbl; |
| 627 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 628 | tbl = slot->table; |
| 629 | spin_lock(&tbl->slot_tbl_lock); |
| 630 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 631 | nfs4_free_slot(tbl, slot); |
| 632 | spin_unlock(&tbl->slot_tbl_lock); |
| 633 | |
| 634 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static int nfs40_sequence_done(struct rpc_task *task, |
| 638 | struct nfs4_sequence_res *res) |
| 639 | { |
| 640 | if (res->sr_slot != NULL) |
| 641 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 642 | return 1; |
| 643 | } |
| 644 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 645 | #if defined(CONFIG_NFS_V4_1) |
| 646 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 647 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 648 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 649 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 650 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 651 | struct nfs4_slot *slot = res->sr_slot; |
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 | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 654 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 655 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 656 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 657 | /* Bump the slot sequence number */ |
| 658 | if (slot->seq_done) |
| 659 | slot->seq_nr++; |
| 660 | slot->seq_done = 0; |
| 661 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 662 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 663 | /* Be nice to the server: try to ensure that the last transmitted |
| 664 | * value for highest_user_slotid <= target_highest_slotid |
| 665 | */ |
| 666 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 667 | send_new_highest_used_slotid = true; |
| 668 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 669 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 670 | send_new_highest_used_slotid = false; |
| 671 | goto out_unlock; |
| 672 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 673 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 674 | |
| 675 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 676 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 677 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 678 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 679 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 680 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 681 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 682 | if (waitqueue_active(&tbl->slot_waitq)) |
| 683 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 686 | static int nfs41_sequence_process(struct rpc_task *task, |
| 687 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 688 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 689 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 690 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 691 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 692 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 693 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 694 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 695 | if (slot == NULL) |
| 696 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 697 | /* don't increment the sequence number if the task wasn't sent */ |
| 698 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 699 | goto out; |
| 700 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 701 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 702 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 703 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 704 | if (res->sr_status != -NFS4ERR_DELAY) |
| 705 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 706 | interrupted = true; |
| 707 | } |
| 708 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 709 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 710 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 711 | switch (res->sr_status) { |
| 712 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 713 | /* If previous op on slot was interrupted and we reused |
| 714 | * the seq# and got a reply from the cache, then retry |
| 715 | */ |
| 716 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 717 | ++slot->seq_nr; |
| 718 | goto retry_nowait; |
| 719 | } |
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 | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 753 | goto retry_nowait; |
| 754 | case -NFS4ERR_SEQ_MISORDERED: |
| 755 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 756 | * Was the last operation on this sequence interrupted? |
| 757 | * If so, retry after bumping the sequence number. |
| 758 | */ |
| 759 | if (interrupted) { |
| 760 | ++slot->seq_nr; |
| 761 | goto retry_nowait; |
| 762 | } |
| 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 | } |
| 771 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 772 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 773 | ++slot->seq_nr; |
| 774 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 775 | default: |
| 776 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 777 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 778 | } |
| 779 | out: |
| 780 | /* The session may be reset by one of the error handlers. */ |
| 781 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 782 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 783 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 784 | retry_nowait: |
| 785 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 786 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 787 | task->tk_status = 0; |
| 788 | ret = 0; |
| 789 | } |
| 790 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 791 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 792 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 793 | goto out; |
| 794 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 795 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 796 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 797 | |
| 798 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 799 | { |
| 800 | if (!nfs41_sequence_process(task, res)) |
| 801 | return 0; |
| 802 | if (res->sr_slot != NULL) |
| 803 | nfs41_sequence_free_slot(res); |
| 804 | return 1; |
| 805 | |
| 806 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 807 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 808 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 809 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 810 | { |
| 811 | if (res->sr_slot == NULL) |
| 812 | return 1; |
| 813 | if (res->sr_slot->table->session != NULL) |
| 814 | return nfs41_sequence_process(task, res); |
| 815 | return nfs40_sequence_done(task, res); |
| 816 | } |
| 817 | |
| 818 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 819 | { |
| 820 | if (res->sr_slot != NULL) { |
| 821 | if (res->sr_slot->table->session != NULL) |
| 822 | nfs41_sequence_free_slot(res); |
| 823 | else |
| 824 | nfs40_sequence_free_slot(res); |
| 825 | } |
| 826 | } |
| 827 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 828 | 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] | 829 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 830 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 831 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 832 | if (!res->sr_slot->table->session) |
| 833 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 834 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 835 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 836 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 837 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 838 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 839 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 840 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 841 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 842 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 843 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 844 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 845 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 846 | } |
| 847 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 848 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 849 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 850 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 851 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 852 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 853 | } |
| 854 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 855 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 856 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 857 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 858 | }; |
| 859 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 860 | #else /* !CONFIG_NFS_V4_1 */ |
| 861 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 862 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 863 | { |
| 864 | return nfs40_sequence_done(task, res); |
| 865 | } |
| 866 | |
| 867 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 868 | { |
| 869 | if (res->sr_slot != NULL) |
| 870 | nfs40_sequence_free_slot(res); |
| 871 | } |
| 872 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 873 | int nfs4_sequence_done(struct rpc_task *task, |
| 874 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 875 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 876 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 877 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 878 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 879 | |
| 880 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 881 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 882 | int nfs4_setup_sequence(const struct nfs_client *client, |
| 883 | struct nfs4_sequence_args *args, |
| 884 | struct nfs4_sequence_res *res, |
| 885 | struct rpc_task *task) |
| 886 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 887 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 888 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 889 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 890 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 891 | /* slot already allocated? */ |
| 892 | if (res->sr_slot != NULL) |
| 893 | goto out_start; |
| 894 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 895 | if (session) { |
| 896 | tbl = &session->fc_slot_table; |
| 897 | task->tk_timeout = 0; |
| 898 | } |
| 899 | |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 900 | spin_lock(&tbl->slot_tbl_lock); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 901 | /* The state manager will wait until the slot table is empty */ |
| 902 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 903 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 904 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 905 | slot = nfs4_alloc_slot(tbl); |
| 906 | if (IS_ERR(slot)) { |
| 907 | /* Try again in 1/4 second */ |
| 908 | if (slot == ERR_PTR(-ENOMEM)) |
| 909 | task->tk_timeout = HZ >> 2; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 910 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 911 | } |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 912 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 913 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 914 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 915 | args->sa_slot = slot; |
| 916 | |
| 917 | res->sr_slot = slot; |
| 918 | if (session) { |
| 919 | res->sr_timestamp = jiffies; |
| 920 | res->sr_status_flags = 0; |
| 921 | res->sr_status = 1; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 922 | } |
| 923 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 924 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 925 | out_start: |
| 926 | rpc_call_start(task); |
| 927 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 928 | |
| 929 | out_sleep: |
| 930 | if (args->sa_privileged) |
| 931 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 932 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 933 | else |
| 934 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 935 | spin_unlock(&tbl->slot_tbl_lock); |
| 936 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 937 | } |
| 938 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 939 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 940 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 941 | { |
| 942 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 943 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 944 | data->seq_args, data->seq_res, task); |
| 945 | } |
| 946 | |
| 947 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 948 | { |
| 949 | struct nfs4_call_sync_data *data = calldata; |
| 950 | nfs4_sequence_done(task, data->seq_res); |
| 951 | } |
| 952 | |
| 953 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 954 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 955 | .rpc_call_done = nfs40_call_sync_done, |
| 956 | }; |
| 957 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 958 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 959 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 960 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 961 | struct nfs4_sequence_args *args, |
| 962 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 963 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 964 | int ret; |
| 965 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 966 | struct nfs_client *clp = server->nfs_client; |
| 967 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 968 | .seq_server = server, |
| 969 | .seq_args = args, |
| 970 | .seq_res = res, |
| 971 | }; |
| 972 | struct rpc_task_setup task_setup = { |
| 973 | .rpc_client = clnt, |
| 974 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 975 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 976 | .callback_data = &data |
| 977 | }; |
| 978 | |
| 979 | task = rpc_run_task(&task_setup); |
| 980 | if (IS_ERR(task)) |
| 981 | ret = PTR_ERR(task); |
| 982 | else { |
| 983 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 984 | rpc_put_task(task); |
| 985 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 986 | return ret; |
| 987 | } |
| 988 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 989 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 990 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 991 | struct rpc_message *msg, |
| 992 | struct nfs4_sequence_args *args, |
| 993 | struct nfs4_sequence_res *res, |
| 994 | int cache_reply) |
| 995 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 996 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 997 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1000 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1001 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
| 1003 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1004 | |
| 1005 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1006 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1007 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1008 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1009 | nfsi->attrtimeo_timestamp = jiffies; |
| 1010 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1012 | if (cinfo->before != dir->i_version) |
| 1013 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1014 | NFS_INO_INVALID_ACL; |
| 1015 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1016 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1017 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1018 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1019 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | spin_unlock(&dir->i_lock); |
| 1021 | } |
| 1022 | |
| 1023 | struct nfs4_opendata { |
| 1024 | struct kref kref; |
| 1025 | struct nfs_openargs o_arg; |
| 1026 | struct nfs_openres o_res; |
| 1027 | struct nfs_open_confirmargs c_arg; |
| 1028 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1029 | struct nfs4_string owner_name; |
| 1030 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1031 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1033 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1035 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | struct nfs4_state_owner *owner; |
| 1037 | struct nfs4_state *state; |
| 1038 | struct iattr attrs; |
| 1039 | unsigned long timestamp; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1040 | bool rpc_done; |
| 1041 | bool file_created; |
| 1042 | bool is_recover; |
| 1043 | bool cancelled; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1044 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1046 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1047 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1048 | int err, struct nfs4_exception *exception) |
| 1049 | { |
| 1050 | if (err != -EINVAL) |
| 1051 | return false; |
| 1052 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1053 | return false; |
| 1054 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1055 | exception->retry = 1; |
| 1056 | return true; |
| 1057 | } |
| 1058 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1059 | static u32 |
| 1060 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1061 | fmode_t fmode, int openflags) |
| 1062 | { |
| 1063 | u32 res = 0; |
| 1064 | |
| 1065 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1066 | case FMODE_READ: |
| 1067 | res = NFS4_SHARE_ACCESS_READ; |
| 1068 | break; |
| 1069 | case FMODE_WRITE: |
| 1070 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1071 | break; |
| 1072 | case FMODE_READ|FMODE_WRITE: |
| 1073 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1074 | } |
| 1075 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1076 | goto out; |
| 1077 | /* Want no delegation if we're using O_DIRECT */ |
| 1078 | if (openflags & O_DIRECT) |
| 1079 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1080 | out: |
| 1081 | return res; |
| 1082 | } |
| 1083 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1084 | static enum open_claim_type4 |
| 1085 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1086 | enum open_claim_type4 claim) |
| 1087 | { |
| 1088 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1089 | return claim; |
| 1090 | switch (claim) { |
| 1091 | default: |
| 1092 | return claim; |
| 1093 | case NFS4_OPEN_CLAIM_FH: |
| 1094 | return NFS4_OPEN_CLAIM_NULL; |
| 1095 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1096 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1097 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1098 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1099 | } |
| 1100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
| 1102 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1103 | { |
| 1104 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1105 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1106 | p->o_res.seqid = p->o_arg.seqid; |
| 1107 | p->c_res.seqid = p->c_arg.seqid; |
| 1108 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1109 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1110 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1111 | 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] | 1112 | } |
| 1113 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1114 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1115 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1116 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1117 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1118 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1119 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1120 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1121 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1122 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1123 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1124 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1125 | struct nfs4_opendata *p; |
| 1126 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1127 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1128 | if (p == NULL) |
| 1129 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1130 | |
| 1131 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1132 | if (IS_ERR(p->f_label)) |
| 1133 | goto err_free_p; |
| 1134 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1135 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1136 | if (IS_ERR(p->a_label)) |
| 1137 | goto err_free_f; |
| 1138 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1139 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1140 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1141 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1142 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1143 | nfs_sb_active(dentry->d_sb); |
| 1144 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1145 | p->dir = parent; |
| 1146 | p->owner = sp; |
| 1147 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1148 | p->o_arg.open_flags = flags; |
| 1149 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1150 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1151 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1152 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1153 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1154 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1155 | * will return permission denied for all bits until close */ |
| 1156 | if (!(flags & O_EXCL)) { |
| 1157 | /* ask server to check for all possible rights as results |
| 1158 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1159 | switch (p->o_arg.claim) { |
| 1160 | default: |
| 1161 | break; |
| 1162 | case NFS4_OPEN_CLAIM_NULL: |
| 1163 | case NFS4_OPEN_CLAIM_FH: |
| 1164 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1165 | NFS4_ACCESS_MODIFY | |
| 1166 | NFS4_ACCESS_EXTEND | |
| 1167 | NFS4_ACCESS_EXECUTE; |
| 1168 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1169 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1170 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1171 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1172 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1173 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1174 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1175 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1176 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1177 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1178 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1179 | case NFS4_OPEN_CLAIM_NULL: |
| 1180 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1181 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1182 | p->o_arg.fh = NFS_FH(dir); |
| 1183 | break; |
| 1184 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1185 | case NFS4_OPEN_CLAIM_FH: |
| 1186 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1187 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1188 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1189 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1190 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1191 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1192 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1193 | p->o_arg.u.attrs = &p->attrs; |
| 1194 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1195 | |
| 1196 | verf[0] = jiffies; |
| 1197 | verf[1] = current->pid; |
| 1198 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1199 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1201 | p->c_arg.fh = &p->o_res.fh; |
| 1202 | p->c_arg.stateid = &p->o_res.stateid; |
| 1203 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1204 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1205 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1206 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1207 | |
| 1208 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1209 | nfs4_label_free(p->a_label); |
| 1210 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1211 | nfs4_label_free(p->f_label); |
| 1212 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1213 | kfree(p); |
| 1214 | err: |
| 1215 | dput(parent); |
| 1216 | return NULL; |
| 1217 | } |
| 1218 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1219 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1220 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1221 | struct nfs4_opendata *p = container_of(kref, |
| 1222 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1223 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1224 | |
| 1225 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1226 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1227 | if (p->state != NULL) |
| 1228 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1229 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1230 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1231 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1232 | nfs4_label_free(p->f_label); |
| 1233 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1234 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1235 | dput(p->dentry); |
| 1236 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1237 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1238 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1239 | kfree(p); |
| 1240 | } |
| 1241 | |
| 1242 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1243 | { |
| 1244 | if (p != NULL) |
| 1245 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1246 | } |
| 1247 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1248 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1249 | fmode_t fmode) |
| 1250 | { |
| 1251 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1252 | case FMODE_READ|FMODE_WRITE: |
| 1253 | return state->n_rdwr != 0; |
| 1254 | case FMODE_WRITE: |
| 1255 | return state->n_wronly != 0; |
| 1256 | case FMODE_READ: |
| 1257 | return state->n_rdonly != 0; |
| 1258 | } |
| 1259 | WARN_ON_ONCE(1); |
| 1260 | return false; |
| 1261 | } |
| 1262 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1263 | 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] | 1264 | { |
| 1265 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1266 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1267 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1268 | goto out; |
| 1269 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1270 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1271 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1272 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1273 | break; |
| 1274 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1275 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1276 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1277 | break; |
| 1278 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1279 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1280 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1281 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1282 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1283 | return ret; |
| 1284 | } |
| 1285 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1286 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1287 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1288 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1289 | if (delegation == NULL) |
| 1290 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1291 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1292 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1293 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1294 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1295 | switch (claim) { |
| 1296 | case NFS4_OPEN_CLAIM_NULL: |
| 1297 | case NFS4_OPEN_CLAIM_FH: |
| 1298 | break; |
| 1299 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1300 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1301 | break; |
| 1302 | default: |
| 1303 | return 0; |
| 1304 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1305 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1306 | return 1; |
| 1307 | } |
| 1308 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1309 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1310 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1311 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1312 | case FMODE_WRITE: |
| 1313 | state->n_wronly++; |
| 1314 | break; |
| 1315 | case FMODE_READ: |
| 1316 | state->n_rdonly++; |
| 1317 | break; |
| 1318 | case FMODE_READ|FMODE_WRITE: |
| 1319 | state->n_rdwr++; |
| 1320 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1321 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1324 | #ifdef CONFIG_NFS_V4_1 |
| 1325 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1326 | { |
| 1327 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1328 | return true; |
| 1329 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1330 | return true; |
| 1331 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1332 | return true; |
| 1333 | return false; |
| 1334 | } |
| 1335 | #endif /* CONFIG_NFS_V4_1 */ |
| 1336 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1337 | 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] | 1338 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1339 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1340 | bool need_recover = false; |
| 1341 | |
| 1342 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1343 | need_recover = true; |
| 1344 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1345 | need_recover = true; |
| 1346 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1347 | need_recover = true; |
| 1348 | if (need_recover) |
| 1349 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1350 | } |
| 1351 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1352 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1353 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1354 | { |
| 1355 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1356 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1357 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1358 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1359 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1360 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1361 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1362 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1363 | return true; |
| 1364 | return false; |
| 1365 | } |
| 1366 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1367 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1368 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1369 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1370 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1371 | if (state->n_wronly) |
| 1372 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1373 | if (state->n_rdonly) |
| 1374 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1375 | if (state->n_rdwr) |
| 1376 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1377 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1378 | } |
| 1379 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1380 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1381 | nfs4_stateid *stateid, fmode_t fmode) |
| 1382 | { |
| 1383 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1384 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1385 | case FMODE_WRITE: |
| 1386 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1387 | break; |
| 1388 | case FMODE_READ: |
| 1389 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1390 | break; |
| 1391 | case 0: |
| 1392 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1393 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1394 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1395 | } |
| 1396 | if (stateid == NULL) |
| 1397 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1398 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1399 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1400 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1401 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1402 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1403 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1404 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1405 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1406 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1407 | } |
| 1408 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1409 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1410 | nfs4_stateid *arg_stateid, |
| 1411 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1412 | { |
| 1413 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1414 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1415 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1416 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1417 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1418 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1419 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1422 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1423 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1424 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1425 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1426 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1427 | case FMODE_READ: |
| 1428 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1429 | break; |
| 1430 | case FMODE_WRITE: |
| 1431 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1432 | break; |
| 1433 | case FMODE_READ|FMODE_WRITE: |
| 1434 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1435 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1436 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1437 | return; |
| 1438 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1439 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1440 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1441 | } |
| 1442 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1443 | static void __update_open_stateid(struct nfs4_state *state, |
| 1444 | const nfs4_stateid *open_stateid, |
| 1445 | const nfs4_stateid *deleg_stateid, |
| 1446 | fmode_t fmode, |
| 1447 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1449 | /* |
| 1450 | * Protect the call to nfs4_state_set_mode_locked and |
| 1451 | * serialise the stateid update |
| 1452 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1453 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1454 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1455 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1456 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1457 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1458 | } |
| 1459 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1460 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1461 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1462 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1463 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1466 | static int update_open_stateid(struct nfs4_state *state, |
| 1467 | const nfs4_stateid *open_stateid, |
| 1468 | const nfs4_stateid *delegation, |
| 1469 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1470 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1471 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1472 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1473 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1474 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1475 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1476 | int ret = 0; |
| 1477 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1478 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1479 | |
| 1480 | rcu_read_lock(); |
| 1481 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1482 | if (deleg_cur == NULL) |
| 1483 | goto no_delegation; |
| 1484 | |
| 1485 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1486 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1487 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1488 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1489 | goto no_delegation_unlock; |
| 1490 | |
| 1491 | if (delegation == NULL) |
| 1492 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1493 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1494 | goto no_delegation_unlock; |
| 1495 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1496 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1497 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1498 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1499 | ret = 1; |
| 1500 | no_delegation_unlock: |
| 1501 | spin_unlock(&deleg_cur->lock); |
| 1502 | no_delegation: |
| 1503 | rcu_read_unlock(); |
| 1504 | |
| 1505 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1506 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1507 | ret = 1; |
| 1508 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1509 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1510 | nfs4_schedule_state_manager(clp); |
| 1511 | if (freeme.type != 0) |
| 1512 | nfs4_test_and_free_stateid(server, &freeme, |
| 1513 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1514 | |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1518 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1519 | const nfs4_stateid *stateid) |
| 1520 | { |
| 1521 | struct nfs4_state *state = lsp->ls_state; |
| 1522 | bool ret = false; |
| 1523 | |
| 1524 | spin_lock(&state->state_lock); |
| 1525 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1526 | goto out_noupdate; |
| 1527 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1528 | goto out_noupdate; |
| 1529 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1530 | ret = true; |
| 1531 | out_noupdate: |
| 1532 | spin_unlock(&state->state_lock); |
| 1533 | return ret; |
| 1534 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1535 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1536 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1537 | { |
| 1538 | struct nfs_delegation *delegation; |
| 1539 | |
| 1540 | rcu_read_lock(); |
| 1541 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1542 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1543 | rcu_read_unlock(); |
| 1544 | return; |
| 1545 | } |
| 1546 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1547 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | } |
| 1549 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1550 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1551 | { |
| 1552 | struct nfs4_state *state = opendata->state; |
| 1553 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1554 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1555 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1556 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1557 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1558 | nfs4_stateid stateid; |
| 1559 | int ret = -EAGAIN; |
| 1560 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1561 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1562 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1563 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1564 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1565 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1566 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1567 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1568 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1569 | rcu_read_lock(); |
| 1570 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1571 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1572 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1573 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1574 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1575 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1576 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1577 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1578 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1579 | if (!opendata->is_recover) { |
| 1580 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1581 | if (ret != 0) |
| 1582 | goto out; |
| 1583 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1584 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1585 | |
| 1586 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1587 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1588 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1589 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1590 | out: |
| 1591 | return ERR_PTR(ret); |
| 1592 | out_return_state: |
| 1593 | atomic_inc(&state->count); |
| 1594 | return state; |
| 1595 | } |
| 1596 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1597 | static void |
| 1598 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1599 | { |
| 1600 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1601 | struct nfs_delegation *delegation; |
| 1602 | int delegation_flags = 0; |
| 1603 | |
| 1604 | rcu_read_lock(); |
| 1605 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1606 | if (delegation) |
| 1607 | delegation_flags = delegation->flags; |
| 1608 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1609 | switch (data->o_arg.claim) { |
| 1610 | default: |
| 1611 | break; |
| 1612 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1613 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1614 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1615 | "returning a delegation for " |
| 1616 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1617 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1618 | return; |
| 1619 | } |
| 1620 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1621 | nfs_inode_set_delegation(state->inode, |
| 1622 | data->owner->so_cred, |
| 1623 | &data->o_res); |
| 1624 | else |
| 1625 | nfs_inode_reclaim_delegation(state->inode, |
| 1626 | data->owner->so_cred, |
| 1627 | &data->o_res); |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1632 | * and update the nfs4_state. |
| 1633 | */ |
| 1634 | static struct nfs4_state * |
| 1635 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1636 | { |
| 1637 | struct inode *inode = data->state->inode; |
| 1638 | struct nfs4_state *state = data->state; |
| 1639 | int ret; |
| 1640 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1641 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1642 | if (data->rpc_status) |
| 1643 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1644 | /* cached opens have already been processed */ |
| 1645 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1646 | } |
| 1647 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1648 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1649 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1650 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1651 | |
| 1652 | if (data->o_res.delegation_type != 0) |
| 1653 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1654 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1655 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1656 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1657 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1658 | |
| 1659 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame^] | 1662 | static struct inode * |
| 1663 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1664 | { |
| 1665 | struct inode *inode; |
| 1666 | |
| 1667 | switch (data->o_arg.claim) { |
| 1668 | case NFS4_OPEN_CLAIM_NULL: |
| 1669 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1670 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1671 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1672 | return ERR_PTR(-EAGAIN); |
| 1673 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1674 | &data->f_attr, data->f_label); |
| 1675 | break; |
| 1676 | default: |
| 1677 | inode = d_inode(data->dentry); |
| 1678 | ihold(inode); |
| 1679 | nfs_refresh_inode(inode, &data->f_attr); |
| 1680 | } |
| 1681 | return inode; |
| 1682 | } |
| 1683 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1684 | static struct nfs4_state * |
| 1685 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | { |
| 1687 | struct inode *inode; |
| 1688 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1689 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1690 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1691 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1692 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1693 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1694 | goto out; |
| 1695 | } |
| 1696 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame^] | 1697 | inode = nfs4_opendata_get_inode(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1698 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1699 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1700 | goto err; |
| 1701 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1702 | state = nfs4_get_open_state(inode, data->owner); |
| 1703 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1704 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1705 | if (data->o_res.delegation_type != 0) |
| 1706 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1707 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1708 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1709 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1710 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1711 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1712 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1713 | err_put_inode: |
| 1714 | iput(inode); |
| 1715 | err: |
| 1716 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1717 | } |
| 1718 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1719 | static struct nfs4_state * |
| 1720 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1721 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1722 | struct nfs4_state *ret; |
| 1723 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1724 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1725 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1726 | else |
| 1727 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1728 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1729 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1730 | } |
| 1731 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1732 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1733 | { |
| 1734 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1735 | struct nfs_open_context *ctx; |
| 1736 | |
| 1737 | spin_lock(&state->inode->i_lock); |
| 1738 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1739 | if (ctx->state != state) |
| 1740 | continue; |
| 1741 | get_nfs_open_context(ctx); |
| 1742 | spin_unlock(&state->inode->i_lock); |
| 1743 | return ctx; |
| 1744 | } |
| 1745 | spin_unlock(&state->inode->i_lock); |
| 1746 | return ERR_PTR(-ENOENT); |
| 1747 | } |
| 1748 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1749 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1750 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1751 | { |
| 1752 | struct nfs4_opendata *opendata; |
| 1753 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1754 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1755 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1756 | if (opendata == NULL) |
| 1757 | return ERR_PTR(-ENOMEM); |
| 1758 | opendata->state = state; |
| 1759 | atomic_inc(&state->count); |
| 1760 | return opendata; |
| 1761 | } |
| 1762 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1763 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1764 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1765 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1766 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1767 | int ret; |
| 1768 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1769 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1770 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1771 | opendata->o_arg.open_flags = 0; |
| 1772 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1773 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1774 | NFS_SB(opendata->dentry->d_sb), |
| 1775 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1776 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1777 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1778 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1779 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | if (ret != 0) |
| 1781 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1782 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1783 | if (IS_ERR(newstate)) |
| 1784 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1785 | if (newstate != opendata->state) |
| 1786 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1787 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1788 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1792 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1793 | int ret; |
| 1794 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1795 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1796 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1797 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1798 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1799 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1800 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1801 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1802 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1803 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1804 | if (ret != 0) |
| 1805 | return ret; |
| 1806 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1807 | if (ret != 0) |
| 1808 | return ret; |
| 1809 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1810 | if (ret != 0) |
| 1811 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1812 | /* |
| 1813 | * We may have performed cached opens for all three recoveries. |
| 1814 | * Check if we need to update the current stateid. |
| 1815 | */ |
| 1816 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1817 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1818 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1819 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1820 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1821 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1822 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1823 | return 0; |
| 1824 | } |
| 1825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | /* |
| 1827 | * OPEN_RECLAIM: |
| 1828 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1830 | 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] | 1831 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1832 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1833 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1834 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | int status; |
| 1836 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1837 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1838 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1839 | if (IS_ERR(opendata)) |
| 1840 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1841 | rcu_read_lock(); |
| 1842 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1843 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1844 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1845 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1846 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1847 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1848 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | return status; |
| 1850 | } |
| 1851 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1852 | 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] | 1853 | { |
| 1854 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1855 | struct nfs4_exception exception = { }; |
| 1856 | int err; |
| 1857 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1858 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1859 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1860 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1861 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1862 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1863 | break; |
| 1864 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | } while (exception.retry); |
| 1866 | return err; |
| 1867 | } |
| 1868 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1869 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1870 | { |
| 1871 | struct nfs_open_context *ctx; |
| 1872 | int ret; |
| 1873 | |
| 1874 | ctx = nfs4_state_find_open_context(state); |
| 1875 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1876 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1877 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1878 | put_nfs_open_context(ctx); |
| 1879 | return ret; |
| 1880 | } |
| 1881 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1882 | 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] | 1883 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1884 | switch (err) { |
| 1885 | default: |
| 1886 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1887 | "%d.\n", __func__, err); |
| 1888 | case 0: |
| 1889 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1890 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1891 | case -ESTALE: |
| 1892 | break; |
| 1893 | case -NFS4ERR_BADSESSION: |
| 1894 | case -NFS4ERR_BADSLOT: |
| 1895 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1896 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1897 | case -NFS4ERR_DEADSESSION: |
| 1898 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1899 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1900 | return -EAGAIN; |
| 1901 | case -NFS4ERR_STALE_CLIENTID: |
| 1902 | case -NFS4ERR_STALE_STATEID: |
| 1903 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1904 | /* Don't recall a delegation if it was lost */ |
| 1905 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1906 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1907 | case -NFS4ERR_MOVED: |
| 1908 | nfs4_schedule_migration_recovery(server); |
| 1909 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1910 | case -NFS4ERR_LEASE_MOVED: |
| 1911 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1912 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1913 | case -NFS4ERR_DELEG_REVOKED: |
| 1914 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1915 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1916 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1917 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1918 | nfs_inode_find_state_and_recover(state->inode, |
| 1919 | stateid); |
| 1920 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1921 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1922 | case -NFS4ERR_DELAY: |
| 1923 | case -NFS4ERR_GRACE: |
| 1924 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1925 | ssleep(1); |
| 1926 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1927 | case -ENOMEM: |
| 1928 | case -NFS4ERR_DENIED: |
| 1929 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1930 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | return err; |
| 1933 | } |
| 1934 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1935 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1936 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1937 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1938 | { |
| 1939 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1940 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1941 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1942 | |
| 1943 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1944 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1945 | if (IS_ERR(opendata)) |
| 1946 | return PTR_ERR(opendata); |
| 1947 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1948 | write_seqlock(&state->seqlock); |
| 1949 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1950 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1951 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1952 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1953 | case FMODE_READ|FMODE_WRITE: |
| 1954 | case FMODE_WRITE: |
| 1955 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1956 | if (err) |
| 1957 | break; |
| 1958 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1959 | if (err) |
| 1960 | break; |
| 1961 | case FMODE_READ: |
| 1962 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1963 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1964 | nfs4_opendata_put(opendata); |
| 1965 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1966 | } |
| 1967 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1968 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1969 | { |
| 1970 | struct nfs4_opendata *data = calldata; |
| 1971 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1972 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 1973 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1974 | } |
| 1975 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1976 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1977 | { |
| 1978 | struct nfs4_opendata *data = calldata; |
| 1979 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1980 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1981 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1982 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1983 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1984 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1985 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1986 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1987 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1988 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | static void nfs4_open_confirm_release(void *calldata) |
| 1992 | { |
| 1993 | struct nfs4_opendata *data = calldata; |
| 1994 | struct nfs4_state *state = NULL; |
| 1995 | |
| 1996 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1997 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1998 | goto out_free; |
| 1999 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2000 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2001 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2002 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2003 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2004 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2005 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2006 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2010 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2011 | .rpc_call_done = nfs4_open_confirm_done, |
| 2012 | .rpc_release = nfs4_open_confirm_release, |
| 2013 | }; |
| 2014 | |
| 2015 | /* |
| 2016 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2017 | */ |
| 2018 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2019 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2020 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2021 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2022 | struct rpc_message msg = { |
| 2023 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2024 | .rpc_argp = &data->c_arg, |
| 2025 | .rpc_resp = &data->c_res, |
| 2026 | .rpc_cred = data->owner->so_cred, |
| 2027 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2028 | struct rpc_task_setup task_setup_data = { |
| 2029 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2030 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2031 | .callback_ops = &nfs4_open_confirm_ops, |
| 2032 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2033 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2034 | .flags = RPC_TASK_ASYNC, |
| 2035 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | int status; |
| 2037 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2038 | 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] | 2039 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2040 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2041 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2042 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2043 | if (data->is_recover) |
| 2044 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2045 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2046 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2047 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2048 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2049 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2050 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2051 | smp_wmb(); |
| 2052 | } else |
| 2053 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2054 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | return status; |
| 2056 | } |
| 2057 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2058 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2060 | struct nfs4_opendata *data = calldata; |
| 2061 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2062 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2063 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2064 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2065 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2066 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2067 | /* |
| 2068 | * Check if we still need to send an OPEN call, or if we can use |
| 2069 | * a delegation instead. |
| 2070 | */ |
| 2071 | if (data->state != NULL) { |
| 2072 | struct nfs_delegation *delegation; |
| 2073 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2074 | 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] | 2075 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2076 | rcu_read_lock(); |
| 2077 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2078 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2079 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2080 | rcu_read_unlock(); |
| 2081 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2082 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2083 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2084 | switch (claim) { |
| 2085 | default: |
| 2086 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2087 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2088 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2089 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2090 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2091 | case NFS4_OPEN_CLAIM_FH: |
| 2092 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2093 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2094 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2095 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2096 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2097 | &data->o_res.seq_res, |
| 2098 | task) != 0) |
| 2099 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2100 | |
| 2101 | /* Set the create mode (note dependency on the session type) */ |
| 2102 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2103 | if (data->o_arg.open_flags & O_EXCL) { |
| 2104 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2105 | if (nfs4_has_persistent_session(clp)) |
| 2106 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2107 | else if (clp->cl_mvops->minor_version > 0) |
| 2108 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2109 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2110 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2111 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2112 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2113 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2114 | out_no_action: |
| 2115 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2116 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2117 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2118 | } |
| 2119 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2120 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2121 | { |
| 2122 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2124 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2125 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2126 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2127 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2128 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2129 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2130 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2131 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2132 | case S_IFREG: |
| 2133 | break; |
| 2134 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2135 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2136 | break; |
| 2137 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2138 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2139 | break; |
| 2140 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2141 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2142 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2143 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2144 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2145 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2146 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2147 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2148 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2149 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2150 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2151 | static void nfs4_open_release(void *calldata) |
| 2152 | { |
| 2153 | struct nfs4_opendata *data = calldata; |
| 2154 | struct nfs4_state *state = NULL; |
| 2155 | |
| 2156 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2157 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2158 | goto out_free; |
| 2159 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2160 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2161 | goto out_free; |
| 2162 | /* In case we need an open_confirm, no cleanup! */ |
| 2163 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2164 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2165 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2166 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2167 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2168 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2169 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2173 | .rpc_call_prepare = nfs4_open_prepare, |
| 2174 | .rpc_call_done = nfs4_open_done, |
| 2175 | .rpc_release = nfs4_open_release, |
| 2176 | }; |
| 2177 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2178 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2179 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2180 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2181 | struct nfs_server *server = NFS_SERVER(dir); |
| 2182 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2183 | struct nfs_openres *o_res = &data->o_res; |
| 2184 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2185 | struct rpc_message msg = { |
| 2186 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2187 | .rpc_argp = o_arg, |
| 2188 | .rpc_resp = o_res, |
| 2189 | .rpc_cred = data->owner->so_cred, |
| 2190 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2191 | struct rpc_task_setup task_setup_data = { |
| 2192 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2193 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2194 | .callback_ops = &nfs4_open_ops, |
| 2195 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2196 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2197 | .flags = RPC_TASK_ASYNC, |
| 2198 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2199 | int status; |
| 2200 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2201 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2202 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2203 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2204 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2205 | data->cancelled = false; |
| 2206 | data->is_recover = false; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2207 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2208 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2209 | data->is_recover = true; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2210 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2211 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2212 | if (IS_ERR(task)) |
| 2213 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2214 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2215 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2216 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2217 | smp_wmb(); |
| 2218 | } else |
| 2219 | status = data->rpc_status; |
| 2220 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2221 | |
| 2222 | return status; |
| 2223 | } |
| 2224 | |
| 2225 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2226 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2227 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2228 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2229 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2230 | |
| 2231 | status = nfs4_run_open_task(data, 1); |
| 2232 | if (status != 0 || !data->rpc_done) |
| 2233 | return status; |
| 2234 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2235 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2236 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2237 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2238 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2239 | |
| 2240 | return status; |
| 2241 | } |
| 2242 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2243 | /* |
| 2244 | * Additional permission checks in order to distinguish between an |
| 2245 | * open for read, and an open for execute. This works around the |
| 2246 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2247 | * the same. |
| 2248 | * Note that in the non-execute case, we want to turn off permission |
| 2249 | * checking if we just created a new file (POSIX open() semantics). |
| 2250 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2251 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2252 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2253 | struct nfs4_state *state, fmode_t fmode, |
| 2254 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2255 | { |
| 2256 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2257 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2258 | |
| 2259 | /* access call failed or for some reason the server doesn't |
| 2260 | * support any access modes -- defer access call until later */ |
| 2261 | if (opendata->o_res.access_supported == 0) |
| 2262 | return 0; |
| 2263 | |
| 2264 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2265 | /* |
| 2266 | * Use openflags to check for exec, because fmode won't |
| 2267 | * always have FMODE_EXEC set when file open for exec. |
| 2268 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2269 | if (openflags & __FMODE_EXEC) { |
| 2270 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2271 | if (S_ISDIR(state->inode->i_mode)) |
| 2272 | mask = NFS4_ACCESS_LOOKUP; |
| 2273 | else |
| 2274 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2275 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2276 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2277 | |
| 2278 | cache.cred = cred; |
| 2279 | cache.jiffies = jiffies; |
| 2280 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2281 | nfs_access_add_cache(state->inode, &cache); |
| 2282 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2283 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2284 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2285 | return 0; |
| 2286 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2287 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2288 | } |
| 2289 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2290 | /* |
| 2291 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2292 | */ |
| 2293 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2294 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2295 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2296 | struct nfs_server *server = NFS_SERVER(dir); |
| 2297 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2298 | struct nfs_openres *o_res = &data->o_res; |
| 2299 | int status; |
| 2300 | |
| 2301 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2302 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2303 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2304 | if (status != 0) { |
| 2305 | if (status == -NFS4ERR_BADNAME && |
| 2306 | !(o_arg->open_flags & O_CREAT)) |
| 2307 | return -ENOENT; |
| 2308 | return status; |
| 2309 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2310 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2311 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2312 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2313 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2314 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2315 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2316 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2317 | data->file_created = true; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2318 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2319 | update_changeattr(dir, &o_res->cinfo, |
| 2320 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2321 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2322 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2323 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2325 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2327 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2329 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2330 | nfs4_sequence_free_slot(&o_res->seq_res); |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2331 | 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] | 2332 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2333 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | /* |
| 2337 | * OPEN_EXPIRED: |
| 2338 | * reclaim state on the server after a network partition. |
| 2339 | * Assumes caller holds the appropriate lock |
| 2340 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2341 | 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] | 2342 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2343 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2344 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2346 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2347 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2348 | if (IS_ERR(opendata)) |
| 2349 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2350 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2351 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2352 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2353 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2354 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2357 | 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] | 2358 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2359 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2360 | struct nfs4_exception exception = { }; |
| 2361 | int err; |
| 2362 | |
| 2363 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2364 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2365 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2366 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2367 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2368 | switch (err) { |
| 2369 | default: |
| 2370 | goto out; |
| 2371 | case -NFS4ERR_GRACE: |
| 2372 | case -NFS4ERR_DELAY: |
| 2373 | nfs4_handle_exception(server, err, &exception); |
| 2374 | err = 0; |
| 2375 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2376 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2377 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2378 | return err; |
| 2379 | } |
| 2380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2382 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2384 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2386 | ctx = nfs4_state_find_open_context(state); |
| 2387 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2388 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2389 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2390 | put_nfs_open_context(ctx); |
| 2391 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2394 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2395 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2396 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2397 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2398 | write_seqlock(&state->seqlock); |
| 2399 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2400 | write_sequnlock(&state->seqlock); |
| 2401 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2402 | } |
| 2403 | |
| 2404 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2405 | { |
| 2406 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2407 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2411 | { |
| 2412 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2413 | nfs40_clear_delegation_stateid(state); |
| 2414 | return nfs4_open_expired(sp, state); |
| 2415 | } |
| 2416 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2417 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2418 | nfs4_stateid *stateid, |
| 2419 | struct rpc_cred *cred) |
| 2420 | { |
| 2421 | return -NFS4ERR_BAD_STATEID; |
| 2422 | } |
| 2423 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2424 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2425 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2426 | nfs4_stateid *stateid, |
| 2427 | struct rpc_cred *cred) |
| 2428 | { |
| 2429 | int status; |
| 2430 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2431 | switch (stateid->type) { |
| 2432 | default: |
| 2433 | break; |
| 2434 | case NFS4_INVALID_STATEID_TYPE: |
| 2435 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2436 | return -NFS4ERR_BAD_STATEID; |
| 2437 | case NFS4_REVOKED_STATEID_TYPE: |
| 2438 | goto out_free; |
| 2439 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2440 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2441 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2442 | switch (status) { |
| 2443 | case -NFS4ERR_EXPIRED: |
| 2444 | case -NFS4ERR_ADMIN_REVOKED: |
| 2445 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2446 | break; |
| 2447 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2448 | return status; |
| 2449 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2450 | out_free: |
| 2451 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2452 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2453 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2454 | } |
| 2455 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2456 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2457 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2458 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2459 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2460 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2461 | struct rpc_cred *cred; |
| 2462 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2463 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2464 | /* Get the delegation credential for use by test/free_stateid */ |
| 2465 | rcu_read_lock(); |
| 2466 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2467 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2468 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2469 | return; |
| 2470 | } |
| 2471 | |
| 2472 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2473 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2474 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2475 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2476 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2477 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2478 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2479 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2480 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2481 | cred = get_rpccred(delegation->cred); |
| 2482 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2483 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2484 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2485 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2486 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2487 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2488 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2492 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2493 | * |
| 2494 | * @state: NFSv4 state for an inode |
| 2495 | * |
| 2496 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2497 | * Otherwise a negative NFS4ERR value is returned. |
| 2498 | */ |
| 2499 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2500 | { |
| 2501 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2502 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2503 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2504 | |
| 2505 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2506 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2507 | |
| 2508 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2509 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2510 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2511 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2512 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2513 | atomic_inc(&lsp->ls_count); |
| 2514 | spin_unlock(&state->state_lock); |
| 2515 | |
| 2516 | nfs4_put_lock_state(prev); |
| 2517 | prev = lsp; |
| 2518 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2519 | status = nfs41_test_and_free_expired_stateid(server, |
| 2520 | &lsp->ls_stateid, |
| 2521 | cred); |
| 2522 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2523 | if (status == -NFS4ERR_EXPIRED || |
| 2524 | status == -NFS4ERR_BAD_STATEID) { |
| 2525 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2526 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2527 | if (!recover_lost_locks) |
| 2528 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2529 | } else if (status != NFS_OK) { |
| 2530 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2531 | nfs4_put_lock_state(prev); |
| 2532 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2533 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2534 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2535 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2536 | } |
| 2537 | spin_unlock(&state->state_lock); |
| 2538 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2539 | out: |
| 2540 | return ret; |
| 2541 | } |
| 2542 | |
| 2543 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2544 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2545 | * |
| 2546 | * @state: NFSv4 state for an inode |
| 2547 | * |
| 2548 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2549 | * Otherwise a negative NFS4ERR value is returned. |
| 2550 | */ |
| 2551 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2552 | { |
| 2553 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2554 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2555 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2556 | int status; |
| 2557 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2558 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2559 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2560 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2561 | return NFS_OK; |
| 2562 | return -NFS4ERR_OPENMODE; |
| 2563 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2564 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2565 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2566 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2567 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2568 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2569 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2570 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2571 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2572 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2573 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2574 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2575 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2576 | if (nfs_open_stateid_recover_openmode(state)) |
| 2577 | return -NFS4ERR_OPENMODE; |
| 2578 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2582 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2583 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2584 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2585 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2586 | status = nfs41_check_expired_locks(state); |
| 2587 | if (status != NFS_OK) |
| 2588 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2589 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2590 | if (status != NFS_OK) |
| 2591 | status = nfs4_open_expired(sp, state); |
| 2592 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2593 | } |
| 2594 | #endif |
| 2595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2597 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2598 | * fields corresponding to attributes that were used to store the verifier. |
| 2599 | * Make sure we clobber those fields in the later setattr call |
| 2600 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2601 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2602 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2603 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2604 | const u32 *attrset = opendata->o_res.attrset; |
| 2605 | |
| 2606 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2607 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2608 | sattr->ia_valid |= ATTR_ATIME; |
| 2609 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2610 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2611 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2612 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2613 | |
| 2614 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2615 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
Benjamin Coddington | 501e7a4 | 2017-06-02 11:21:34 -0400 | [diff] [blame] | 2616 | (attrset[1] & FATTR4_WORD1_MODE || |
| 2617 | attrset[2] & FATTR4_WORD2_MODE_UMASK)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2618 | sattr->ia_valid &= ~ATTR_MODE; |
| 2619 | |
| 2620 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2621 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2622 | } |
| 2623 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2624 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2625 | fmode_t fmode, |
| 2626 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2627 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2628 | { |
| 2629 | struct nfs4_state_owner *sp = opendata->owner; |
| 2630 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2631 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2632 | struct nfs4_state *state; |
| 2633 | unsigned int seq; |
| 2634 | int ret; |
| 2635 | |
| 2636 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2637 | |
| 2638 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2639 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2640 | goto out; |
| 2641 | |
| 2642 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2643 | ret = PTR_ERR(state); |
| 2644 | if (IS_ERR(state)) |
| 2645 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2646 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2647 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2648 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2649 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2650 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2651 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2652 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2653 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2654 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2655 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2656 | alias = d_exact_alias(dentry, state->inode); |
| 2657 | if (!alias) |
| 2658 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2659 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2660 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2661 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2662 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2663 | } |
| 2664 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2665 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2666 | } |
| 2667 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2668 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2669 | if (ret != 0) |
| 2670 | goto out; |
| 2671 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2672 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2673 | nfs_inode_attach_open_context(ctx); |
| 2674 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2675 | nfs4_schedule_stateid_recovery(server, state); |
| 2676 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2677 | out: |
| 2678 | return ret; |
| 2679 | } |
| 2680 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2681 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2682 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2684 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2685 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2686 | int flags, |
| 2687 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2688 | struct nfs4_label *label, |
| 2689 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | { |
| 2691 | struct nfs4_state_owner *sp; |
| 2692 | struct nfs4_state *state = NULL; |
| 2693 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2694 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2695 | struct dentry *dentry = ctx->dentry; |
| 2696 | struct rpc_cred *cred = ctx->cred; |
| 2697 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2698 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2699 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2700 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2701 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | |
| 2703 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2705 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2706 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2708 | goto out_err; |
| 2709 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2710 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2711 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2712 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2713 | if (d_really_is_positive(dentry)) |
| 2714 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2715 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2716 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2717 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2718 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2719 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2720 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2721 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2723 | if (label) { |
| 2724 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2725 | if (IS_ERR(olabel)) { |
| 2726 | status = PTR_ERR(olabel); |
| 2727 | goto err_opendata_put; |
| 2728 | } |
| 2729 | } |
| 2730 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2731 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2732 | if (!opendata->f_attr.mdsthreshold) { |
| 2733 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2734 | if (!opendata->f_attr.mdsthreshold) |
| 2735 | goto err_free_label; |
| 2736 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2737 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2738 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2739 | if (d_really_is_positive(dentry)) |
| 2740 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2741 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2742 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2743 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2744 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2745 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2746 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2747 | 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] | 2748 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2749 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2750 | /* |
| 2751 | * send create attributes which was not set by open |
| 2752 | * with an extra setattr. |
| 2753 | */ |
| 2754 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2755 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2756 | status = nfs4_do_setattr(state->inode, cred, |
| 2757 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2758 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2759 | if (status == 0) { |
| 2760 | nfs_setattr_update_inode(state->inode, sattr, |
| 2761 | opendata->o_res.f_attr); |
| 2762 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2763 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2764 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2765 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2766 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2767 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2768 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2769 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2770 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2771 | opendata->f_attr.mdsthreshold = NULL; |
| 2772 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2773 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2774 | nfs4_label_free(olabel); |
| 2775 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2776 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2779 | err_free_label: |
| 2780 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2781 | err_opendata_put: |
| 2782 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2783 | err_put_state_owner: |
| 2784 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | return status; |
| 2787 | } |
| 2788 | |
| 2789 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2790 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2791 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2792 | int flags, |
| 2793 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2794 | struct nfs4_label *label, |
| 2795 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2797 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | struct nfs4_exception exception = { }; |
| 2799 | struct nfs4_state *res; |
| 2800 | int status; |
| 2801 | |
| 2802 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2803 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2804 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2805 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | if (status == 0) |
| 2807 | break; |
| 2808 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2809 | * book-keeping w.r.t. state-changing operations |
| 2810 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2811 | * It is actually a sign of a bug on the client or on the server. |
| 2812 | * |
| 2813 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2814 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | * have unhashed the old state_owner for us, and that we can |
| 2816 | * therefore safely retry using a new one. We should still warn |
| 2817 | * the user though... |
| 2818 | */ |
| 2819 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2820 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2821 | " returned a bad sequence-id error!\n", |
| 2822 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | exception.retry = 1; |
| 2824 | continue; |
| 2825 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2826 | /* |
| 2827 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2828 | * state before it received the OPEN_CONFIRM. |
| 2829 | * Recover by retrying the request as per the discussion |
| 2830 | * on Page 181 of RFC3530. |
| 2831 | */ |
| 2832 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2833 | exception.retry = 1; |
| 2834 | continue; |
| 2835 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2836 | if (status == -EAGAIN) { |
| 2837 | /* We must have found a delegation */ |
| 2838 | exception.retry = 1; |
| 2839 | continue; |
| 2840 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2841 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2842 | continue; |
| 2843 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | status, &exception)); |
| 2845 | } while (exception.retry); |
| 2846 | return res; |
| 2847 | } |
| 2848 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2849 | static int _nfs4_do_setattr(struct inode *inode, |
| 2850 | struct nfs_setattrargs *arg, |
| 2851 | struct nfs_setattrres *res, |
| 2852 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2853 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2854 | { |
| 2855 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2856 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2857 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2858 | .rpc_argp = arg, |
| 2859 | .rpc_resp = res, |
| 2860 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2861 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2862 | struct rpc_cred *delegation_cred = NULL; |
| 2863 | unsigned long timestamp = jiffies; |
| 2864 | fmode_t fmode; |
| 2865 | bool truncate; |
| 2866 | int status; |
| 2867 | |
| 2868 | nfs_fattr_init(res->fattr); |
| 2869 | |
| 2870 | /* Servers should only apply open mode checks for file size changes */ |
| 2871 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2872 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2873 | |
| 2874 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2875 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2876 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2877 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2878 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2879 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2880 | l_ctx = nfs_get_lock_context(ctx); |
| 2881 | if (IS_ERR(l_ctx)) |
| 2882 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2883 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2884 | &arg->stateid, &delegation_cred); |
| 2885 | nfs_put_lock_context(l_ctx); |
| 2886 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2887 | return -EBADF; |
| 2888 | } else |
| 2889 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2890 | if (delegation_cred) |
| 2891 | msg.rpc_cred = delegation_cred; |
| 2892 | |
| 2893 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2894 | |
| 2895 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2896 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2897 | renew_lease(server, timestamp); |
| 2898 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2899 | return status; |
| 2900 | } |
| 2901 | |
| 2902 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2903 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2904 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2905 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2907 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2908 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2909 | struct nfs_setattrargs arg = { |
| 2910 | .fh = NFS_FH(inode), |
| 2911 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | .server = server, |
| 2913 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2914 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2915 | }; |
| 2916 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2918 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2920 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2921 | struct nfs4_exception exception = { |
| 2922 | .state = state, |
| 2923 | .inode = inode, |
| 2924 | .stateid = &arg.stateid, |
| 2925 | }; |
| 2926 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2928 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2929 | if (ilabel) |
| 2930 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2933 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2934 | switch (err) { |
| 2935 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2936 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2937 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2938 | "applying open mode checks to " |
| 2939 | "a SETATTR that is not " |
| 2940 | "changing file size.\n", |
| 2941 | server->nfs_client->cl_hostname); |
| 2942 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2943 | if (state && !(state->state & FMODE_WRITE)) { |
| 2944 | err = -EBADF; |
| 2945 | if (sattr->ia_valid & ATTR_OPEN) |
| 2946 | err = -EACCES; |
| 2947 | goto out; |
| 2948 | } |
| 2949 | } |
| 2950 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2952 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | return err; |
| 2954 | } |
| 2955 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2956 | static bool |
| 2957 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2958 | { |
| 2959 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2960 | return false; |
| 2961 | |
| 2962 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2963 | } |
| 2964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | struct nfs4_closedata { |
| 2966 | struct inode *inode; |
| 2967 | struct nfs4_state *state; |
| 2968 | struct nfs_closeargs arg; |
| 2969 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2970 | struct { |
| 2971 | struct nfs4_layoutreturn_args arg; |
| 2972 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 2973 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2974 | u32 roc_barrier; |
| 2975 | bool roc; |
| 2976 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2977 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2978 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | }; |
| 2980 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2981 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2982 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2983 | struct nfs4_closedata *calldata = data; |
| 2984 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2985 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2986 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2987 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 2988 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 2989 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2990 | nfs4_put_open_state(calldata->state); |
| 2991 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2992 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2993 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2994 | kfree(calldata); |
| 2995 | } |
| 2996 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2997 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2999 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3002 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3004 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3005 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3006 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3007 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3008 | |
| 3009 | /* Handle Layoutreturn errors */ |
| 3010 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3011 | switch (calldata->res.lr_ret) { |
| 3012 | default: |
| 3013 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3014 | break; |
| 3015 | case 0: |
| 3016 | calldata->arg.lr_args = NULL; |
| 3017 | calldata->res.lr_res = NULL; |
| 3018 | break; |
| 3019 | case -NFS4ERR_ADMIN_REVOKED: |
| 3020 | case -NFS4ERR_DELEG_REVOKED: |
| 3021 | case -NFS4ERR_EXPIRED: |
| 3022 | case -NFS4ERR_BAD_STATEID: |
| 3023 | case -NFS4ERR_OLD_STATEID: |
| 3024 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3025 | case -NFS4ERR_WRONG_CRED: |
| 3026 | calldata->arg.lr_args = NULL; |
| 3027 | calldata->res.lr_res = NULL; |
| 3028 | calldata->res.lr_ret = 0; |
| 3029 | rpc_restart_call_prepare(task); |
| 3030 | return; |
| 3031 | } |
| 3032 | } |
| 3033 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3034 | /* 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] | 3035 | * the state_owner. we keep this around to process errors |
| 3036 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | switch (task->tk_status) { |
| 3038 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3039 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3040 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3041 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3042 | case -NFS4ERR_ACCESS: |
| 3043 | if (calldata->arg.bitmask != NULL) { |
| 3044 | calldata->arg.bitmask = NULL; |
| 3045 | calldata->res.fattr = NULL; |
| 3046 | task->tk_status = 0; |
| 3047 | rpc_restart_call_prepare(task); |
| 3048 | goto out_release; |
| 3049 | |
| 3050 | } |
| 3051 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3052 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3054 | case -NFS4ERR_EXPIRED: |
| 3055 | nfs4_free_revoked_stateid(server, |
| 3056 | &calldata->arg.stateid, |
| 3057 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3058 | case -NFS4ERR_OLD_STATEID: |
| 3059 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3060 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3061 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3062 | rpc_restart_call_prepare(task); |
| 3063 | goto out_release; |
| 3064 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3065 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3066 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3068 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3069 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3070 | goto out_release; |
| 3071 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3073 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3074 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3075 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3076 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3077 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3078 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3081 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3083 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3084 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3085 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3086 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3087 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3088 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3089 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3090 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3091 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3092 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3093 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3094 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3095 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3096 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3097 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3098 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3099 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3100 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3101 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3102 | if (state->n_rdonly == 0) |
| 3103 | call_close |= is_rdonly; |
| 3104 | else if (is_rdonly) |
| 3105 | calldata->arg.fmode |= FMODE_READ; |
| 3106 | if (state->n_wronly == 0) |
| 3107 | call_close |= is_wronly; |
| 3108 | else if (is_wronly) |
| 3109 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3110 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3111 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3112 | } else if (is_rdwr) |
| 3113 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3114 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3115 | if (!nfs4_valid_open_stateid(state) || |
| 3116 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3117 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3118 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3119 | |
| 3120 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3121 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3122 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3123 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3124 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3125 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3126 | nfs_release_seqid(calldata->arg.seqid); |
| 3127 | goto out_wait; |
| 3128 | } |
| 3129 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3130 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3131 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3132 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3133 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3134 | /* Close-to-open cache consistency revalidation */ |
| 3135 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3136 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3137 | else |
| 3138 | calldata->arg.bitmask = NULL; |
| 3139 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3140 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3141 | calldata->arg.share_access = |
| 3142 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3143 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3144 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3145 | if (calldata->res.fattr == NULL) |
| 3146 | calldata->arg.bitmask = NULL; |
| 3147 | else if (calldata->arg.bitmask == NULL) |
| 3148 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3149 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3150 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3151 | &calldata->arg.seq_args, |
| 3152 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3153 | task) != 0) |
| 3154 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3155 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3156 | return; |
| 3157 | out_no_action: |
| 3158 | task->tk_action = NULL; |
| 3159 | out_wait: |
| 3160 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3163 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3164 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3165 | .rpc_call_done = nfs4_close_done, |
| 3166 | .rpc_release = nfs4_free_closedata, |
| 3167 | }; |
| 3168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | /* |
| 3170 | * It is possible for data to be read/written from a mem-mapped file |
| 3171 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3172 | * This means that we can't safely call nfsv4 close on a file until |
| 3173 | * the inode is cleared. This in turn means that we are not good |
| 3174 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3175 | * share state even when we are done with one of the three share |
| 3176 | * stateid's in the inode. |
| 3177 | * |
| 3178 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3179 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3180 | 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] | 3181 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3182 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3183 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3185 | struct nfs4_state_owner *sp = state->owner; |
| 3186 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3187 | struct rpc_message msg = { |
| 3188 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3189 | .rpc_cred = state->owner->so_cred, |
| 3190 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3191 | struct rpc_task_setup task_setup_data = { |
| 3192 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3193 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3194 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3195 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3196 | .flags = RPC_TASK_ASYNC, |
| 3197 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3198 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3200 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3201 | &task_setup_data.rpc_client, &msg); |
| 3202 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3203 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3205 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3206 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3207 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3209 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3211 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3212 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3213 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3214 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3215 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3216 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3217 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3218 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3219 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3220 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3221 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3222 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3223 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3224 | if (calldata->lr.roc) { |
| 3225 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3226 | calldata->res.lr_res = &calldata->lr.res; |
| 3227 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3228 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3229 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3230 | msg.rpc_argp = &calldata->arg; |
| 3231 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3232 | task_setup_data.callback_data = calldata; |
| 3233 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3234 | if (IS_ERR(task)) |
| 3235 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3236 | status = 0; |
| 3237 | if (wait) |
| 3238 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3239 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3240 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3241 | out_free_calldata: |
| 3242 | kfree(calldata); |
| 3243 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3244 | nfs4_put_open_state(state); |
| 3245 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3246 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3249 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3250 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3251 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3254 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3255 | |
| 3256 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3258 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3259 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3260 | |
| 3261 | nfs4_label_release_security(label); |
| 3262 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3263 | if (IS_ERR(state)) |
| 3264 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3265 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | } |
| 3267 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3268 | 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] | 3269 | { |
| 3270 | if (ctx->state == NULL) |
| 3271 | return; |
| 3272 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3273 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3274 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3275 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3278 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3279 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3280 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3283 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3284 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3285 | struct nfs4_server_caps_arg args = { |
| 3286 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3287 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3288 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | struct nfs4_server_caps_res res = {}; |
| 3290 | struct rpc_message msg = { |
| 3291 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3292 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | .rpc_resp = &res, |
| 3294 | }; |
| 3295 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3296 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3298 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3299 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3300 | FATTR4_WORD0_LINK_SUPPORT | |
| 3301 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3302 | FATTR4_WORD0_ACLSUPPORT; |
| 3303 | if (minorversion) |
| 3304 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3305 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3306 | 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] | 3307 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3308 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3309 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3310 | case 0: |
| 3311 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3312 | res.attr_bitmask[2] = 0; |
| 3313 | break; |
| 3314 | case 1: |
| 3315 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3316 | break; |
| 3317 | case 2: |
| 3318 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3319 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3321 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3322 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3323 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3324 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3325 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3326 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3327 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3328 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | server->caps |= NFS_CAP_ACLS; |
| 3330 | if (res.has_links != 0) |
| 3331 | server->caps |= NFS_CAP_HARDLINKS; |
| 3332 | if (res.has_symlinks != 0) |
| 3333 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3334 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3335 | server->caps |= NFS_CAP_FILEID; |
| 3336 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3337 | server->caps |= NFS_CAP_MODE; |
| 3338 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3339 | server->caps |= NFS_CAP_NLINK; |
| 3340 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3341 | server->caps |= NFS_CAP_OWNER; |
| 3342 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3343 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3344 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3345 | server->caps |= NFS_CAP_ATIME; |
| 3346 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3347 | server->caps |= NFS_CAP_CTIME; |
| 3348 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3349 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3350 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3351 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3352 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3353 | #endif |
| 3354 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3355 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3356 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3357 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3358 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3359 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3360 | 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] | 3361 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3362 | |
| 3363 | /* Avoid a regression due to buggy server */ |
| 3364 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3365 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3366 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3367 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3370 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | return status; |
| 3374 | } |
| 3375 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3376 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | { |
| 3378 | struct nfs4_exception exception = { }; |
| 3379 | int err; |
| 3380 | do { |
| 3381 | err = nfs4_handle_exception(server, |
| 3382 | _nfs4_server_capabilities(server, fhandle), |
| 3383 | &exception); |
| 3384 | } while (exception.retry); |
| 3385 | return err; |
| 3386 | } |
| 3387 | |
| 3388 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3389 | struct nfs_fsinfo *info) |
| 3390 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3391 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3393 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | }; |
| 3395 | struct nfs4_lookup_res res = { |
| 3396 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3397 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | .fh = fhandle, |
| 3399 | }; |
| 3400 | struct rpc_message msg = { |
| 3401 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3402 | .rpc_argp = &args, |
| 3403 | .rpc_resp = &res, |
| 3404 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3405 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3406 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3407 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3408 | /* |
| 3409 | * Process the label in the upcoming getfattr |
| 3410 | */ |
| 3411 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3412 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3413 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3414 | 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] | 3415 | } |
| 3416 | |
| 3417 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3418 | struct nfs_fsinfo *info) |
| 3419 | { |
| 3420 | struct nfs4_exception exception = { }; |
| 3421 | int err; |
| 3422 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3423 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3424 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3425 | switch (err) { |
| 3426 | case 0: |
| 3427 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3428 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3429 | default: |
| 3430 | err = nfs4_handle_exception(server, err, &exception); |
| 3431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3433 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | return err; |
| 3435 | } |
| 3436 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3437 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3438 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3439 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3440 | struct rpc_auth_create_args auth_args = { |
| 3441 | .pseudoflavor = flavor, |
| 3442 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3443 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3444 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3445 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3446 | if (IS_ERR(auth)) |
| 3447 | return -EACCES; |
| 3448 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3451 | /* |
| 3452 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3453 | * |
| 3454 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3455 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3456 | * |
| 3457 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3458 | * negative errno value. |
| 3459 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3460 | 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] | 3461 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3463 | /* Per 3530bis 15.33.5 */ |
| 3464 | static const rpc_authflavor_t flav_array[] = { |
| 3465 | RPC_AUTH_GSS_KRB5P, |
| 3466 | RPC_AUTH_GSS_KRB5I, |
| 3467 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3468 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3469 | RPC_AUTH_NULL, |
| 3470 | }; |
| 3471 | int status = -EPERM; |
| 3472 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3474 | if (server->auth_info.flavor_len > 0) { |
| 3475 | /* try each flavor specified by user */ |
| 3476 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3477 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3478 | server->auth_info.flavors[i]); |
| 3479 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3480 | continue; |
| 3481 | break; |
| 3482 | } |
| 3483 | } else { |
| 3484 | /* no flavors specified by user, try default list */ |
| 3485 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3486 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3487 | flav_array[i]); |
| 3488 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3489 | continue; |
| 3490 | break; |
| 3491 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3492 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3493 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3494 | /* |
| 3495 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3496 | * to access the mount. It could also mean that we tried to mount |
| 3497 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3498 | * existing mount programs don't handle -EACCES very well so it should |
| 3499 | * be mapped to -EPERM instead. |
| 3500 | */ |
| 3501 | if (status == -EACCES) |
| 3502 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3503 | return status; |
| 3504 | } |
| 3505 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3506 | /** |
| 3507 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3508 | * @server: initialized nfs_server handle |
| 3509 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3510 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3511 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3512 | * |
| 3513 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3514 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3515 | 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] | 3516 | struct nfs_fsinfo *info, |
| 3517 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3518 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3519 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3520 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3521 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3522 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3523 | |
| 3524 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3525 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3526 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | if (status == 0) |
| 3529 | status = nfs4_server_capabilities(server, fhandle); |
| 3530 | if (status == 0) |
| 3531 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3532 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3533 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3536 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3537 | struct nfs_fsinfo *info) |
| 3538 | { |
| 3539 | int error; |
| 3540 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3541 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3542 | |
| 3543 | error = nfs4_server_capabilities(server, mntfh); |
| 3544 | if (error < 0) { |
| 3545 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3546 | return error; |
| 3547 | } |
| 3548 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3549 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3550 | if (IS_ERR(label)) |
| 3551 | return PTR_ERR(label); |
| 3552 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3553 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3554 | if (error < 0) { |
| 3555 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3556 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3560 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3561 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3562 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3563 | err_free_label: |
| 3564 | nfs4_label_free(label); |
| 3565 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3566 | return error; |
| 3567 | } |
| 3568 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3569 | /* |
| 3570 | * Get locations and (maybe) other attributes of a referral. |
| 3571 | * Note that we'll actually follow the referral later when |
| 3572 | * we detect fsid mismatch in inode revalidation |
| 3573 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3574 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3575 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3576 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3577 | { |
| 3578 | int status = -ENOMEM; |
| 3579 | struct page *page = NULL; |
| 3580 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3581 | |
| 3582 | page = alloc_page(GFP_KERNEL); |
| 3583 | if (page == NULL) |
| 3584 | goto out; |
| 3585 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3586 | if (locations == NULL) |
| 3587 | goto out; |
| 3588 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3589 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3590 | if (status != 0) |
| 3591 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3592 | |
| 3593 | /* |
| 3594 | * If the fsid didn't change, this is a migration event, not a |
| 3595 | * referral. Cause us to drop into the exception handler, which |
| 3596 | * will kick off migration recovery. |
| 3597 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3598 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3599 | dprintk("%s: server did not return a different fsid for" |
| 3600 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3601 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3602 | goto out; |
| 3603 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3604 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3605 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3606 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3607 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3608 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3609 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3610 | out: |
| 3611 | if (page) |
| 3612 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3613 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3614 | return status; |
| 3615 | } |
| 3616 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3617 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3618 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | { |
| 3620 | struct nfs4_getattr_arg args = { |
| 3621 | .fh = fhandle, |
| 3622 | .bitmask = server->attr_bitmask, |
| 3623 | }; |
| 3624 | struct nfs4_getattr_res res = { |
| 3625 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3626 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | .server = server, |
| 3628 | }; |
| 3629 | struct rpc_message msg = { |
| 3630 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3631 | .rpc_argp = &args, |
| 3632 | .rpc_resp = &res, |
| 3633 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3634 | |
| 3635 | args.bitmask = nfs4_bitmask(server, label); |
| 3636 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3637 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3638 | 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] | 3639 | } |
| 3640 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3641 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3642 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | { |
| 3644 | struct nfs4_exception exception = { }; |
| 3645 | int err; |
| 3646 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3647 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3648 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3649 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | &exception); |
| 3651 | } while (exception.retry); |
| 3652 | return err; |
| 3653 | } |
| 3654 | |
| 3655 | /* |
| 3656 | * The file is not closed if it is opened due to the a request to change |
| 3657 | * the size of the file. The open call will not be needed once the |
| 3658 | * VFS layer lookup-intents are implemented. |
| 3659 | * |
| 3660 | * Close is called when the inode is destroyed. |
| 3661 | * If we haven't opened the file for O_WRONLY, we |
| 3662 | * need to in the size_change case to obtain a stateid. |
| 3663 | * |
| 3664 | * Got race? |
| 3665 | * Because OPEN is always done by name in nfsv4, it is |
| 3666 | * possible that we opened a different file by the same |
| 3667 | * name. We can recognize this race condition, but we |
| 3668 | * can't do anything about it besides returning an error. |
| 3669 | * |
| 3670 | * This will be fixed with VFS changes (lookup-intent). |
| 3671 | */ |
| 3672 | static int |
| 3673 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3674 | struct iattr *sattr) |
| 3675 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3676 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3677 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3678 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3679 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | int status; |
| 3681 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3682 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3683 | sattr->ia_valid & ATTR_SIZE && |
| 3684 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3685 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3686 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3687 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3689 | /* Deal with open(O_TRUNC) */ |
| 3690 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3691 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3692 | |
| 3693 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3694 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3695 | return 0; |
| 3696 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3697 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3698 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3699 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3700 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3701 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3702 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3703 | } |
| 3704 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3705 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3706 | if (IS_ERR(label)) |
| 3707 | return PTR_ERR(label); |
| 3708 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3709 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3710 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3711 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3712 | nfs_setsecurity(inode, fattr, label); |
| 3713 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3714 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | return status; |
| 3716 | } |
| 3717 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3718 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3719 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3720 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3721 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3722 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3723 | int status; |
| 3724 | struct nfs4_lookup_arg args = { |
| 3725 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3726 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3727 | .name = name, |
| 3728 | }; |
| 3729 | struct nfs4_lookup_res res = { |
| 3730 | .server = server, |
| 3731 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3732 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3733 | .fh = fhandle, |
| 3734 | }; |
| 3735 | struct rpc_message msg = { |
| 3736 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3737 | .rpc_argp = &args, |
| 3738 | .rpc_resp = &res, |
| 3739 | }; |
| 3740 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3741 | args.bitmask = nfs4_bitmask(server, label); |
| 3742 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3743 | nfs_fattr_init(fattr); |
| 3744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3746 | 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] | 3747 | dprintk("NFS reply lookup: %d\n", status); |
| 3748 | return status; |
| 3749 | } |
| 3750 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3751 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3752 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3753 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3754 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3755 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3756 | fattr->nlink = 2; |
| 3757 | } |
| 3758 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3759 | 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] | 3760 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3761 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3762 | { |
| 3763 | struct nfs4_exception exception = { }; |
| 3764 | struct rpc_clnt *client = *clnt; |
| 3765 | int err; |
| 3766 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3767 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3768 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3769 | switch (err) { |
| 3770 | case -NFS4ERR_BADNAME: |
| 3771 | err = -ENOENT; |
| 3772 | goto out; |
| 3773 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3774 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3775 | if (err == -NFS4ERR_MOVED) |
| 3776 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3777 | goto out; |
| 3778 | case -NFS4ERR_WRONGSEC: |
| 3779 | err = -EPERM; |
| 3780 | if (client != *clnt) |
| 3781 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3782 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3783 | if (IS_ERR(client)) |
| 3784 | return PTR_ERR(client); |
| 3785 | |
| 3786 | exception.retry = 1; |
| 3787 | break; |
| 3788 | default: |
| 3789 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3790 | } |
| 3791 | } while (exception.retry); |
| 3792 | |
| 3793 | out: |
| 3794 | if (err == 0) |
| 3795 | *clnt = client; |
| 3796 | else if (client != *clnt) |
| 3797 | rpc_shutdown_client(client); |
| 3798 | |
| 3799 | return err; |
| 3800 | } |
| 3801 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3802 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3803 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3804 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3806 | int status; |
| 3807 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3808 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3809 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3810 | if (client != NFS_CLIENT(dir)) { |
| 3811 | rpc_shutdown_client(client); |
| 3812 | nfs_fixup_secinfo_attributes(fattr); |
| 3813 | } |
| 3814 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3817 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3818 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3819 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3820 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3821 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3822 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3823 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3824 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3825 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3826 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3827 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3828 | } |
| 3829 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 3830 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 3831 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3832 | struct nfs4_label *label) |
| 3833 | { |
| 3834 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 3835 | struct nfs_server *server = NFS_SERVER(inode); |
| 3836 | int status; |
| 3837 | struct nfs4_lookupp_arg args = { |
| 3838 | .bitmask = server->attr_bitmask, |
| 3839 | .fh = NFS_FH(inode), |
| 3840 | }; |
| 3841 | struct nfs4_lookupp_res res = { |
| 3842 | .server = server, |
| 3843 | .fattr = fattr, |
| 3844 | .label = label, |
| 3845 | .fh = fhandle, |
| 3846 | }; |
| 3847 | struct rpc_message msg = { |
| 3848 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 3849 | .rpc_argp = &args, |
| 3850 | .rpc_resp = &res, |
| 3851 | }; |
| 3852 | |
| 3853 | args.bitmask = nfs4_bitmask(server, label); |
| 3854 | |
| 3855 | nfs_fattr_init(fattr); |
| 3856 | |
| 3857 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 3858 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 3859 | &res.seq_res, 0); |
| 3860 | dprintk("NFS reply lookupp: %d\n", status); |
| 3861 | return status; |
| 3862 | } |
| 3863 | |
| 3864 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 3865 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 3866 | { |
| 3867 | struct nfs4_exception exception = { }; |
| 3868 | int err; |
| 3869 | do { |
| 3870 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 3871 | trace_nfs4_lookupp(inode, err); |
| 3872 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 3873 | &exception); |
| 3874 | } while (exception.retry); |
| 3875 | return err; |
| 3876 | } |
| 3877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3879 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3880 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | struct nfs4_accessargs args = { |
| 3882 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3883 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3885 | struct nfs4_accessres res = { |
| 3886 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3887 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | struct rpc_message msg = { |
| 3889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3890 | .rpc_argp = &args, |
| 3891 | .rpc_resp = &res, |
| 3892 | .rpc_cred = entry->cred, |
| 3893 | }; |
| 3894 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3895 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | |
| 3897 | /* |
| 3898 | * Determine which access bits we want to ask for... |
| 3899 | */ |
| 3900 | if (mode & MAY_READ) |
| 3901 | args.access |= NFS4_ACCESS_READ; |
| 3902 | if (S_ISDIR(inode->i_mode)) { |
| 3903 | if (mode & MAY_WRITE) |
| 3904 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3905 | if (mode & MAY_EXEC) |
| 3906 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3907 | } else { |
| 3908 | if (mode & MAY_WRITE) |
| 3909 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3910 | if (mode & MAY_EXEC) |
| 3911 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3912 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3913 | |
| 3914 | res.fattr = nfs_alloc_fattr(); |
| 3915 | if (res.fattr == NULL) |
| 3916 | return -ENOMEM; |
| 3917 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3918 | 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] | 3919 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3920 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3921 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3923 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | return status; |
| 3925 | } |
| 3926 | |
| 3927 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3928 | { |
| 3929 | struct nfs4_exception exception = { }; |
| 3930 | int err; |
| 3931 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3932 | err = _nfs4_proc_access(inode, entry); |
| 3933 | trace_nfs4_access(inode, err); |
| 3934 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | &exception); |
| 3936 | } while (exception.retry); |
| 3937 | return err; |
| 3938 | } |
| 3939 | |
| 3940 | /* |
| 3941 | * TODO: For the time being, we don't try to get any attributes |
| 3942 | * along with any of the zero-copy operations READ, READDIR, |
| 3943 | * READLINK, WRITE. |
| 3944 | * |
| 3945 | * In the case of the first three, we want to put the GETATTR |
| 3946 | * after the read-type operation -- this is because it is hard |
| 3947 | * to predict the length of a GETATTR response in v4, and thus |
| 3948 | * align the READ data correctly. This means that the GETATTR |
| 3949 | * may end up partially falling into the page cache, and we should |
| 3950 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3951 | * To do this efficiently, we need to know the total length |
| 3952 | * of data received, which doesn't seem to be available outside |
| 3953 | * of the RPC layer. |
| 3954 | * |
| 3955 | * In the case of WRITE, we also want to put the GETATTR after |
| 3956 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3957 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | * |
| 3959 | * Both of these changes to the XDR layer would in fact be quite |
| 3960 | * minor, but I decided to leave them for a subsequent patch. |
| 3961 | */ |
| 3962 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3963 | unsigned int pgbase, unsigned int pglen) |
| 3964 | { |
| 3965 | struct nfs4_readlink args = { |
| 3966 | .fh = NFS_FH(inode), |
| 3967 | .pgbase = pgbase, |
| 3968 | .pglen = pglen, |
| 3969 | .pages = &page, |
| 3970 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3971 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | struct rpc_message msg = { |
| 3973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3974 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3975 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | }; |
| 3977 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3978 | 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] | 3979 | } |
| 3980 | |
| 3981 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3982 | unsigned int pgbase, unsigned int pglen) |
| 3983 | { |
| 3984 | struct nfs4_exception exception = { }; |
| 3985 | int err; |
| 3986 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3987 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3988 | trace_nfs4_readlink(inode, err); |
| 3989 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | &exception); |
| 3991 | } while (exception.retry); |
| 3992 | return err; |
| 3993 | } |
| 3994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3996 | * 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] | 3997 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | static int |
| 3999 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4000 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4002 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4003 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4004 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | int status = 0; |
| 4007 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4008 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4009 | if (IS_ERR(ctx)) |
| 4010 | return PTR_ERR(ctx); |
| 4011 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4012 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4013 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4014 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4015 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4016 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | if (IS_ERR(state)) { |
| 4018 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4019 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4022 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4023 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | return status; |
| 4025 | } |
| 4026 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4027 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4029 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4030 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4032 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4034 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4035 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4036 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4038 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4039 | .rpc_argp = &args, |
| 4040 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4042 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4043 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4044 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4045 | 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] | 4046 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4047 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | return status; |
| 4049 | } |
| 4050 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4051 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | { |
| 4053 | struct nfs4_exception exception = { }; |
| 4054 | int err; |
| 4055 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4056 | err = _nfs4_proc_remove(dir, name); |
| 4057 | trace_nfs4_remove(dir, name, err); |
| 4058 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | &exception); |
| 4060 | } while (exception.retry); |
| 4061 | return err; |
| 4062 | } |
| 4063 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4064 | 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] | 4065 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4066 | struct nfs_server *server = NFS_SERVER(dir); |
| 4067 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4068 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4070 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4072 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4073 | |
| 4074 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4077 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4078 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4079 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4080 | &data->args.seq_args, |
| 4081 | &data->res.seq_res, |
| 4082 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4085 | 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] | 4086 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4087 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4088 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4089 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4090 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4091 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4092 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4093 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4094 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4095 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4096 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4097 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4100 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4101 | { |
| 4102 | struct nfs_server *server = NFS_SERVER(dir); |
| 4103 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4104 | struct nfs_renameres *res = msg->rpc_resp; |
| 4105 | |
| 4106 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4107 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4108 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4109 | } |
| 4110 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4111 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4112 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4113 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4114 | &data->args.seq_args, |
| 4115 | &data->res.seq_res, |
| 4116 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4120 | struct inode *new_dir) |
| 4121 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4122 | struct nfs_renamedata *data = task->tk_calldata; |
| 4123 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4124 | |
| 4125 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4126 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4127 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4128 | return 0; |
| 4129 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4130 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4131 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4132 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4133 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4134 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4135 | return 1; |
| 4136 | } |
| 4137 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4138 | 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] | 4139 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4140 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | struct nfs4_link_arg arg = { |
| 4142 | .fh = NFS_FH(inode), |
| 4143 | .dir_fh = NFS_FH(dir), |
| 4144 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4145 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4147 | struct nfs4_link_res res = { |
| 4148 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4149 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4150 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | struct rpc_message msg = { |
| 4152 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4153 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4154 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4156 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4158 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4159 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4160 | goto out; |
| 4161 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4162 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4163 | if (IS_ERR(res.label)) { |
| 4164 | status = PTR_ERR(res.label); |
| 4165 | goto out; |
| 4166 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4167 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4168 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4169 | 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] | 4170 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4171 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4172 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4173 | if (!status) |
| 4174 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4175 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4176 | |
| 4177 | |
| 4178 | nfs4_label_free(res.label); |
| 4179 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4180 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4181 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | return status; |
| 4183 | } |
| 4184 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4185 | 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] | 4186 | { |
| 4187 | struct nfs4_exception exception = { }; |
| 4188 | int err; |
| 4189 | do { |
| 4190 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4191 | _nfs4_proc_link(inode, dir, name), |
| 4192 | &exception); |
| 4193 | } while (exception.retry); |
| 4194 | return err; |
| 4195 | } |
| 4196 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4197 | struct nfs4_createdata { |
| 4198 | struct rpc_message msg; |
| 4199 | struct nfs4_create_arg arg; |
| 4200 | struct nfs4_create_res res; |
| 4201 | struct nfs_fh fh; |
| 4202 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4203 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4204 | }; |
| 4205 | |
| 4206 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4207 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4208 | { |
| 4209 | struct nfs4_createdata *data; |
| 4210 | |
| 4211 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4212 | if (data != NULL) { |
| 4213 | struct nfs_server *server = NFS_SERVER(dir); |
| 4214 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4215 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4216 | if (IS_ERR(data->label)) |
| 4217 | goto out_free; |
| 4218 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4219 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4220 | data->msg.rpc_argp = &data->arg; |
| 4221 | data->msg.rpc_resp = &data->res; |
| 4222 | data->arg.dir_fh = NFS_FH(dir); |
| 4223 | data->arg.server = server; |
| 4224 | data->arg.name = name; |
| 4225 | data->arg.attrs = sattr; |
| 4226 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4227 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4228 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4229 | data->res.server = server; |
| 4230 | data->res.fh = &data->fh; |
| 4231 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4232 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4233 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4234 | } |
| 4235 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4236 | out_free: |
| 4237 | kfree(data); |
| 4238 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4242 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4243 | 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] | 4244 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4245 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4246 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4247 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4248 | 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] | 4249 | } |
| 4250 | return status; |
| 4251 | } |
| 4252 | |
| 4253 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4254 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4255 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4256 | kfree(data); |
| 4257 | } |
| 4258 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4259 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4260 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4261 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4263 | struct nfs4_createdata *data; |
| 4264 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4266 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4267 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4268 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4269 | status = -ENOMEM; |
| 4270 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4271 | if (data == NULL) |
| 4272 | goto out; |
| 4273 | |
| 4274 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4275 | data->arg.u.symlink.pages = &page; |
| 4276 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4277 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4279 | status = nfs4_do_create(dir, dentry, data); |
| 4280 | |
| 4281 | nfs4_free_createdata(data); |
| 4282 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | return status; |
| 4284 | } |
| 4285 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4286 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4287 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | { |
| 4289 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4290 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4292 | |
| 4293 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4296 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4297 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4298 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | &exception); |
| 4300 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4301 | |
| 4302 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | return err; |
| 4304 | } |
| 4305 | |
| 4306 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4307 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4309 | struct nfs4_createdata *data; |
| 4310 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4312 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4313 | if (data == NULL) |
| 4314 | goto out; |
| 4315 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4316 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4317 | status = nfs4_do_create(dir, dentry, data); |
| 4318 | |
| 4319 | nfs4_free_createdata(data); |
| 4320 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | return status; |
| 4322 | } |
| 4323 | |
| 4324 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4325 | struct iattr *sattr) |
| 4326 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4327 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4329 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4331 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4332 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4333 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4334 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4335 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4337 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4338 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4339 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | &exception); |
| 4341 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4342 | nfs4_label_release_security(label); |
| 4343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | return err; |
| 4345 | } |
| 4346 | |
| 4347 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4348 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4350 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | struct nfs4_readdir_arg args = { |
| 4352 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4353 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | .pgbase = 0, |
| 4355 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4356 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4357 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | }; |
| 4359 | struct nfs4_readdir_res res; |
| 4360 | struct rpc_message msg = { |
| 4361 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4362 | .rpc_argp = &args, |
| 4363 | .rpc_resp = &res, |
| 4364 | .rpc_cred = cred, |
| 4365 | }; |
| 4366 | int status; |
| 4367 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4368 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4369 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4370 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4371 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4372 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4373 | 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] | 4374 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4375 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4376 | status += args.pgbase; |
| 4377 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4378 | |
| 4379 | nfs_invalidate_atime(dir); |
| 4380 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4381 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | return status; |
| 4383 | } |
| 4384 | |
| 4385 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4386 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | { |
| 4388 | struct nfs4_exception exception = { }; |
| 4389 | int err; |
| 4390 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4391 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4392 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4393 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4394 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | &exception); |
| 4396 | } while (exception.retry); |
| 4397 | return err; |
| 4398 | } |
| 4399 | |
| 4400 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4401 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4403 | struct nfs4_createdata *data; |
| 4404 | int mode = sattr->ia_mode; |
| 4405 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4407 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4408 | if (data == NULL) |
| 4409 | goto out; |
| 4410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4412 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4414 | data->arg.ftype = NF4BLK; |
| 4415 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4416 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | } |
| 4418 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4419 | data->arg.ftype = NF4CHR; |
| 4420 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4421 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4422 | } else if (!S_ISSOCK(mode)) { |
| 4423 | status = -EINVAL; |
| 4424 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4426 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4427 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4428 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4429 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4430 | nfs4_free_createdata(data); |
| 4431 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | return status; |
| 4433 | } |
| 4434 | |
| 4435 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4436 | struct iattr *sattr, dev_t rdev) |
| 4437 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4438 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4440 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4442 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4443 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4444 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4445 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4446 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4448 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4449 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4450 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | &exception); |
| 4452 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4453 | |
| 4454 | nfs4_label_release_security(label); |
| 4455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | return err; |
| 4457 | } |
| 4458 | |
| 4459 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4460 | struct nfs_fsstat *fsstat) |
| 4461 | { |
| 4462 | struct nfs4_statfs_arg args = { |
| 4463 | .fh = fhandle, |
| 4464 | .bitmask = server->attr_bitmask, |
| 4465 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4466 | struct nfs4_statfs_res res = { |
| 4467 | .fsstat = fsstat, |
| 4468 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | struct rpc_message msg = { |
| 4470 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4471 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4472 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | }; |
| 4474 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4475 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4476 | 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] | 4477 | } |
| 4478 | |
| 4479 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4480 | { |
| 4481 | struct nfs4_exception exception = { }; |
| 4482 | int err; |
| 4483 | do { |
| 4484 | err = nfs4_handle_exception(server, |
| 4485 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4486 | &exception); |
| 4487 | } while (exception.retry); |
| 4488 | return err; |
| 4489 | } |
| 4490 | |
| 4491 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4492 | struct nfs_fsinfo *fsinfo) |
| 4493 | { |
| 4494 | struct nfs4_fsinfo_arg args = { |
| 4495 | .fh = fhandle, |
| 4496 | .bitmask = server->attr_bitmask, |
| 4497 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4498 | struct nfs4_fsinfo_res res = { |
| 4499 | .fsinfo = fsinfo, |
| 4500 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | struct rpc_message msg = { |
| 4502 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4503 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4504 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | }; |
| 4506 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4507 | 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] | 4508 | } |
| 4509 | |
| 4510 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4511 | { |
| 4512 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4513 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | int err; |
| 4515 | |
| 4516 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4517 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4518 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4519 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4520 | nfs4_set_lease_period(server->nfs_client, |
| 4521 | fsinfo->lease_time * HZ, |
| 4522 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4523 | break; |
| 4524 | } |
| 4525 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | } while (exception.retry); |
| 4527 | return err; |
| 4528 | } |
| 4529 | |
| 4530 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4531 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4532 | int error; |
| 4533 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4534 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4535 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4536 | if (error == 0) { |
| 4537 | /* block layout checks this! */ |
| 4538 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4539 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4540 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4541 | |
| 4542 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4546 | struct nfs_pathconf *pathconf) |
| 4547 | { |
| 4548 | struct nfs4_pathconf_arg args = { |
| 4549 | .fh = fhandle, |
| 4550 | .bitmask = server->attr_bitmask, |
| 4551 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4552 | struct nfs4_pathconf_res res = { |
| 4553 | .pathconf = pathconf, |
| 4554 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | struct rpc_message msg = { |
| 4556 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4557 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4558 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | }; |
| 4560 | |
| 4561 | /* None of the pathconf attributes are mandatory to implement */ |
| 4562 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4563 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4564 | return 0; |
| 4565 | } |
| 4566 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4567 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4568 | 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] | 4569 | } |
| 4570 | |
| 4571 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4572 | struct nfs_pathconf *pathconf) |
| 4573 | { |
| 4574 | struct nfs4_exception exception = { }; |
| 4575 | int err; |
| 4576 | |
| 4577 | do { |
| 4578 | err = nfs4_handle_exception(server, |
| 4579 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4580 | &exception); |
| 4581 | } while (exception.retry); |
| 4582 | return err; |
| 4583 | } |
| 4584 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4585 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4586 | const struct nfs_open_context *ctx, |
| 4587 | const struct nfs_lock_context *l_ctx, |
| 4588 | fmode_t fmode) |
| 4589 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4590 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4591 | } |
| 4592 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4593 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4594 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4595 | const struct nfs_open_context *ctx, |
| 4596 | const struct nfs_lock_context *l_ctx, |
| 4597 | fmode_t fmode) |
| 4598 | { |
| 4599 | nfs4_stateid current_stateid; |
| 4600 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4601 | /* If the current stateid represents a lost lock, then exit */ |
| 4602 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4603 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4604 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4605 | } |
| 4606 | |
| 4607 | static bool nfs4_error_stateid_expired(int err) |
| 4608 | { |
| 4609 | switch (err) { |
| 4610 | case -NFS4ERR_DELEG_REVOKED: |
| 4611 | case -NFS4ERR_ADMIN_REVOKED: |
| 4612 | case -NFS4ERR_BAD_STATEID: |
| 4613 | case -NFS4ERR_STALE_STATEID: |
| 4614 | case -NFS4ERR_OLD_STATEID: |
| 4615 | case -NFS4ERR_OPENMODE: |
| 4616 | case -NFS4ERR_EXPIRED: |
| 4617 | return true; |
| 4618 | } |
| 4619 | return false; |
| 4620 | } |
| 4621 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4622 | 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] | 4623 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4624 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4626 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4627 | if (task->tk_status < 0) { |
| 4628 | struct nfs4_exception exception = { |
| 4629 | .inode = hdr->inode, |
| 4630 | .state = hdr->args.context->state, |
| 4631 | .stateid = &hdr->args.stateid, |
| 4632 | }; |
| 4633 | task->tk_status = nfs4_async_handle_exception(task, |
| 4634 | server, task->tk_status, &exception); |
| 4635 | if (exception.retry) { |
| 4636 | rpc_restart_call_prepare(task); |
| 4637 | return -EAGAIN; |
| 4638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4642 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4643 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | } |
| 4645 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4646 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4647 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4648 | { |
| 4649 | |
| 4650 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4651 | nfs4_stateid_is_current(&args->stateid, |
| 4652 | args->context, |
| 4653 | args->lock_context, |
| 4654 | FMODE_READ)) |
| 4655 | return false; |
| 4656 | rpc_restart_call_prepare(task); |
| 4657 | return true; |
| 4658 | } |
| 4659 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4660 | 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] | 4661 | { |
| 4662 | |
| 4663 | dprintk("--> %s\n", __func__); |
| 4664 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4665 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4666 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4667 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4668 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4669 | if (task->tk_status > 0) |
| 4670 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4671 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4672 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4675 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4676 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4678 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4679 | if (!hdr->pgio_done_cb) |
| 4680 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4681 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4682 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | } |
| 4684 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4685 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4686 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4687 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4688 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4689 | &hdr->args.seq_args, |
| 4690 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4691 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4692 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4693 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4694 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4695 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4696 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4697 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4698 | return -EIO; |
| 4699 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | } |
| 4701 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4702 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4703 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4705 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4706 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4707 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4708 | if (task->tk_status < 0) { |
| 4709 | struct nfs4_exception exception = { |
| 4710 | .inode = hdr->inode, |
| 4711 | .state = hdr->args.context->state, |
| 4712 | .stateid = &hdr->args.stateid, |
| 4713 | }; |
| 4714 | task->tk_status = nfs4_async_handle_exception(task, |
| 4715 | NFS_SERVER(inode), task->tk_status, |
| 4716 | &exception); |
| 4717 | if (exception.retry) { |
| 4718 | rpc_restart_call_prepare(task); |
| 4719 | return -EAGAIN; |
| 4720 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4722 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4723 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4724 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4725 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4726 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | } |
| 4728 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4729 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4730 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4731 | { |
| 4732 | |
| 4733 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4734 | nfs4_stateid_is_current(&args->stateid, |
| 4735 | args->context, |
| 4736 | args->lock_context, |
| 4737 | FMODE_WRITE)) |
| 4738 | return false; |
| 4739 | rpc_restart_call_prepare(task); |
| 4740 | return true; |
| 4741 | } |
| 4742 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4743 | 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] | 4744 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4745 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4746 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4747 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4748 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4749 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4750 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4751 | } |
| 4752 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4753 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4754 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4755 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4756 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4757 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4758 | return false; |
| 4759 | /* Otherwise, request attributes if and only if we don't hold |
| 4760 | * a delegation |
| 4761 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4762 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4763 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4764 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4765 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4766 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4768 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4769 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4770 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4771 | hdr->args.bitmask = NULL; |
| 4772 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4773 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4774 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4775 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4776 | if (!hdr->pgio_done_cb) |
| 4777 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4778 | hdr->res.server = server; |
| 4779 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4781 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4782 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | } |
| 4784 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4785 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4786 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4787 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4788 | &data->args.seq_args, |
| 4789 | &data->res.seq_res, |
| 4790 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4793 | 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] | 4794 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4796 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4797 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4798 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4799 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4800 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4801 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4803 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | } |
| 4805 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4806 | 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] | 4807 | { |
| 4808 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4809 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4810 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4811 | } |
| 4812 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4813 | 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] | 4814 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4815 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4816 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4817 | if (data->commit_done_cb == NULL) |
| 4818 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4819 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4820 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4821 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4824 | struct nfs4_renewdata { |
| 4825 | struct nfs_client *client; |
| 4826 | unsigned long timestamp; |
| 4827 | }; |
| 4828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | /* |
| 4830 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4831 | * standalone procedure for queueing an asynchronous RENEW. |
| 4832 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4833 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4834 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4835 | struct nfs4_renewdata *data = calldata; |
| 4836 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4837 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4838 | if (atomic_read(&clp->cl_count) > 1) |
| 4839 | nfs4_schedule_state_renewal(clp); |
| 4840 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4841 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4842 | } |
| 4843 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4844 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4846 | struct nfs4_renewdata *data = calldata; |
| 4847 | struct nfs_client *clp = data->client; |
| 4848 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4850 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4851 | switch (task->tk_status) { |
| 4852 | case 0: |
| 4853 | break; |
| 4854 | case -NFS4ERR_LEASE_MOVED: |
| 4855 | nfs4_schedule_lease_moved_recovery(clp); |
| 4856 | break; |
| 4857 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4858 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4859 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4860 | return; |
| 4861 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4862 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4863 | return; |
| 4864 | } |
| 4865 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4867 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | } |
| 4869 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4870 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4871 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4872 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4873 | }; |
| 4874 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4875 | 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] | 4876 | { |
| 4877 | struct rpc_message msg = { |
| 4878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4879 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4880 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4882 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4884 | if (renew_flags == 0) |
| 4885 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4886 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4887 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4888 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 4889 | if (data == NULL) { |
| 4890 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4891 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 4892 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4893 | data->client = clp; |
| 4894 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4895 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4896 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4899 | 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] | 4900 | { |
| 4901 | struct rpc_message msg = { |
| 4902 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4903 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4904 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | }; |
| 4906 | unsigned long now = jiffies; |
| 4907 | int status; |
| 4908 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4909 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | if (status < 0) |
| 4911 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4912 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | return 0; |
| 4914 | } |
| 4915 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4916 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4917 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4918 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4919 | } |
| 4920 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4921 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4922 | * 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] | 4923 | * the stack. |
| 4924 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4925 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4926 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4927 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4928 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4929 | { |
| 4930 | struct page *newpage, **spages; |
| 4931 | int rc = 0; |
| 4932 | size_t len; |
| 4933 | spages = pages; |
| 4934 | |
| 4935 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4936 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4937 | newpage = alloc_page(GFP_KERNEL); |
| 4938 | |
| 4939 | if (newpage == NULL) |
| 4940 | goto unwind; |
| 4941 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 4942 | buf += len; |
| 4943 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4944 | *pages++ = newpage; |
| 4945 | rc++; |
| 4946 | } while (buflen != 0); |
| 4947 | |
| 4948 | return rc; |
| 4949 | |
| 4950 | unwind: |
| 4951 | for(; rc > 0; rc--) |
| 4952 | __free_page(spages[rc-1]); |
| 4953 | return -ENOMEM; |
| 4954 | } |
| 4955 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4956 | struct nfs4_cached_acl { |
| 4957 | int cached; |
| 4958 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4959 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4960 | }; |
| 4961 | |
| 4962 | 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] | 4963 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4964 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4965 | |
| 4966 | spin_lock(&inode->i_lock); |
| 4967 | kfree(nfsi->nfs4_acl); |
| 4968 | nfsi->nfs4_acl = acl; |
| 4969 | spin_unlock(&inode->i_lock); |
| 4970 | } |
| 4971 | |
| 4972 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4973 | { |
| 4974 | nfs4_set_cached_acl(inode, NULL); |
| 4975 | } |
| 4976 | |
| 4977 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4978 | { |
| 4979 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4980 | struct nfs4_cached_acl *acl; |
| 4981 | int ret = -ENOENT; |
| 4982 | |
| 4983 | spin_lock(&inode->i_lock); |
| 4984 | acl = nfsi->nfs4_acl; |
| 4985 | if (acl == NULL) |
| 4986 | goto out; |
| 4987 | if (buf == NULL) /* user is just asking for length */ |
| 4988 | goto out_len; |
| 4989 | if (acl->cached == 0) |
| 4990 | goto out; |
| 4991 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4992 | if (acl->len > buflen) |
| 4993 | goto out; |
| 4994 | memcpy(buf, acl->data, acl->len); |
| 4995 | out_len: |
| 4996 | ret = acl->len; |
| 4997 | out: |
| 4998 | spin_unlock(&inode->i_lock); |
| 4999 | return ret; |
| 5000 | } |
| 5001 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5002 | 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] | 5003 | { |
| 5004 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5005 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5006 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5007 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5008 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5009 | if (acl == NULL) |
| 5010 | goto out; |
| 5011 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5012 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5013 | } else { |
| 5014 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5015 | if (acl == NULL) |
| 5016 | goto out; |
| 5017 | acl->cached = 0; |
| 5018 | } |
| 5019 | acl->len = acl_len; |
| 5020 | out: |
| 5021 | nfs4_set_cached_acl(inode, acl); |
| 5022 | } |
| 5023 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5024 | /* |
| 5025 | * The getxattr API returns the required buffer length when called with a |
| 5026 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5027 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5028 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5029 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5030 | * the cache. If not so, we throw away the page, and cache the required |
| 5031 | * length. The next getxattr call will then produce another round trip to |
| 5032 | * the server, this time with the input buf of the required size. |
| 5033 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5034 | 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] | 5035 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5036 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5037 | struct nfs_getaclargs args = { |
| 5038 | .fh = NFS_FH(inode), |
| 5039 | .acl_pages = pages, |
| 5040 | .acl_len = buflen, |
| 5041 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5042 | struct nfs_getaclres res = { |
| 5043 | .acl_len = buflen, |
| 5044 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5045 | struct rpc_message msg = { |
| 5046 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5047 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5048 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5049 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5050 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5051 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5052 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5053 | if (npages > ARRAY_SIZE(pages)) |
| 5054 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5055 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5056 | for (i = 0; i < npages; i++) { |
| 5057 | pages[i] = alloc_page(GFP_KERNEL); |
| 5058 | if (!pages[i]) |
| 5059 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5060 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5061 | |
| 5062 | /* for decoding across pages */ |
| 5063 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5064 | if (!res.acl_scratch) |
| 5065 | goto out_free; |
| 5066 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5067 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5068 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5069 | 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] | 5070 | __func__, buf, buflen, npages, args.acl_len); |
| 5071 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5072 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5073 | if (ret) |
| 5074 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5075 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5076 | /* Handle the case where the passed-in buffer is too short */ |
| 5077 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5078 | /* Did the user only issue a request for the acl length? */ |
| 5079 | if (buf == NULL) |
| 5080 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5081 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5082 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5083 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5084 | 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] | 5085 | if (buf) { |
| 5086 | if (res.acl_len > buflen) { |
| 5087 | ret = -ERANGE; |
| 5088 | goto out_free; |
| 5089 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5090 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5091 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5092 | out_ok: |
| 5093 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5094 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5095 | for (i = 0; i < npages; i++) |
| 5096 | if (pages[i]) |
| 5097 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5098 | if (res.acl_scratch) |
| 5099 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5100 | return ret; |
| 5101 | } |
| 5102 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5103 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5104 | { |
| 5105 | struct nfs4_exception exception = { }; |
| 5106 | ssize_t ret; |
| 5107 | do { |
| 5108 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5109 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5110 | if (ret >= 0) |
| 5111 | break; |
| 5112 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5113 | } while (exception.retry); |
| 5114 | return ret; |
| 5115 | } |
| 5116 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5117 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5118 | { |
| 5119 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5120 | int ret; |
| 5121 | |
| 5122 | if (!nfs4_server_supports_acls(server)) |
| 5123 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5124 | ret = nfs_revalidate_inode(server, inode); |
| 5125 | if (ret < 0) |
| 5126 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5127 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5128 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5129 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5130 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5131 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5132 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5133 | return ret; |
| 5134 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5135 | } |
| 5136 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5137 | 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] | 5138 | { |
| 5139 | struct nfs_server *server = NFS_SERVER(inode); |
| 5140 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5141 | struct nfs_setaclargs arg = { |
| 5142 | .fh = NFS_FH(inode), |
| 5143 | .acl_pages = pages, |
| 5144 | .acl_len = buflen, |
| 5145 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5146 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5147 | struct rpc_message msg = { |
| 5148 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5149 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5150 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5151 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5152 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5153 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5154 | |
| 5155 | if (!nfs4_server_supports_acls(server)) |
| 5156 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5157 | if (npages > ARRAY_SIZE(pages)) |
| 5158 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5159 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5160 | if (i < 0) |
| 5161 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5162 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5163 | 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] | 5164 | |
| 5165 | /* |
| 5166 | * Free each page after tx, so the only ref left is |
| 5167 | * held by the network stack |
| 5168 | */ |
| 5169 | for (; i > 0; i--) |
| 5170 | put_page(pages[i-1]); |
| 5171 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5172 | /* |
| 5173 | * Acl update can result in inode attribute update. |
| 5174 | * so mark the attribute cache invalid. |
| 5175 | */ |
| 5176 | spin_lock(&inode->i_lock); |
| 5177 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5178 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5179 | nfs_access_zap_cache(inode); |
| 5180 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5181 | return ret; |
| 5182 | } |
| 5183 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5184 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5185 | { |
| 5186 | struct nfs4_exception exception = { }; |
| 5187 | int err; |
| 5188 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5189 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5190 | trace_nfs4_set_acl(inode, err); |
| 5191 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5192 | &exception); |
| 5193 | } while (exception.retry); |
| 5194 | return err; |
| 5195 | } |
| 5196 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5197 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5198 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5199 | size_t buflen) |
| 5200 | { |
| 5201 | struct nfs_server *server = NFS_SERVER(inode); |
| 5202 | struct nfs_fattr fattr; |
| 5203 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5204 | |
| 5205 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5206 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5207 | .fh = NFS_FH(inode), |
| 5208 | .bitmask = bitmask, |
| 5209 | }; |
| 5210 | struct nfs4_getattr_res res = { |
| 5211 | .fattr = &fattr, |
| 5212 | .label = &label, |
| 5213 | .server = server, |
| 5214 | }; |
| 5215 | struct rpc_message msg = { |
| 5216 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5217 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5218 | .rpc_resp = &res, |
| 5219 | }; |
| 5220 | int ret; |
| 5221 | |
| 5222 | nfs_fattr_init(&fattr); |
| 5223 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5224 | 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] | 5225 | if (ret) |
| 5226 | return ret; |
| 5227 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5228 | return -ENOENT; |
| 5229 | if (buflen < label.len) |
| 5230 | return -ERANGE; |
| 5231 | return 0; |
| 5232 | } |
| 5233 | |
| 5234 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5235 | size_t buflen) |
| 5236 | { |
| 5237 | struct nfs4_exception exception = { }; |
| 5238 | int err; |
| 5239 | |
| 5240 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5241 | return -EOPNOTSUPP; |
| 5242 | |
| 5243 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5244 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5245 | trace_nfs4_get_security_label(inode, err); |
| 5246 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5247 | &exception); |
| 5248 | } while (exception.retry); |
| 5249 | return err; |
| 5250 | } |
| 5251 | |
| 5252 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5253 | struct nfs4_label *ilabel, |
| 5254 | struct nfs_fattr *fattr, |
| 5255 | struct nfs4_label *olabel) |
| 5256 | { |
| 5257 | |
| 5258 | struct iattr sattr = {0}; |
| 5259 | struct nfs_server *server = NFS_SERVER(inode); |
| 5260 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5261 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5262 | .fh = NFS_FH(inode), |
| 5263 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5264 | .server = server, |
| 5265 | .bitmask = bitmask, |
| 5266 | .label = ilabel, |
| 5267 | }; |
| 5268 | struct nfs_setattrres res = { |
| 5269 | .fattr = fattr, |
| 5270 | .label = olabel, |
| 5271 | .server = server, |
| 5272 | }; |
| 5273 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5274 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5275 | .rpc_argp = &arg, |
| 5276 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5277 | }; |
| 5278 | int status; |
| 5279 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5280 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5281 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5282 | 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] | 5283 | if (status) |
| 5284 | dprintk("%s failed: %d\n", __func__, status); |
| 5285 | |
| 5286 | return status; |
| 5287 | } |
| 5288 | |
| 5289 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5290 | struct nfs4_label *ilabel, |
| 5291 | struct nfs_fattr *fattr, |
| 5292 | struct nfs4_label *olabel) |
| 5293 | { |
| 5294 | struct nfs4_exception exception = { }; |
| 5295 | int err; |
| 5296 | |
| 5297 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5298 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5299 | fattr, olabel); |
| 5300 | trace_nfs4_set_security_label(inode, err); |
| 5301 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5302 | &exception); |
| 5303 | } while (exception.retry); |
| 5304 | return err; |
| 5305 | } |
| 5306 | |
| 5307 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5308 | 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] | 5309 | { |
| 5310 | struct nfs4_label ilabel, *olabel = NULL; |
| 5311 | struct nfs_fattr fattr; |
| 5312 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5313 | int status; |
| 5314 | |
| 5315 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5316 | return -EOPNOTSUPP; |
| 5317 | |
| 5318 | nfs_fattr_init(&fattr); |
| 5319 | |
| 5320 | ilabel.pi = 0; |
| 5321 | ilabel.lfs = 0; |
| 5322 | ilabel.label = (char *)buf; |
| 5323 | ilabel.len = buflen; |
| 5324 | |
| 5325 | cred = rpc_lookup_cred(); |
| 5326 | if (IS_ERR(cred)) |
| 5327 | return PTR_ERR(cred); |
| 5328 | |
| 5329 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5330 | if (IS_ERR(olabel)) { |
| 5331 | status = -PTR_ERR(olabel); |
| 5332 | goto out; |
| 5333 | } |
| 5334 | |
| 5335 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5336 | if (status == 0) |
| 5337 | nfs_setsecurity(inode, &fattr, olabel); |
| 5338 | |
| 5339 | nfs4_label_free(olabel); |
| 5340 | out: |
| 5341 | put_rpccred(cred); |
| 5342 | return status; |
| 5343 | } |
| 5344 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5345 | |
| 5346 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5347 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5348 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5349 | { |
| 5350 | __be32 verf[2]; |
| 5351 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5352 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5353 | /* An impossible timestamp guarantees this value |
| 5354 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5355 | verf[0] = cpu_to_be32(U32_MAX); |
| 5356 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5357 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5358 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5359 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5360 | |
| 5361 | verf[0] = cpu_to_be32(ns >> 32); |
| 5362 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5363 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5364 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5365 | } |
| 5366 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5367 | static int |
| 5368 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5369 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5370 | size_t len; |
| 5371 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5372 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5373 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5374 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5375 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5376 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5377 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5378 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5379 | 1 + |
| 5380 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5381 | 1; |
| 5382 | rcu_read_unlock(); |
| 5383 | |
| 5384 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5385 | return -EINVAL; |
| 5386 | |
| 5387 | /* |
| 5388 | * Since this string is allocated at mount time, and held until the |
| 5389 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5390 | * about a memory-reclaim deadlock. |
| 5391 | */ |
| 5392 | str = kmalloc(len, GFP_KERNEL); |
| 5393 | if (!str) |
| 5394 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5395 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5396 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5397 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5398 | clp->cl_ipaddr, |
| 5399 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5400 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5401 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5402 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5403 | clp->cl_owner_id = str; |
| 5404 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5405 | } |
| 5406 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5407 | static int |
| 5408 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5409 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5410 | size_t len; |
| 5411 | char *str; |
| 5412 | |
| 5413 | len = 10 + 10 + 1 + 10 + 1 + |
| 5414 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5415 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5416 | |
| 5417 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5418 | return -EINVAL; |
| 5419 | |
| 5420 | /* |
| 5421 | * Since this string is allocated at mount time, and held until the |
| 5422 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5423 | * about a memory-reclaim deadlock. |
| 5424 | */ |
| 5425 | str = kmalloc(len, GFP_KERNEL); |
| 5426 | if (!str) |
| 5427 | return -ENOMEM; |
| 5428 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5429 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5430 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5431 | nfs4_client_id_uniquifier, |
| 5432 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5433 | clp->cl_owner_id = str; |
| 5434 | return 0; |
| 5435 | } |
| 5436 | |
| 5437 | static int |
| 5438 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5439 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5440 | size_t len; |
| 5441 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5442 | |
| 5443 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5444 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5445 | |
| 5446 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5447 | return nfs4_init_uniquifier_client_string(clp); |
| 5448 | |
| 5449 | len = 10 + 10 + 1 + 10 + 1 + |
| 5450 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5451 | |
| 5452 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5453 | return -EINVAL; |
| 5454 | |
| 5455 | /* |
| 5456 | * Since this string is allocated at mount time, and held until the |
| 5457 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5458 | * about a memory-reclaim deadlock. |
| 5459 | */ |
| 5460 | str = kmalloc(len, GFP_KERNEL); |
| 5461 | if (!str) |
| 5462 | return -ENOMEM; |
| 5463 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5464 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5465 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5466 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5467 | clp->cl_owner_id = str; |
| 5468 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5469 | } |
| 5470 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5471 | /* |
| 5472 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5473 | * services. Advertise one based on the address family of the |
| 5474 | * clientaddr. |
| 5475 | */ |
| 5476 | static unsigned int |
| 5477 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5478 | { |
| 5479 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5480 | return scnprintf(buf, len, "tcp6"); |
| 5481 | else |
| 5482 | return scnprintf(buf, len, "tcp"); |
| 5483 | } |
| 5484 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5485 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5486 | { |
| 5487 | struct nfs4_setclientid *sc = calldata; |
| 5488 | |
| 5489 | if (task->tk_status == 0) |
| 5490 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5491 | } |
| 5492 | |
| 5493 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5494 | .rpc_call_done = nfs4_setclientid_done, |
| 5495 | }; |
| 5496 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5497 | /** |
| 5498 | * nfs4_proc_setclientid - Negotiate client ID |
| 5499 | * @clp: state data structure |
| 5500 | * @program: RPC program for NFSv4 callback service |
| 5501 | * @port: IP port number for NFS4 callback service |
| 5502 | * @cred: RPC credential to use for this call |
| 5503 | * @res: where to place the result |
| 5504 | * |
| 5505 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5506 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5507 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5508 | unsigned short port, struct rpc_cred *cred, |
| 5509 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | { |
| 5511 | nfs4_verifier sc_verifier; |
| 5512 | struct nfs4_setclientid setclientid = { |
| 5513 | .sc_verifier = &sc_verifier, |
| 5514 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5515 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | }; |
| 5517 | struct rpc_message msg = { |
| 5518 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5519 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5520 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5521 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5523 | struct rpc_task *task; |
| 5524 | struct rpc_task_setup task_setup_data = { |
| 5525 | .rpc_client = clp->cl_rpcclient, |
| 5526 | .rpc_message = &msg, |
| 5527 | .callback_ops = &nfs4_setclientid_ops, |
| 5528 | .callback_data = &setclientid, |
| 5529 | .flags = RPC_TASK_TIMEOUT, |
| 5530 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5531 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5533 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5534 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5535 | |
| 5536 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5537 | status = nfs4_init_uniform_client_string(clp); |
| 5538 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5539 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5540 | |
| 5541 | if (status) |
| 5542 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5543 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5544 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5545 | setclientid.sc_netid_len = |
| 5546 | nfs4_init_callback_netid(clp, |
| 5547 | setclientid.sc_netid, |
| 5548 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5549 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5550 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5551 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5552 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5553 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5554 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5555 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5556 | task = rpc_run_task(&task_setup_data); |
| 5557 | if (IS_ERR(task)) { |
| 5558 | status = PTR_ERR(task); |
| 5559 | goto out; |
| 5560 | } |
| 5561 | status = task->tk_status; |
| 5562 | if (setclientid.sc_cred) { |
| 5563 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5564 | put_rpccred(setclientid.sc_cred); |
| 5565 | } |
| 5566 | rpc_put_task(task); |
| 5567 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5568 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5569 | dprintk("NFS reply setclientid: %d\n", status); |
| 5570 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | } |
| 5572 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5573 | /** |
| 5574 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5575 | * @clp: state data structure |
| 5576 | * @res: result of a previous SETCLIENTID |
| 5577 | * @cred: RPC credential to use for this call |
| 5578 | * |
| 5579 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5580 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5581 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5582 | struct nfs4_setclientid_res *arg, |
| 5583 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5585 | struct rpc_message msg = { |
| 5586 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5587 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5588 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5589 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | int status; |
| 5591 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5592 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5593 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5594 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5595 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5596 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5597 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | return status; |
| 5599 | } |
| 5600 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5601 | struct nfs4_delegreturndata { |
| 5602 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5603 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5604 | struct nfs_fh fh; |
| 5605 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5606 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5607 | struct { |
| 5608 | struct nfs4_layoutreturn_args arg; |
| 5609 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5610 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5611 | u32 roc_barrier; |
| 5612 | bool roc; |
| 5613 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5614 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5615 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5616 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5617 | }; |
| 5618 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5619 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5620 | { |
| 5621 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5622 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5623 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5624 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5625 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5626 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5627 | |
| 5628 | /* Handle Layoutreturn errors */ |
| 5629 | if (data->args.lr_args && task->tk_status != 0) { |
| 5630 | switch(data->res.lr_ret) { |
| 5631 | default: |
| 5632 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5633 | break; |
| 5634 | case 0: |
| 5635 | data->args.lr_args = NULL; |
| 5636 | data->res.lr_res = NULL; |
| 5637 | break; |
| 5638 | case -NFS4ERR_ADMIN_REVOKED: |
| 5639 | case -NFS4ERR_DELEG_REVOKED: |
| 5640 | case -NFS4ERR_EXPIRED: |
| 5641 | case -NFS4ERR_BAD_STATEID: |
| 5642 | case -NFS4ERR_OLD_STATEID: |
| 5643 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5644 | case -NFS4ERR_WRONG_CRED: |
| 5645 | data->args.lr_args = NULL; |
| 5646 | data->res.lr_res = NULL; |
| 5647 | data->res.lr_ret = 0; |
| 5648 | rpc_restart_call_prepare(task); |
| 5649 | return; |
| 5650 | } |
| 5651 | } |
| 5652 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5653 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5654 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5655 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5656 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5657 | case -NFS4ERR_ADMIN_REVOKED: |
| 5658 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5659 | case -NFS4ERR_EXPIRED: |
| 5660 | nfs4_free_revoked_stateid(data->res.server, |
| 5661 | data->args.stateid, |
| 5662 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5663 | case -NFS4ERR_BAD_STATEID: |
| 5664 | case -NFS4ERR_OLD_STATEID: |
| 5665 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5666 | task->tk_status = 0; |
| 5667 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5668 | case -NFS4ERR_ACCESS: |
| 5669 | if (data->args.bitmask) { |
| 5670 | data->args.bitmask = NULL; |
| 5671 | data->res.fattr = NULL; |
| 5672 | task->tk_status = 0; |
| 5673 | rpc_restart_call_prepare(task); |
| 5674 | return; |
| 5675 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5676 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5677 | if (nfs4_async_handle_error(task, data->res.server, |
| 5678 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5679 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5680 | return; |
| 5681 | } |
| 5682 | } |
| 5683 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | static void nfs4_delegreturn_release(void *calldata) |
| 5687 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5688 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5689 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5690 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5691 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5692 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5693 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5694 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5695 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5696 | nfs_iput_and_deactive(inode); |
| 5697 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5698 | kfree(calldata); |
| 5699 | } |
| 5700 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5701 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5702 | { |
| 5703 | struct nfs4_delegreturndata *d_data; |
| 5704 | |
| 5705 | d_data = (struct nfs4_delegreturndata *)data; |
| 5706 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5707 | 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] | 5708 | return; |
| 5709 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5710 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5711 | &d_data->args.seq_args, |
| 5712 | &d_data->res.seq_res, |
| 5713 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5714 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5715 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5716 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5717 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5718 | .rpc_call_done = nfs4_delegreturn_done, |
| 5719 | .rpc_release = nfs4_delegreturn_release, |
| 5720 | }; |
| 5721 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5722 | 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] | 5723 | { |
| 5724 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5725 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5726 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5727 | struct rpc_message msg = { |
| 5728 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5729 | .rpc_cred = cred, |
| 5730 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5731 | struct rpc_task_setup task_setup_data = { |
| 5732 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5733 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5734 | .callback_ops = &nfs4_delegreturn_ops, |
| 5735 | .flags = RPC_TASK_ASYNC, |
| 5736 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5737 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5738 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5739 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5740 | if (data == NULL) |
| 5741 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5742 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5743 | |
| 5744 | nfs4_state_protect(server->nfs_client, |
| 5745 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5746 | &task_setup_data.rpc_client, &msg); |
| 5747 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5748 | data->args.fhandle = &data->fh; |
| 5749 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5750 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5751 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5752 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5753 | data->res.fattr = &data->fattr; |
| 5754 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5755 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5756 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5757 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5758 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5759 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5760 | 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] | 5761 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5762 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5763 | if (data->lr.roc) { |
| 5764 | data->args.lr_args = &data->lr.arg; |
| 5765 | data->res.lr_res = &data->lr.res; |
| 5766 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5767 | } else if (data->lr.roc) { |
| 5768 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5769 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5770 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5771 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5772 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5773 | msg.rpc_argp = &data->args; |
| 5774 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5775 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5776 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5777 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5778 | if (!issync) |
| 5779 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5780 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5781 | if (status != 0) |
| 5782 | goto out; |
| 5783 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5784 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5785 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5786 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5787 | } |
| 5788 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5789 | 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] | 5790 | { |
| 5791 | struct nfs_server *server = NFS_SERVER(inode); |
| 5792 | struct nfs4_exception exception = { }; |
| 5793 | int err; |
| 5794 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5795 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5796 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5797 | switch (err) { |
| 5798 | case -NFS4ERR_STALE_STATEID: |
| 5799 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | case 0: |
| 5801 | return 0; |
| 5802 | } |
| 5803 | err = nfs4_handle_exception(server, err, &exception); |
| 5804 | } while (exception.retry); |
| 5805 | return err; |
| 5806 | } |
| 5807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5809 | { |
| 5810 | struct inode *inode = state->inode; |
| 5811 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5812 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5813 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5814 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5815 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5816 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5817 | struct nfs_lockt_res res = { |
| 5818 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | }; |
| 5820 | struct rpc_message msg = { |
| 5821 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5822 | .rpc_argp = &arg, |
| 5823 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5824 | .rpc_cred = state->owner->so_cred, |
| 5825 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | struct nfs4_lock_state *lsp; |
| 5827 | int status; |
| 5828 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5829 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5830 | status = nfs4_set_lock_state(state, request); |
| 5831 | if (status != 0) |
| 5832 | goto out; |
| 5833 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5834 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5835 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5836 | 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] | 5837 | switch (status) { |
| 5838 | case 0: |
| 5839 | request->fl_type = F_UNLCK; |
| 5840 | break; |
| 5841 | case -NFS4ERR_DENIED: |
| 5842 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5843 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5844 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5845 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5846 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | return status; |
| 5848 | } |
| 5849 | |
| 5850 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5851 | { |
| 5852 | struct nfs4_exception exception = { }; |
| 5853 | int err; |
| 5854 | |
| 5855 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5856 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5857 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5858 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | &exception); |
| 5860 | } while (exception.retry); |
| 5861 | return err; |
| 5862 | } |
| 5863 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5864 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5865 | struct nfs_locku_args arg; |
| 5866 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5867 | struct nfs4_lock_state *lsp; |
| 5868 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5869 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5870 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5871 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5872 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5873 | }; |
| 5874 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5875 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5876 | struct nfs_open_context *ctx, |
| 5877 | struct nfs4_lock_state *lsp, |
| 5878 | struct nfs_seqid *seqid) |
| 5879 | { |
| 5880 | struct nfs4_unlockdata *p; |
| 5881 | struct inode *inode = lsp->ls_state->inode; |
| 5882 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5883 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5884 | if (p == NULL) |
| 5885 | return NULL; |
| 5886 | p->arg.fh = NFS_FH(inode); |
| 5887 | p->arg.fl = &p->fl; |
| 5888 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5889 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5890 | p->lsp = lsp; |
| 5891 | atomic_inc(&lsp->ls_count); |
| 5892 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5893 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5894 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5895 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5896 | p->server = NFS_SERVER(inode); |
| 5897 | return p; |
| 5898 | } |
| 5899 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5900 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5901 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5902 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5903 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5904 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5905 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5906 | put_nfs_open_context(calldata->ctx); |
| 5907 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5910 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5911 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5912 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5913 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5914 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5915 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5916 | switch (task->tk_status) { |
| 5917 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5918 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5919 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5920 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5921 | &calldata->res.stateid)) |
| 5922 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5923 | case -NFS4ERR_ADMIN_REVOKED: |
| 5924 | case -NFS4ERR_EXPIRED: |
| 5925 | nfs4_free_revoked_stateid(calldata->server, |
| 5926 | &calldata->arg.stateid, |
| 5927 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5928 | case -NFS4ERR_BAD_STATEID: |
| 5929 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5930 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5931 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5932 | &calldata->lsp->ls_stateid)) |
| 5933 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5934 | break; |
| 5935 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5936 | if (nfs4_async_handle_error(task, calldata->server, |
| 5937 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5938 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5939 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5940 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5943 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5944 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5945 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5946 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5947 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 5948 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 5949 | return; |
| 5950 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5951 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5952 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5953 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5954 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5955 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5956 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5957 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5958 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5959 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5960 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5961 | &calldata->res.seq_res, |
| 5962 | task) != 0) |
| 5963 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5964 | return; |
| 5965 | out_no_action: |
| 5966 | task->tk_action = NULL; |
| 5967 | out_wait: |
| 5968 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5971 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5972 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5973 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5974 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5975 | }; |
| 5976 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5977 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5978 | struct nfs_open_context *ctx, |
| 5979 | struct nfs4_lock_state *lsp, |
| 5980 | struct nfs_seqid *seqid) |
| 5981 | { |
| 5982 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5983 | struct rpc_message msg = { |
| 5984 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5985 | .rpc_cred = ctx->cred, |
| 5986 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5987 | struct rpc_task_setup task_setup_data = { |
| 5988 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5989 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5990 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5991 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5992 | .flags = RPC_TASK_ASYNC, |
| 5993 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5994 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5995 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5996 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5997 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5998 | /* Ensure this is an unlock - when canceling a lock, the |
| 5999 | * canceled lock is passed in, and it won't be an unlock. |
| 6000 | */ |
| 6001 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6002 | if (fl->fl_flags & FL_CLOSE) |
| 6003 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6004 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6005 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6006 | if (data == NULL) { |
| 6007 | nfs_free_seqid(seqid); |
| 6008 | return ERR_PTR(-ENOMEM); |
| 6009 | } |
| 6010 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6011 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6012 | msg.rpc_argp = &data->arg; |
| 6013 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6014 | task_setup_data.callback_data = data; |
| 6015 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6016 | } |
| 6017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6018 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6019 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6020 | struct inode *inode = state->inode; |
| 6021 | struct nfs4_state_owner *sp = state->owner; |
| 6022 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6023 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6024 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6025 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6026 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6027 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6028 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6030 | status = nfs4_set_lock_state(state, request); |
| 6031 | /* Unlock _before_ we do the RPC call */ |
| 6032 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6033 | /* Exclude nfs_delegation_claim_locks() */ |
| 6034 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6035 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6036 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6037 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6038 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6039 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6040 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6041 | } |
| 6042 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6043 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6044 | if (status != 0) |
| 6045 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6046 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6047 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6048 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6049 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6050 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6051 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6052 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6053 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6054 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6055 | 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] | 6056 | status = PTR_ERR(task); |
| 6057 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6058 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6059 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6060 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6061 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6062 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6063 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6064 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6065 | } |
| 6066 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6067 | struct nfs4_lockdata { |
| 6068 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6069 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6070 | struct nfs4_lock_state *lsp; |
| 6071 | struct nfs_open_context *ctx; |
| 6072 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6073 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6074 | int rpc_status; |
| 6075 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6076 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6077 | }; |
| 6078 | |
| 6079 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6080 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6081 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6082 | { |
| 6083 | struct nfs4_lockdata *p; |
| 6084 | struct inode *inode = lsp->ls_state->inode; |
| 6085 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6086 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6087 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6088 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6089 | if (p == NULL) |
| 6090 | return NULL; |
| 6091 | |
| 6092 | p->arg.fh = NFS_FH(inode); |
| 6093 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6094 | 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] | 6095 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6096 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6097 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6098 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6099 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6100 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6101 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6102 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6103 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6104 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6105 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6106 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6107 | atomic_inc(&lsp->ls_count); |
| 6108 | p->ctx = get_nfs_open_context(ctx); |
| 6109 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6110 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6111 | out_free_seqid: |
| 6112 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6113 | out_free: |
| 6114 | kfree(p); |
| 6115 | return NULL; |
| 6116 | } |
| 6117 | |
| 6118 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6119 | { |
| 6120 | struct nfs4_lockdata *data = calldata; |
| 6121 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6122 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6123 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6124 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6125 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6126 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6127 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6128 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6129 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6130 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6131 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6132 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6133 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6134 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6135 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6136 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6137 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6138 | &data->lsp->ls_stateid); |
| 6139 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6140 | if (!nfs4_valid_open_stateid(state)) { |
| 6141 | data->rpc_status = -EBADF; |
| 6142 | task->tk_action = NULL; |
| 6143 | goto out_release_open_seqid; |
| 6144 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6145 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6146 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6147 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6148 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6149 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6150 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6151 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6152 | nfs_release_seqid(data->arg.open_seqid); |
| 6153 | out_release_lock_seqid: |
| 6154 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6155 | out_wait: |
| 6156 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6157 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6158 | } |
| 6159 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6160 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6161 | { |
| 6162 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6163 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6164 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6165 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6166 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6167 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6168 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6169 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6170 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6171 | switch (task->tk_status) { |
| 6172 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6173 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6174 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6175 | if (data->arg.new_lock) { |
| 6176 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6177 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6178 | rpc_restart_call_prepare(task); |
| 6179 | break; |
| 6180 | } |
| 6181 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6182 | if (data->arg.new_lock_owner != 0) { |
| 6183 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6184 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6185 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6186 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6187 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6188 | break; |
| 6189 | case -NFS4ERR_BAD_STATEID: |
| 6190 | case -NFS4ERR_OLD_STATEID: |
| 6191 | case -NFS4ERR_STALE_STATEID: |
| 6192 | case -NFS4ERR_EXPIRED: |
| 6193 | if (data->arg.new_lock_owner != 0) { |
| 6194 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6195 | &lsp->ls_state->open_stateid)) |
| 6196 | rpc_restart_call_prepare(task); |
| 6197 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6198 | &lsp->ls_stateid)) |
| 6199 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6200 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6201 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | static void nfs4_lock_release(void *calldata) |
| 6205 | { |
| 6206 | struct nfs4_lockdata *data = calldata; |
| 6207 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6208 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6209 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6210 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6211 | struct rpc_task *task; |
| 6212 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6213 | data->arg.lock_seqid); |
| 6214 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6215 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6216 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6217 | } else |
| 6218 | nfs_free_seqid(data->arg.lock_seqid); |
| 6219 | nfs4_put_lock_state(data->lsp); |
| 6220 | put_nfs_open_context(data->ctx); |
| 6221 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6222 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6226 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6227 | .rpc_call_done = nfs4_lock_done, |
| 6228 | .rpc_release = nfs4_lock_release, |
| 6229 | }; |
| 6230 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6231 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6232 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6233 | switch (error) { |
| 6234 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6235 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6236 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6237 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6238 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6239 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6240 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6241 | break; |
| 6242 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6243 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6244 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6245 | }; |
| 6246 | } |
| 6247 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6248 | 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] | 6249 | { |
| 6250 | struct nfs4_lockdata *data; |
| 6251 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6252 | struct rpc_message msg = { |
| 6253 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6254 | .rpc_cred = state->owner->so_cred, |
| 6255 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6256 | struct rpc_task_setup task_setup_data = { |
| 6257 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6258 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6259 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6260 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6261 | .flags = RPC_TASK_ASYNC, |
| 6262 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6263 | int ret; |
| 6264 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6265 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6266 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6267 | fl->fl_u.nfs4_fl.owner, |
| 6268 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6269 | if (data == NULL) |
| 6270 | return -ENOMEM; |
| 6271 | if (IS_SETLKW(cmd)) |
| 6272 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6273 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6274 | msg.rpc_argp = &data->arg; |
| 6275 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6276 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6277 | if (recovery_type > NFS_LOCK_NEW) { |
| 6278 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6279 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6280 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6281 | } else |
| 6282 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6283 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6284 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6285 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6286 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6287 | if (ret == 0) { |
| 6288 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6289 | if (ret) |
| 6290 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6291 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6292 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6293 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6294 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6295 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6296 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6297 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6301 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6302 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6303 | struct nfs4_exception exception = { |
| 6304 | .inode = state->inode, |
| 6305 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6306 | int err; |
| 6307 | |
| 6308 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6309 | /* Cache the lock if possible... */ |
| 6310 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6311 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6312 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6313 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6314 | break; |
| 6315 | nfs4_handle_exception(server, err, &exception); |
| 6316 | } while (exception.retry); |
| 6317 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6321 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6322 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6323 | struct nfs4_exception exception = { |
| 6324 | .inode = state->inode, |
| 6325 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6326 | int err; |
| 6327 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6328 | err = nfs4_set_lock_state(state, request); |
| 6329 | if (err != 0) |
| 6330 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6331 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6332 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6333 | return 0; |
| 6334 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6335 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6336 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6337 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6338 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6339 | switch (err) { |
| 6340 | default: |
| 6341 | goto out; |
| 6342 | case -NFS4ERR_GRACE: |
| 6343 | case -NFS4ERR_DELAY: |
| 6344 | nfs4_handle_exception(server, err, &exception); |
| 6345 | err = 0; |
| 6346 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6347 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6348 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6349 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6350 | } |
| 6351 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6352 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6353 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6354 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6355 | struct nfs4_lock_state *lsp; |
| 6356 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6357 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6358 | status = nfs4_set_lock_state(state, request); |
| 6359 | if (status != 0) |
| 6360 | return status; |
| 6361 | lsp = request->fl_u.nfs4_fl.owner; |
| 6362 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6363 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6364 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6365 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6366 | } |
| 6367 | #endif |
| 6368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6369 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6370 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6371 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6372 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6373 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6374 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6375 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6376 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6377 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6378 | if (status < 0) |
| 6379 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6380 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6381 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6382 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6383 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6384 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6385 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6386 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6387 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6388 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6389 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6390 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6391 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6392 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6393 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6394 | out: |
| 6395 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6396 | return status; |
| 6397 | } |
| 6398 | |
| 6399 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6400 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6401 | struct nfs4_exception exception = { |
| 6402 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6403 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6404 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6405 | int err; |
| 6406 | |
| 6407 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6408 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6409 | if (err == -NFS4ERR_DENIED) |
| 6410 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6411 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6412 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | } while (exception.retry); |
| 6414 | return err; |
| 6415 | } |
| 6416 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6417 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6418 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6419 | |
| 6420 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6421 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6422 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6423 | { |
| 6424 | int status = -ERESTARTSYS; |
| 6425 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6426 | |
| 6427 | while(!signalled()) { |
| 6428 | status = nfs4_proc_setlk(state, cmd, request); |
| 6429 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6430 | break; |
| 6431 | freezable_schedule_timeout_interruptible(timeout); |
| 6432 | timeout *= 2; |
| 6433 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6434 | status = -ERESTARTSYS; |
| 6435 | } |
| 6436 | return status; |
| 6437 | } |
| 6438 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6439 | #ifdef CONFIG_NFS_V4_1 |
| 6440 | struct nfs4_lock_waiter { |
| 6441 | struct task_struct *task; |
| 6442 | struct inode *inode; |
| 6443 | struct nfs_lowner *owner; |
| 6444 | bool notified; |
| 6445 | }; |
| 6446 | |
| 6447 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6448 | 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] | 6449 | { |
| 6450 | int ret; |
| 6451 | struct cb_notify_lock_args *cbnl = key; |
| 6452 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6453 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6454 | *wowner = waiter->owner; |
| 6455 | |
| 6456 | /* Only wake if the callback was for the same owner */ |
| 6457 | if (lowner->clientid != wowner->clientid || |
| 6458 | lowner->id != wowner->id || |
| 6459 | lowner->s_dev != wowner->s_dev) |
| 6460 | return 0; |
| 6461 | |
| 6462 | /* Make sure it's for the right inode */ |
| 6463 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6464 | return 0; |
| 6465 | |
| 6466 | waiter->notified = true; |
| 6467 | |
| 6468 | /* override "private" so we can use default_wake_function */ |
| 6469 | wait->private = waiter->task; |
| 6470 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6471 | wait->private = waiter; |
| 6472 | return ret; |
| 6473 | } |
| 6474 | |
| 6475 | static int |
| 6476 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6477 | { |
| 6478 | int status = -ERESTARTSYS; |
| 6479 | unsigned long flags; |
| 6480 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6481 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6482 | struct nfs_client *clp = server->nfs_client; |
| 6483 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6484 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6485 | .id = lsp->ls_seqid.owner_id, |
| 6486 | .s_dev = server->s_dev }; |
| 6487 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6488 | .inode = state->inode, |
| 6489 | .owner = &owner, |
| 6490 | .notified = false }; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6491 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6492 | |
| 6493 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6494 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6495 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6496 | |
| 6497 | init_wait(&wait); |
| 6498 | wait.private = &waiter; |
| 6499 | wait.func = nfs4_wake_lock_waiter; |
| 6500 | add_wait_queue(q, &wait); |
| 6501 | |
| 6502 | while(!signalled()) { |
| 6503 | status = nfs4_proc_setlk(state, cmd, request); |
| 6504 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6505 | break; |
| 6506 | |
| 6507 | status = -ERESTARTSYS; |
| 6508 | spin_lock_irqsave(&q->lock, flags); |
| 6509 | if (waiter.notified) { |
| 6510 | spin_unlock_irqrestore(&q->lock, flags); |
| 6511 | continue; |
| 6512 | } |
| 6513 | set_current_state(TASK_INTERRUPTIBLE); |
| 6514 | spin_unlock_irqrestore(&q->lock, flags); |
| 6515 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6516 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | finish_wait(q, &wait); |
| 6520 | return status; |
| 6521 | } |
| 6522 | #else /* !CONFIG_NFS_V4_1 */ |
| 6523 | static inline int |
| 6524 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6525 | { |
| 6526 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6527 | } |
| 6528 | #endif |
| 6529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6530 | static int |
| 6531 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6532 | { |
| 6533 | struct nfs_open_context *ctx; |
| 6534 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6535 | int status; |
| 6536 | |
| 6537 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6538 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6539 | state = ctx->state; |
| 6540 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6541 | if (IS_GETLK(cmd)) { |
| 6542 | if (state != NULL) |
| 6543 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6544 | return 0; |
| 6545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6546 | |
| 6547 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6548 | return -EINVAL; |
| 6549 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6550 | if (request->fl_type == F_UNLCK) { |
| 6551 | if (state != NULL) |
| 6552 | return nfs4_proc_unlck(state, cmd, request); |
| 6553 | return 0; |
| 6554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6555 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6556 | if (state == NULL) |
| 6557 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6558 | |
| 6559 | if ((request->fl_flags & FL_POSIX) && |
| 6560 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6561 | return -ENOLCK; |
| 6562 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6563 | status = nfs4_set_lock_state(state, request); |
| 6564 | if (status != 0) |
| 6565 | return status; |
| 6566 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6567 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6568 | } |
| 6569 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6570 | 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] | 6571 | { |
| 6572 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6573 | int err; |
| 6574 | |
| 6575 | err = nfs4_set_lock_state(state, fl); |
| 6576 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6577 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6578 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6579 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6580 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6581 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6582 | struct nfs_release_lockowner_data { |
| 6583 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6584 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6585 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6586 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6587 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6588 | }; |
| 6589 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6590 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6591 | { |
| 6592 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6593 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6594 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6595 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6596 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6597 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6601 | { |
| 6602 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6603 | struct nfs_server *server = data->server; |
| 6604 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6605 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6606 | |
| 6607 | switch (task->tk_status) { |
| 6608 | case 0: |
| 6609 | renew_lease(server, data->timestamp); |
| 6610 | break; |
| 6611 | case -NFS4ERR_STALE_CLIENTID: |
| 6612 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6613 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6614 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6615 | case -NFS4ERR_LEASE_MOVED: |
| 6616 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6617 | if (nfs4_async_handle_error(task, server, |
| 6618 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6619 | rpc_restart_call_prepare(task); |
| 6620 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6621 | } |
| 6622 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6623 | static void nfs4_release_lockowner_release(void *calldata) |
| 6624 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6625 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6626 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6627 | kfree(calldata); |
| 6628 | } |
| 6629 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6630 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6631 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6632 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6633 | .rpc_release = nfs4_release_lockowner_release, |
| 6634 | }; |
| 6635 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6636 | static void |
| 6637 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6638 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6639 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6640 | struct rpc_message msg = { |
| 6641 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6642 | }; |
| 6643 | |
| 6644 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6645 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6646 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6647 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6648 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6649 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6650 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6651 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6652 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6653 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6654 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6655 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6656 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6657 | msg.rpc_resp = &data->res; |
| 6658 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6659 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6660 | } |
| 6661 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6662 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6663 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6664 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6665 | struct dentry *unused, struct inode *inode, |
| 6666 | const char *key, const void *buf, |
| 6667 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6668 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6669 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6670 | } |
| 6671 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6672 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6673 | struct dentry *unused, struct inode *inode, |
| 6674 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6675 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6676 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6677 | } |
| 6678 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6679 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6680 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6681 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6682 | } |
| 6683 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6684 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6685 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6686 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6687 | struct dentry *unused, struct inode *inode, |
| 6688 | const char *key, const void *buf, |
| 6689 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6690 | { |
| 6691 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6692 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6693 | |
| 6694 | return -EOPNOTSUPP; |
| 6695 | } |
| 6696 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6697 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6698 | struct dentry *unused, struct inode *inode, |
| 6699 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6700 | { |
| 6701 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6702 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6703 | return -EOPNOTSUPP; |
| 6704 | } |
| 6705 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6706 | static ssize_t |
| 6707 | 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] | 6708 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6709 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6710 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6711 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6712 | len = security_inode_listsecurity(inode, list, list_len); |
| 6713 | if (list_len && len > list_len) |
| 6714 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6715 | } |
| 6716 | return len; |
| 6717 | } |
| 6718 | |
| 6719 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6720 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6721 | .get = nfs4_xattr_get_nfs4_label, |
| 6722 | .set = nfs4_xattr_set_nfs4_label, |
| 6723 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6724 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6725 | #else |
| 6726 | |
| 6727 | static ssize_t |
| 6728 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6729 | { |
| 6730 | return 0; |
| 6731 | } |
| 6732 | |
| 6733 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6734 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6735 | /* |
| 6736 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6737 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6738 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6739 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6740 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6741 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6742 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6743 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6744 | return; |
| 6745 | |
| 6746 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6747 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6748 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6749 | fattr->nlink = 2; |
| 6750 | } |
| 6751 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6752 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6753 | const struct qstr *name, |
| 6754 | struct nfs4_fs_locations *fs_locations, |
| 6755 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6756 | { |
| 6757 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6758 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6759 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6760 | }; |
| 6761 | struct nfs4_fs_locations_arg args = { |
| 6762 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6763 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6764 | .page = page, |
| 6765 | .bitmask = bitmask, |
| 6766 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6767 | struct nfs4_fs_locations_res res = { |
| 6768 | .fs_locations = fs_locations, |
| 6769 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6770 | struct rpc_message msg = { |
| 6771 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6772 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6773 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6774 | }; |
| 6775 | int status; |
| 6776 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6777 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6778 | |
| 6779 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6780 | * is not supported */ |
| 6781 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6782 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6783 | else |
| 6784 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6785 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6786 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6787 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6788 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6789 | 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] | 6790 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6791 | return status; |
| 6792 | } |
| 6793 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6794 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6795 | const struct qstr *name, |
| 6796 | struct nfs4_fs_locations *fs_locations, |
| 6797 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6798 | { |
| 6799 | struct nfs4_exception exception = { }; |
| 6800 | int err; |
| 6801 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6802 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6803 | fs_locations, page); |
| 6804 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6805 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6806 | &exception); |
| 6807 | } while (exception.retry); |
| 6808 | return err; |
| 6809 | } |
| 6810 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6811 | /* |
| 6812 | * This operation also signals the server that this client is |
| 6813 | * performing migration recovery. The server can stop returning |
| 6814 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6815 | * appended to this compound to identify the client ID which is |
| 6816 | * performing recovery. |
| 6817 | */ |
| 6818 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6819 | struct nfs4_fs_locations *locations, |
| 6820 | struct page *page, struct rpc_cred *cred) |
| 6821 | { |
| 6822 | struct nfs_server *server = NFS_SERVER(inode); |
| 6823 | struct rpc_clnt *clnt = server->client; |
| 6824 | u32 bitmask[2] = { |
| 6825 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6826 | }; |
| 6827 | struct nfs4_fs_locations_arg args = { |
| 6828 | .clientid = server->nfs_client->cl_clientid, |
| 6829 | .fh = NFS_FH(inode), |
| 6830 | .page = page, |
| 6831 | .bitmask = bitmask, |
| 6832 | .migration = 1, /* skip LOOKUP */ |
| 6833 | .renew = 1, /* append RENEW */ |
| 6834 | }; |
| 6835 | struct nfs4_fs_locations_res res = { |
| 6836 | .fs_locations = locations, |
| 6837 | .migration = 1, |
| 6838 | .renew = 1, |
| 6839 | }; |
| 6840 | struct rpc_message msg = { |
| 6841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6842 | .rpc_argp = &args, |
| 6843 | .rpc_resp = &res, |
| 6844 | .rpc_cred = cred, |
| 6845 | }; |
| 6846 | unsigned long now = jiffies; |
| 6847 | int status; |
| 6848 | |
| 6849 | nfs_fattr_init(&locations->fattr); |
| 6850 | locations->server = server; |
| 6851 | locations->nlocations = 0; |
| 6852 | |
| 6853 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6854 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6855 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6856 | &args.seq_args, &res.seq_res); |
| 6857 | if (status) |
| 6858 | return status; |
| 6859 | |
| 6860 | renew_lease(server, now); |
| 6861 | return 0; |
| 6862 | } |
| 6863 | |
| 6864 | #ifdef CONFIG_NFS_V4_1 |
| 6865 | |
| 6866 | /* |
| 6867 | * This operation also signals the server that this client is |
| 6868 | * performing migration recovery. The server can stop asserting |
| 6869 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6870 | * performing this operation is identified in the SEQUENCE |
| 6871 | * operation in this compound. |
| 6872 | * |
| 6873 | * When the client supports GETATTR(fs_locations_info), it can |
| 6874 | * be plumbed in here. |
| 6875 | */ |
| 6876 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6877 | struct nfs4_fs_locations *locations, |
| 6878 | struct page *page, struct rpc_cred *cred) |
| 6879 | { |
| 6880 | struct nfs_server *server = NFS_SERVER(inode); |
| 6881 | struct rpc_clnt *clnt = server->client; |
| 6882 | u32 bitmask[2] = { |
| 6883 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6884 | }; |
| 6885 | struct nfs4_fs_locations_arg args = { |
| 6886 | .fh = NFS_FH(inode), |
| 6887 | .page = page, |
| 6888 | .bitmask = bitmask, |
| 6889 | .migration = 1, /* skip LOOKUP */ |
| 6890 | }; |
| 6891 | struct nfs4_fs_locations_res res = { |
| 6892 | .fs_locations = locations, |
| 6893 | .migration = 1, |
| 6894 | }; |
| 6895 | struct rpc_message msg = { |
| 6896 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6897 | .rpc_argp = &args, |
| 6898 | .rpc_resp = &res, |
| 6899 | .rpc_cred = cred, |
| 6900 | }; |
| 6901 | int status; |
| 6902 | |
| 6903 | nfs_fattr_init(&locations->fattr); |
| 6904 | locations->server = server; |
| 6905 | locations->nlocations = 0; |
| 6906 | |
| 6907 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6908 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6909 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6910 | &args.seq_args, &res.seq_res); |
| 6911 | if (status == NFS4_OK && |
| 6912 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6913 | status = -NFS4ERR_LEASE_MOVED; |
| 6914 | return status; |
| 6915 | } |
| 6916 | |
| 6917 | #endif /* CONFIG_NFS_V4_1 */ |
| 6918 | |
| 6919 | /** |
| 6920 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6921 | * @inode: inode on FSID that is migrating |
| 6922 | * @locations: result of query |
| 6923 | * @page: buffer |
| 6924 | * @cred: credential to use for this operation |
| 6925 | * |
| 6926 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6927 | * operation failed, or a negative errno if a local error occurred. |
| 6928 | * |
| 6929 | * On success, "locations" is filled in, but if the server has |
| 6930 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6931 | * asserted. |
| 6932 | * |
| 6933 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6934 | * from this client that require migration recovery. |
| 6935 | */ |
| 6936 | int nfs4_proc_get_locations(struct inode *inode, |
| 6937 | struct nfs4_fs_locations *locations, |
| 6938 | struct page *page, struct rpc_cred *cred) |
| 6939 | { |
| 6940 | struct nfs_server *server = NFS_SERVER(inode); |
| 6941 | struct nfs_client *clp = server->nfs_client; |
| 6942 | const struct nfs4_mig_recovery_ops *ops = |
| 6943 | clp->cl_mvops->mig_recovery_ops; |
| 6944 | struct nfs4_exception exception = { }; |
| 6945 | int status; |
| 6946 | |
| 6947 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6948 | (unsigned long long)server->fsid.major, |
| 6949 | (unsigned long long)server->fsid.minor, |
| 6950 | clp->cl_hostname); |
| 6951 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6952 | |
| 6953 | do { |
| 6954 | status = ops->get_locations(inode, locations, page, cred); |
| 6955 | if (status != -NFS4ERR_DELAY) |
| 6956 | break; |
| 6957 | nfs4_handle_exception(server, status, &exception); |
| 6958 | } while (exception.retry); |
| 6959 | return status; |
| 6960 | } |
| 6961 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6962 | /* |
| 6963 | * This operation also signals the server that this client is |
| 6964 | * performing "lease moved" recovery. The server can stop |
| 6965 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6966 | * is appended to this compound to identify the client ID which is |
| 6967 | * performing recovery. |
| 6968 | */ |
| 6969 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6970 | { |
| 6971 | struct nfs_server *server = NFS_SERVER(inode); |
| 6972 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6973 | struct rpc_clnt *clnt = server->client; |
| 6974 | struct nfs4_fsid_present_arg args = { |
| 6975 | .fh = NFS_FH(inode), |
| 6976 | .clientid = clp->cl_clientid, |
| 6977 | .renew = 1, /* append RENEW */ |
| 6978 | }; |
| 6979 | struct nfs4_fsid_present_res res = { |
| 6980 | .renew = 1, |
| 6981 | }; |
| 6982 | struct rpc_message msg = { |
| 6983 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6984 | .rpc_argp = &args, |
| 6985 | .rpc_resp = &res, |
| 6986 | .rpc_cred = cred, |
| 6987 | }; |
| 6988 | unsigned long now = jiffies; |
| 6989 | int status; |
| 6990 | |
| 6991 | res.fh = nfs_alloc_fhandle(); |
| 6992 | if (res.fh == NULL) |
| 6993 | return -ENOMEM; |
| 6994 | |
| 6995 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6996 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6997 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6998 | &args.seq_args, &res.seq_res); |
| 6999 | nfs_free_fhandle(res.fh); |
| 7000 | if (status) |
| 7001 | return status; |
| 7002 | |
| 7003 | do_renew_lease(clp, now); |
| 7004 | return 0; |
| 7005 | } |
| 7006 | |
| 7007 | #ifdef CONFIG_NFS_V4_1 |
| 7008 | |
| 7009 | /* |
| 7010 | * This operation also signals the server that this client is |
| 7011 | * performing "lease moved" recovery. The server can stop asserting |
| 7012 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7013 | * this operation is identified in the SEQUENCE operation in this |
| 7014 | * compound. |
| 7015 | */ |
| 7016 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7017 | { |
| 7018 | struct nfs_server *server = NFS_SERVER(inode); |
| 7019 | struct rpc_clnt *clnt = server->client; |
| 7020 | struct nfs4_fsid_present_arg args = { |
| 7021 | .fh = NFS_FH(inode), |
| 7022 | }; |
| 7023 | struct nfs4_fsid_present_res res = { |
| 7024 | }; |
| 7025 | struct rpc_message msg = { |
| 7026 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7027 | .rpc_argp = &args, |
| 7028 | .rpc_resp = &res, |
| 7029 | .rpc_cred = cred, |
| 7030 | }; |
| 7031 | int status; |
| 7032 | |
| 7033 | res.fh = nfs_alloc_fhandle(); |
| 7034 | if (res.fh == NULL) |
| 7035 | return -ENOMEM; |
| 7036 | |
| 7037 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7038 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7039 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7040 | &args.seq_args, &res.seq_res); |
| 7041 | nfs_free_fhandle(res.fh); |
| 7042 | if (status == NFS4_OK && |
| 7043 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7044 | status = -NFS4ERR_LEASE_MOVED; |
| 7045 | return status; |
| 7046 | } |
| 7047 | |
| 7048 | #endif /* CONFIG_NFS_V4_1 */ |
| 7049 | |
| 7050 | /** |
| 7051 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7052 | * @inode: inode on FSID to check |
| 7053 | * @cred: credential to use for this operation |
| 7054 | * |
| 7055 | * Server indicates whether the FSID is present, moved, or not |
| 7056 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7057 | * condition for this client ID. |
| 7058 | * |
| 7059 | * Returns NFS4_OK if the FSID is present on this server, |
| 7060 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7061 | * NFS4ERR code if some error occurred on the server, or a |
| 7062 | * negative errno if a local failure occurred. |
| 7063 | */ |
| 7064 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7065 | { |
| 7066 | struct nfs_server *server = NFS_SERVER(inode); |
| 7067 | struct nfs_client *clp = server->nfs_client; |
| 7068 | const struct nfs4_mig_recovery_ops *ops = |
| 7069 | clp->cl_mvops->mig_recovery_ops; |
| 7070 | struct nfs4_exception exception = { }; |
| 7071 | int status; |
| 7072 | |
| 7073 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7074 | (unsigned long long)server->fsid.major, |
| 7075 | (unsigned long long)server->fsid.minor, |
| 7076 | clp->cl_hostname); |
| 7077 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7078 | |
| 7079 | do { |
| 7080 | status = ops->fsid_present(inode, cred); |
| 7081 | if (status != -NFS4ERR_DELAY) |
| 7082 | break; |
| 7083 | nfs4_handle_exception(server, status, &exception); |
| 7084 | } while (exception.retry); |
| 7085 | return status; |
| 7086 | } |
| 7087 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7088 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7089 | * If 'use_integrity' is true and the state managment nfs_client |
| 7090 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7091 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7092 | * Considerations sections. Otherwise, just use the user cred with the |
| 7093 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7094 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7095 | 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] | 7096 | { |
| 7097 | int status; |
| 7098 | struct nfs4_secinfo_arg args = { |
| 7099 | .dir_fh = NFS_FH(dir), |
| 7100 | .name = name, |
| 7101 | }; |
| 7102 | struct nfs4_secinfo_res res = { |
| 7103 | .flavors = flavors, |
| 7104 | }; |
| 7105 | struct rpc_message msg = { |
| 7106 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7107 | .rpc_argp = &args, |
| 7108 | .rpc_resp = &res, |
| 7109 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7110 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7111 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7112 | |
| 7113 | if (use_integrity) { |
| 7114 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7115 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7116 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7117 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7118 | |
| 7119 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7120 | |
| 7121 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7122 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7123 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7124 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7125 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7126 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7127 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7128 | if (cred) |
| 7129 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7130 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7131 | return status; |
| 7132 | } |
| 7133 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7134 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7135 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7136 | { |
| 7137 | struct nfs4_exception exception = { }; |
| 7138 | int err; |
| 7139 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7140 | err = -NFS4ERR_WRONGSEC; |
| 7141 | |
| 7142 | /* try to use integrity protection with machine cred */ |
| 7143 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7144 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7145 | |
| 7146 | /* |
| 7147 | * if unable to use integrity protection, or SECINFO with |
| 7148 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7149 | * disallowed by spec, but exists in deployed servers) use |
| 7150 | * the current filesystem's rpc_client and the user cred. |
| 7151 | */ |
| 7152 | if (err == -NFS4ERR_WRONGSEC) |
| 7153 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7154 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7155 | trace_nfs4_secinfo(dir, name, err); |
| 7156 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7157 | &exception); |
| 7158 | } while (exception.retry); |
| 7159 | return err; |
| 7160 | } |
| 7161 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7162 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7163 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7164 | * Check the exchange flags returned by the server for invalid flags, having |
| 7165 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7166 | * DS flags set. |
| 7167 | */ |
| 7168 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7169 | { |
| 7170 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7171 | goto out_inval; |
| 7172 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7173 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7174 | goto out_inval; |
| 7175 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7176 | goto out_inval; |
| 7177 | return NFS_OK; |
| 7178 | out_inval: |
| 7179 | return -NFS4ERR_INVAL; |
| 7180 | } |
| 7181 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7182 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7183 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7184 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7185 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7186 | if (a->server_scope_sz != b->server_scope_sz) |
| 7187 | return false; |
| 7188 | 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] | 7189 | } |
| 7190 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7191 | static void |
| 7192 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7193 | { |
| 7194 | } |
| 7195 | |
| 7196 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7197 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7198 | }; |
| 7199 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7200 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7201 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7202 | * |
| 7203 | * The 4.1 client currently uses the same TCP connection for the |
| 7204 | * fore and backchannel. |
| 7205 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7206 | static |
| 7207 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7208 | struct rpc_xprt *xprt, |
| 7209 | struct nfs_client *clp, |
| 7210 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7211 | { |
| 7212 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7213 | struct nfs41_bind_conn_to_session_args args = { |
| 7214 | .client = clp, |
| 7215 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7216 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7217 | struct nfs41_bind_conn_to_session_res res; |
| 7218 | struct rpc_message msg = { |
| 7219 | .rpc_proc = |
| 7220 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7221 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7222 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7223 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7224 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7225 | struct rpc_task_setup task_setup_data = { |
| 7226 | .rpc_client = clnt, |
| 7227 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7228 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7229 | .rpc_message = &msg, |
| 7230 | .flags = RPC_TASK_TIMEOUT, |
| 7231 | }; |
| 7232 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7233 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7234 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7235 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7236 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7237 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7238 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7239 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7240 | args.dir = NFS4_CDFC4_FORE; |
| 7241 | |
| 7242 | task = rpc_run_task(&task_setup_data); |
| 7243 | if (!IS_ERR(task)) { |
| 7244 | status = task->tk_status; |
| 7245 | rpc_put_task(task); |
| 7246 | } else |
| 7247 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7248 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7249 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7250 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7251 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7252 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7253 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7254 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7255 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7256 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7257 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7258 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7259 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7260 | 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] | 7261 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7262 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7263 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7264 | } |
| 7265 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7266 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7267 | return status; |
| 7268 | } |
| 7269 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7270 | struct rpc_bind_conn_calldata { |
| 7271 | struct nfs_client *clp; |
| 7272 | struct rpc_cred *cred; |
| 7273 | }; |
| 7274 | |
| 7275 | static int |
| 7276 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7277 | struct rpc_xprt *xprt, |
| 7278 | void *calldata) |
| 7279 | { |
| 7280 | struct rpc_bind_conn_calldata *p = calldata; |
| 7281 | |
| 7282 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7283 | } |
| 7284 | |
| 7285 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7286 | { |
| 7287 | struct rpc_bind_conn_calldata data = { |
| 7288 | .clp = clp, |
| 7289 | .cred = cred, |
| 7290 | }; |
| 7291 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7292 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7293 | } |
| 7294 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7295 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7296 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7297 | * 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] | 7298 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7299 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7300 | .how = SP4_MACH_CRED, |
| 7301 | .enforce.u.words = { |
| 7302 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7303 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7304 | 1 << (OP_CREATE_SESSION - 32) | |
| 7305 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7306 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7307 | }, |
| 7308 | .allow.u.words = { |
| 7309 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7310 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7311 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7312 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7313 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7314 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7315 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7316 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7317 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7318 | 1 << (OP_FREE_STATEID - 32) | |
| 7319 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7320 | } |
| 7321 | }; |
| 7322 | |
| 7323 | /* |
| 7324 | * Select the state protection mode for client `clp' given the server results |
| 7325 | * from exchange_id in `sp'. |
| 7326 | * |
| 7327 | * Returns 0 on success, negative errno otherwise. |
| 7328 | */ |
| 7329 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7330 | struct nfs41_state_protection *sp) |
| 7331 | { |
| 7332 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7333 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7334 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7335 | 1 << (OP_CREATE_SESSION - 32) | |
| 7336 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7337 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7338 | }; |
| 7339 | unsigned int i; |
| 7340 | |
| 7341 | if (sp->how == SP4_MACH_CRED) { |
| 7342 | /* Print state protect result */ |
| 7343 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7344 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7345 | if (test_bit(i, sp->enforce.u.longs)) |
| 7346 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7347 | if (test_bit(i, sp->allow.u.longs)) |
| 7348 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7349 | } |
| 7350 | |
| 7351 | /* make sure nothing is on enforce list that isn't supported */ |
| 7352 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7353 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7354 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7355 | return -EINVAL; |
| 7356 | } |
| 7357 | } |
| 7358 | |
| 7359 | /* |
| 7360 | * Minimal mode - state operations are allowed to use machine |
| 7361 | * credential. Note this already happens by default, so the |
| 7362 | * client doesn't have to do anything more than the negotiation. |
| 7363 | * |
| 7364 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7365 | * we're already using the machine cred for exchange_id |
| 7366 | * and will never use a different cred. |
| 7367 | */ |
| 7368 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7369 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7370 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7371 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7372 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7373 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7374 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7375 | } else { |
| 7376 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7377 | return -EINVAL; |
| 7378 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7379 | |
| 7380 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7381 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7382 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7383 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7384 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7385 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7386 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7387 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7388 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7389 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7390 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7391 | &clp->cl_sp4_flags); |
| 7392 | } |
| 7393 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7394 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7395 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7396 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7397 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7398 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7399 | |
| 7400 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7401 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7402 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7403 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7404 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7405 | |
| 7406 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7407 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7408 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7409 | } |
| 7410 | |
| 7411 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7412 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7413 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7414 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7415 | } |
| 7416 | |
| 7417 | return 0; |
| 7418 | } |
| 7419 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7420 | struct nfs41_exchange_id_data { |
| 7421 | struct nfs41_exchange_id_res res; |
| 7422 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7423 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7424 | int rpc_status; |
| 7425 | }; |
| 7426 | |
| 7427 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7428 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7429 | struct nfs41_exchange_id_data *cdata = |
| 7430 | (struct nfs41_exchange_id_data *)data; |
| 7431 | struct nfs_client *clp = cdata->args.client; |
| 7432 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7433 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7434 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7435 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7436 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7437 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7438 | |
| 7439 | if (cdata->xprt && status == 0) { |
| 7440 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7441 | cdata->xprt); |
| 7442 | goto out; |
| 7443 | } |
| 7444 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7445 | if (status == 0) |
| 7446 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7447 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7448 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7449 | clp->cl_clientid = cdata->res.clientid; |
| 7450 | clp->cl_exchange_flags = cdata->res.flags; |
Chuck Lever | 838edb9 | 2017-06-08 11:52:52 -0400 | [diff] [blame] | 7451 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7452 | /* Client ID is not confirmed */ |
Chuck Lever | 838edb9 | 2017-06-08 11:52:52 -0400 | [diff] [blame] | 7453 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7454 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Chuck Lever | 838edb9 | 2017-06-08 11:52:52 -0400 | [diff] [blame] | 7455 | &clp->cl_session->session_state); |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7456 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7457 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7458 | clp->cl_serverowner = cdata->res.server_owner; |
| 7459 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7460 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7461 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7462 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7463 | clp->cl_implid = cdata->res.impl_id; |
| 7464 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7465 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7466 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7467 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7468 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7469 | dprintk("%s: server_scope mismatch detected\n", |
| 7470 | __func__); |
| 7471 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7472 | kfree(clp->cl_serverscope); |
| 7473 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7474 | } |
| 7475 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7476 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7477 | clp->cl_serverscope = cdata->res.server_scope; |
| 7478 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7479 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7480 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7481 | memcpy(clp->cl_confirm.data, cdata->args.verifier.data, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7482 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7483 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7484 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7485 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7486 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7487 | } |
| 7488 | |
| 7489 | static void nfs4_exchange_id_release(void *data) |
| 7490 | { |
| 7491 | struct nfs41_exchange_id_data *cdata = |
| 7492 | (struct nfs41_exchange_id_data *)data; |
| 7493 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7494 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7495 | kfree(cdata->res.impl_id); |
| 7496 | kfree(cdata->res.server_scope); |
| 7497 | kfree(cdata->res.server_owner); |
| 7498 | kfree(cdata); |
| 7499 | } |
| 7500 | |
| 7501 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7502 | .rpc_call_done = nfs4_exchange_id_done, |
| 7503 | .rpc_release = nfs4_exchange_id_release, |
| 7504 | }; |
| 7505 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7506 | /* |
| 7507 | * _nfs4_proc_exchange_id() |
| 7508 | * |
| 7509 | * Wrapper for EXCHANGE_ID operation. |
| 7510 | */ |
| 7511 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7512 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7513 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7514 | struct rpc_message msg = { |
| 7515 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7516 | .rpc_cred = cred, |
| 7517 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7518 | struct rpc_task_setup task_setup_data = { |
| 7519 | .rpc_client = clp->cl_rpcclient, |
| 7520 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7521 | .rpc_message = &msg, |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7522 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7523 | }; |
| 7524 | struct nfs41_exchange_id_data *calldata; |
| 7525 | struct rpc_task *task; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7526 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7527 | |
| 7528 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7529 | return -EIO; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7530 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7531 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 7532 | if (!calldata) { |
| 7533 | nfs_put_client(clp); |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7534 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 7535 | } |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7536 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7537 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7538 | |
| 7539 | status = nfs4_init_uniform_client_string(clp); |
| 7540 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7541 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7542 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7543 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7544 | GFP_NOFS); |
| 7545 | status = -ENOMEM; |
| 7546 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7547 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7548 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7549 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7550 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7551 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7552 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7553 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7554 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7555 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7556 | goto out_server_scope; |
| 7557 | |
| 7558 | switch (sp4_how) { |
| 7559 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7560 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7561 | break; |
| 7562 | |
| 7563 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7564 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7565 | break; |
| 7566 | |
| 7567 | default: |
| 7568 | /* unsupported! */ |
| 7569 | WARN_ON_ONCE(1); |
| 7570 | status = -EINVAL; |
| 7571 | goto out_impl_id; |
| 7572 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7573 | if (xprt) { |
| 7574 | calldata->xprt = xprt; |
| 7575 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7576 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7577 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7578 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7579 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7580 | calldata->args.client = clp; |
| 7581 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7582 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7583 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7584 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7585 | #else |
| 7586 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7587 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7588 | #endif |
| 7589 | msg.rpc_argp = &calldata->args; |
| 7590 | msg.rpc_resp = &calldata->res; |
| 7591 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7592 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7593 | task = rpc_run_task(&task_setup_data); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7594 | if (IS_ERR(task)) |
| 7595 | return PTR_ERR(task); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7596 | |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7597 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7598 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7599 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7600 | out: |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7601 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7602 | |
| 7603 | out_impl_id: |
| 7604 | kfree(calldata->res.impl_id); |
| 7605 | out_server_scope: |
| 7606 | kfree(calldata->res.server_scope); |
| 7607 | out_server_owner: |
| 7608 | kfree(calldata->res.server_owner); |
| 7609 | out_calldata: |
| 7610 | kfree(calldata); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7611 | nfs_put_client(clp); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7612 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7613 | } |
| 7614 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7615 | /* |
| 7616 | * nfs4_proc_exchange_id() |
| 7617 | * |
| 7618 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7619 | * |
| 7620 | * Since the clientid has expired, all compounds using sessions |
| 7621 | * associated with the stale clientid will be returning |
| 7622 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7623 | * be in some phase of session reset. |
| 7624 | * |
| 7625 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7626 | */ |
| 7627 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7628 | { |
| 7629 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7630 | int status; |
| 7631 | |
| 7632 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7633 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7634 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7635 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7636 | if (!status) |
| 7637 | return 0; |
| 7638 | } |
| 7639 | |
| 7640 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7641 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7642 | } |
| 7643 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7644 | /** |
| 7645 | * nfs4_test_session_trunk |
| 7646 | * |
| 7647 | * This is an add_xprt_test() test function called from |
| 7648 | * rpc_clnt_setup_test_and_add_xprt. |
| 7649 | * |
| 7650 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7651 | * and is dereferrenced in nfs4_exchange_id_release |
| 7652 | * |
| 7653 | * Upon success, add the new transport to the rpc_clnt |
| 7654 | * |
| 7655 | * @clnt: struct rpc_clnt to get new transport |
| 7656 | * @xprt: the rpc_xprt to test |
| 7657 | * @data: call data for _nfs4_proc_exchange_id. |
| 7658 | */ |
| 7659 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7660 | void *data) |
| 7661 | { |
| 7662 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7663 | u32 sp4_how; |
| 7664 | |
| 7665 | dprintk("--> %s try %s\n", __func__, |
| 7666 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7667 | |
| 7668 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7669 | |
| 7670 | /* Test connection for session trunking. Async exchange_id call */ |
| 7671 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7672 | } |
| 7673 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7674 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7675 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7676 | struct rpc_cred *cred) |
| 7677 | { |
| 7678 | struct rpc_message msg = { |
| 7679 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7680 | .rpc_argp = clp, |
| 7681 | .rpc_cred = cred, |
| 7682 | }; |
| 7683 | int status; |
| 7684 | |
| 7685 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7686 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7687 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7688 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7689 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7690 | return status; |
| 7691 | } |
| 7692 | |
| 7693 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7694 | struct rpc_cred *cred) |
| 7695 | { |
| 7696 | unsigned int loop; |
| 7697 | int ret; |
| 7698 | |
| 7699 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7700 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7701 | switch (ret) { |
| 7702 | case -NFS4ERR_DELAY: |
| 7703 | case -NFS4ERR_CLIENTID_BUSY: |
| 7704 | ssleep(1); |
| 7705 | break; |
| 7706 | default: |
| 7707 | return ret; |
| 7708 | } |
| 7709 | } |
| 7710 | return 0; |
| 7711 | } |
| 7712 | |
| 7713 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7714 | { |
| 7715 | struct rpc_cred *cred; |
| 7716 | int ret = 0; |
| 7717 | |
| 7718 | if (clp->cl_mvops->minor_version < 1) |
| 7719 | goto out; |
| 7720 | if (clp->cl_exchange_flags == 0) |
| 7721 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7722 | if (clp->cl_preserve_clid) |
| 7723 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7724 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7725 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7726 | if (cred) |
| 7727 | put_rpccred(cred); |
| 7728 | switch (ret) { |
| 7729 | case 0: |
| 7730 | case -NFS4ERR_STALE_CLIENTID: |
| 7731 | clp->cl_exchange_flags = 0; |
| 7732 | } |
| 7733 | out: |
| 7734 | return ret; |
| 7735 | } |
| 7736 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7737 | struct nfs4_get_lease_time_data { |
| 7738 | struct nfs4_get_lease_time_args *args; |
| 7739 | struct nfs4_get_lease_time_res *res; |
| 7740 | struct nfs_client *clp; |
| 7741 | }; |
| 7742 | |
| 7743 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7744 | void *calldata) |
| 7745 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7746 | struct nfs4_get_lease_time_data *data = |
| 7747 | (struct nfs4_get_lease_time_data *)calldata; |
| 7748 | |
| 7749 | dprintk("--> %s\n", __func__); |
| 7750 | /* just setup sequence, do not trigger session recovery |
| 7751 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7752 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7753 | &data->args->la_seq_args, |
| 7754 | &data->res->lr_seq_res, |
| 7755 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7756 | dprintk("<-- %s\n", __func__); |
| 7757 | } |
| 7758 | |
| 7759 | /* |
| 7760 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7761 | * from sequence operation or clientid errors. |
| 7762 | */ |
| 7763 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7764 | { |
| 7765 | struct nfs4_get_lease_time_data *data = |
| 7766 | (struct nfs4_get_lease_time_data *)calldata; |
| 7767 | |
| 7768 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7769 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7770 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7771 | switch (task->tk_status) { |
| 7772 | case -NFS4ERR_DELAY: |
| 7773 | case -NFS4ERR_GRACE: |
| 7774 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7775 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7776 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7777 | /* fall through */ |
| 7778 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7779 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7780 | return; |
| 7781 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7782 | dprintk("<-- %s\n", __func__); |
| 7783 | } |
| 7784 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7785 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7786 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7787 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7788 | }; |
| 7789 | |
| 7790 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7791 | { |
| 7792 | struct rpc_task *task; |
| 7793 | struct nfs4_get_lease_time_args args; |
| 7794 | struct nfs4_get_lease_time_res res = { |
| 7795 | .lr_fsinfo = fsinfo, |
| 7796 | }; |
| 7797 | struct nfs4_get_lease_time_data data = { |
| 7798 | .args = &args, |
| 7799 | .res = &res, |
| 7800 | .clp = clp, |
| 7801 | }; |
| 7802 | struct rpc_message msg = { |
| 7803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7804 | .rpc_argp = &args, |
| 7805 | .rpc_resp = &res, |
| 7806 | }; |
| 7807 | struct rpc_task_setup task_setup = { |
| 7808 | .rpc_client = clp->cl_rpcclient, |
| 7809 | .rpc_message = &msg, |
| 7810 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7811 | .callback_data = &data, |
| 7812 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7813 | }; |
| 7814 | int status; |
| 7815 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7816 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7817 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7818 | task = rpc_run_task(&task_setup); |
| 7819 | |
| 7820 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7821 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7822 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7823 | status = task->tk_status; |
| 7824 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7825 | return status; |
| 7826 | } |
| 7827 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7828 | /* |
| 7829 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7830 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7831 | * use them. |
| 7832 | * |
| 7833 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7834 | * always set csa_cachethis to FALSE because the current implementation |
| 7835 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7836 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7837 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7838 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7839 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7840 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7841 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7842 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7843 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7844 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7845 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7846 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7847 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7848 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7849 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7850 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7851 | |
| 7852 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7853 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7854 | __func__, |
| 7855 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7856 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7857 | |
| 7858 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7859 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7860 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7861 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7862 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7863 | 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] | 7864 | |
| 7865 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7866 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7867 | __func__, |
| 7868 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7869 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7870 | args->bc_attrs.max_reqs); |
| 7871 | } |
| 7872 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7873 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7874 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7875 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7876 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7877 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7878 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7879 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7880 | return -EINVAL; |
| 7881 | /* |
| 7882 | * Our requested max_ops is the minimum we need; we're not |
| 7883 | * prepared to break up compounds into smaller pieces than that. |
| 7884 | * So, no point even trying to continue if the server won't |
| 7885 | * cooperate: |
| 7886 | */ |
| 7887 | if (rcvd->max_ops < sent->max_ops) |
| 7888 | return -EINVAL; |
| 7889 | if (rcvd->max_reqs == 0) |
| 7890 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7891 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7892 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7893 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7894 | } |
| 7895 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7896 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7897 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7898 | { |
| 7899 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7900 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7901 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7902 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7903 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7904 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7905 | return -EINVAL; |
| 7906 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7907 | return -EINVAL; |
| 7908 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7909 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7910 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7911 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7912 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7913 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7914 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7915 | return 0; |
| 7916 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7917 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7918 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7919 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7920 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7921 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7922 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7923 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7924 | if (ret) |
| 7925 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7926 | return nfs4_verify_back_channel_attrs(args, res); |
| 7927 | } |
| 7928 | |
| 7929 | static void nfs4_update_session(struct nfs4_session *session, |
| 7930 | struct nfs41_create_session_res *res) |
| 7931 | { |
| 7932 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7933 | /* Mark client id and session as being confirmed */ |
| 7934 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7935 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7936 | session->flags = res->flags; |
| 7937 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7938 | if (res->flags & SESSION4_BACK_CHAN) |
| 7939 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7940 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7941 | } |
| 7942 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7943 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7944 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7945 | { |
| 7946 | struct nfs4_session *session = clp->cl_session; |
| 7947 | struct nfs41_create_session_args args = { |
| 7948 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7949 | .clientid = clp->cl_clientid, |
| 7950 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7951 | .cb_program = NFS4_CALLBACK, |
| 7952 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7953 | struct nfs41_create_session_res res; |
| 7954 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7955 | struct rpc_message msg = { |
| 7956 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7957 | .rpc_argp = &args, |
| 7958 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7959 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7960 | }; |
| 7961 | int status; |
| 7962 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7963 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7964 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7965 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7966 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7967 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7968 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7969 | switch (status) { |
| 7970 | case -NFS4ERR_STALE_CLIENTID: |
| 7971 | case -NFS4ERR_DELAY: |
| 7972 | case -ETIMEDOUT: |
| 7973 | case -EACCES: |
| 7974 | case -EAGAIN: |
| 7975 | goto out; |
| 7976 | }; |
| 7977 | |
| 7978 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7979 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7980 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7981 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7982 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7983 | if (status) |
| 7984 | goto out; |
| 7985 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7986 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7987 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7988 | return status; |
| 7989 | } |
| 7990 | |
| 7991 | /* |
| 7992 | * Issues a CREATE_SESSION operation to the server. |
| 7993 | * It is the responsibility of the caller to verify the session is |
| 7994 | * expired before calling this routine. |
| 7995 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7996 | 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] | 7997 | { |
| 7998 | int status; |
| 7999 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8000 | struct nfs4_session *session = clp->cl_session; |
| 8001 | |
| 8002 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8003 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8004 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8005 | if (status) |
| 8006 | goto out; |
| 8007 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8008 | /* Init or reset the session slot tables */ |
| 8009 | status = nfs4_setup_session_slot_tables(session); |
| 8010 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8011 | if (status) |
| 8012 | goto out; |
| 8013 | |
| 8014 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8015 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8016 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8017 | out: |
| 8018 | dprintk("<-- %s\n", __func__); |
| 8019 | return status; |
| 8020 | } |
| 8021 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8022 | /* |
| 8023 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8024 | * The caller must serialize access to this routine. |
| 8025 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8026 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8027 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8028 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8029 | struct rpc_message msg = { |
| 8030 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8031 | .rpc_argp = session, |
| 8032 | .rpc_cred = cred, |
| 8033 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8034 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8035 | |
| 8036 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8037 | |
| 8038 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8039 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8040 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8041 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8042 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8043 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8044 | |
| 8045 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8046 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8047 | "Session has been destroyed regardless...\n", status); |
| 8048 | |
| 8049 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8050 | return status; |
| 8051 | } |
| 8052 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8053 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8054 | * Renew the cl_session lease. |
| 8055 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8056 | struct nfs4_sequence_data { |
| 8057 | struct nfs_client *clp; |
| 8058 | struct nfs4_sequence_args args; |
| 8059 | struct nfs4_sequence_res res; |
| 8060 | }; |
| 8061 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8062 | static void nfs41_sequence_release(void *data) |
| 8063 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8064 | struct nfs4_sequence_data *calldata = data; |
| 8065 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8066 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8067 | if (atomic_read(&clp->cl_count) > 1) |
| 8068 | nfs4_schedule_state_renewal(clp); |
| 8069 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8070 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8071 | } |
| 8072 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8073 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8074 | { |
| 8075 | switch(task->tk_status) { |
| 8076 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8077 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8078 | return -EAGAIN; |
| 8079 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8080 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8081 | } |
| 8082 | return 0; |
| 8083 | } |
| 8084 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8085 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8086 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8087 | struct nfs4_sequence_data *calldata = data; |
| 8088 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8089 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8090 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8091 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8092 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8093 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8094 | if (task->tk_status < 0) { |
| 8095 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8096 | if (atomic_read(&clp->cl_count) == 1) |
| 8097 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8098 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8099 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8100 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8101 | return; |
| 8102 | } |
| 8103 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8104 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8105 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8106 | dprintk("<-- %s\n", __func__); |
| 8107 | } |
| 8108 | |
| 8109 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8110 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8111 | struct nfs4_sequence_data *calldata = data; |
| 8112 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8113 | struct nfs4_sequence_args *args; |
| 8114 | struct nfs4_sequence_res *res; |
| 8115 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8116 | args = task->tk_msg.rpc_argp; |
| 8117 | res = task->tk_msg.rpc_resp; |
| 8118 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8119 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8120 | } |
| 8121 | |
| 8122 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8123 | .rpc_call_done = nfs41_sequence_call_done, |
| 8124 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8125 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8126 | }; |
| 8127 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8128 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8129 | struct rpc_cred *cred, |
| 8130 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8131 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8132 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8133 | struct rpc_message msg = { |
| 8134 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8135 | .rpc_cred = cred, |
| 8136 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8137 | struct rpc_task_setup task_setup_data = { |
| 8138 | .rpc_client = clp->cl_rpcclient, |
| 8139 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8140 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8141 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8142 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8143 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8144 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8145 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8146 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8147 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8148 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8149 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8150 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8151 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8152 | if (is_privileged) |
| 8153 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8154 | msg.rpc_argp = &calldata->args; |
| 8155 | msg.rpc_resp = &calldata->res; |
| 8156 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8157 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8158 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8159 | return rpc_run_task(&task_setup_data); |
| 8160 | } |
| 8161 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8162 | 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] | 8163 | { |
| 8164 | struct rpc_task *task; |
| 8165 | int ret = 0; |
| 8166 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8167 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8168 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8169 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8170 | if (IS_ERR(task)) |
| 8171 | ret = PTR_ERR(task); |
| 8172 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8173 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8174 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8175 | return ret; |
| 8176 | } |
| 8177 | |
| 8178 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8179 | { |
| 8180 | struct rpc_task *task; |
| 8181 | int ret; |
| 8182 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8183 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8184 | if (IS_ERR(task)) { |
| 8185 | ret = PTR_ERR(task); |
| 8186 | goto out; |
| 8187 | } |
| 8188 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8189 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8190 | ret = task->tk_status; |
| 8191 | rpc_put_task(task); |
| 8192 | out: |
| 8193 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8194 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8195 | } |
| 8196 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8197 | struct nfs4_reclaim_complete_data { |
| 8198 | struct nfs_client *clp; |
| 8199 | struct nfs41_reclaim_complete_args arg; |
| 8200 | struct nfs41_reclaim_complete_res res; |
| 8201 | }; |
| 8202 | |
| 8203 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8204 | { |
| 8205 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8206 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8207 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8208 | &calldata->arg.seq_args, |
| 8209 | &calldata->res.seq_res, |
| 8210 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8211 | } |
| 8212 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8213 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8214 | { |
| 8215 | switch(task->tk_status) { |
| 8216 | case 0: |
| 8217 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8218 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8219 | break; |
| 8220 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8221 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8222 | /* fall through */ |
| 8223 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8224 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8225 | case -NFS4ERR_BADSESSION: |
| 8226 | case -NFS4ERR_DEADSESSION: |
| 8227 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8228 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8229 | task->tk_status); |
| 8230 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8231 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8232 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8233 | } |
| 8234 | return 0; |
| 8235 | } |
| 8236 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8237 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8238 | { |
| 8239 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8240 | struct nfs_client *clp = calldata->clp; |
| 8241 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8242 | |
| 8243 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8244 | if (!nfs41_sequence_done(task, res)) |
| 8245 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8246 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8247 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8248 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8249 | rpc_restart_call_prepare(task); |
| 8250 | return; |
| 8251 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8252 | dprintk("<-- %s\n", __func__); |
| 8253 | } |
| 8254 | |
| 8255 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8256 | { |
| 8257 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8258 | |
| 8259 | kfree(calldata); |
| 8260 | } |
| 8261 | |
| 8262 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8263 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8264 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8265 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8266 | }; |
| 8267 | |
| 8268 | /* |
| 8269 | * Issue a global reclaim complete. |
| 8270 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8271 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8272 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8273 | { |
| 8274 | struct nfs4_reclaim_complete_data *calldata; |
| 8275 | struct rpc_task *task; |
| 8276 | struct rpc_message msg = { |
| 8277 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8278 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8279 | }; |
| 8280 | struct rpc_task_setup task_setup_data = { |
| 8281 | .rpc_client = clp->cl_rpcclient, |
| 8282 | .rpc_message = &msg, |
| 8283 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8284 | .flags = RPC_TASK_ASYNC, |
| 8285 | }; |
| 8286 | int status = -ENOMEM; |
| 8287 | |
| 8288 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8289 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8290 | if (calldata == NULL) |
| 8291 | goto out; |
| 8292 | calldata->clp = clp; |
| 8293 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8294 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8295 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8296 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8297 | msg.rpc_argp = &calldata->arg; |
| 8298 | msg.rpc_resp = &calldata->res; |
| 8299 | task_setup_data.callback_data = calldata; |
| 8300 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8301 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8302 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8303 | goto out; |
| 8304 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8305 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8306 | if (status == 0) |
| 8307 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8308 | rpc_put_task(task); |
| 8309 | out: |
| 8310 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8311 | return status; |
| 8312 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8313 | |
| 8314 | static void |
| 8315 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8316 | { |
| 8317 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8318 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8319 | |
| 8320 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8321 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8322 | &lgp->res.seq_res, task); |
| 8323 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8324 | } |
| 8325 | |
| 8326 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8327 | { |
| 8328 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8329 | |
| 8330 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8331 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8332 | dprintk("<-- %s\n", __func__); |
| 8333 | } |
| 8334 | |
| 8335 | static int |
| 8336 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8337 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8338 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8339 | struct inode *inode = lgp->args.inode; |
| 8340 | struct nfs_server *server = NFS_SERVER(inode); |
| 8341 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8342 | int nfs4err = task->tk_status; |
| 8343 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8344 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8345 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8346 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8347 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8348 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8349 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8350 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8351 | |
| 8352 | /* |
| 8353 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8354 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8355 | * retry go inband. |
| 8356 | */ |
| 8357 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8358 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8359 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8360 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8361 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8362 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8363 | */ |
| 8364 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8365 | status = -EOVERFLOW; |
| 8366 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8367 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8368 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8369 | * (or clients) writing to the same RAID stripe except when |
| 8370 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8371 | * |
| 8372 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8373 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8374 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8375 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8376 | if (lgp->args.minlength == 0) { |
| 8377 | status = -EOVERFLOW; |
| 8378 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8379 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8380 | status = -EBUSY; |
| 8381 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8382 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8383 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8384 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8385 | case -NFS4ERR_DELEG_REVOKED: |
| 8386 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8387 | case -NFS4ERR_EXPIRED: |
| 8388 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8389 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8390 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8391 | lo = NFS_I(inode)->layout; |
| 8392 | /* If the open stateid was bad, then recover it. */ |
| 8393 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8394 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8395 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8396 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8397 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8398 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8399 | break; |
| 8400 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8401 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8402 | /* |
| 8403 | * Mark the bad layout state as invalid, then retry |
| 8404 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8405 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8406 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8407 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8408 | pnfs_free_lseg_list(&head); |
| 8409 | status = -EAGAIN; |
| 8410 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8411 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8412 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8413 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8414 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8415 | if (!status) { |
| 8416 | if (exception->retry) |
| 8417 | status = -EAGAIN; |
| 8418 | else |
| 8419 | status = err; |
| 8420 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8421 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8422 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8423 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8424 | } |
| 8425 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8426 | static size_t max_response_pages(struct nfs_server *server) |
| 8427 | { |
| 8428 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8429 | return nfs_page_array_len(0, max_resp_sz); |
| 8430 | } |
| 8431 | |
| 8432 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8433 | { |
| 8434 | int i; |
| 8435 | |
| 8436 | if (!pages) |
| 8437 | return; |
| 8438 | |
| 8439 | for (i = 0; i < size; i++) { |
| 8440 | if (!pages[i]) |
| 8441 | break; |
| 8442 | __free_page(pages[i]); |
| 8443 | } |
| 8444 | kfree(pages); |
| 8445 | } |
| 8446 | |
| 8447 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8448 | { |
| 8449 | struct page **pages; |
| 8450 | int i; |
| 8451 | |
| 8452 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8453 | if (!pages) { |
| 8454 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8455 | return NULL; |
| 8456 | } |
| 8457 | |
| 8458 | for (i = 0; i < size; i++) { |
| 8459 | pages[i] = alloc_page(gfp_flags); |
| 8460 | if (!pages[i]) { |
| 8461 | dprintk("%s: failed to allocate page\n", __func__); |
| 8462 | nfs4_free_pages(pages, size); |
| 8463 | return NULL; |
| 8464 | } |
| 8465 | } |
| 8466 | |
| 8467 | return pages; |
| 8468 | } |
| 8469 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8470 | static void nfs4_layoutget_release(void *calldata) |
| 8471 | { |
| 8472 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8473 | struct inode *inode = lgp->args.inode; |
| 8474 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8475 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8476 | |
| 8477 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8478 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8479 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8480 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8481 | put_nfs_open_context(lgp->args.ctx); |
| 8482 | kfree(calldata); |
| 8483 | dprintk("<-- %s\n", __func__); |
| 8484 | } |
| 8485 | |
| 8486 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8487 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8488 | .rpc_call_done = nfs4_layoutget_done, |
| 8489 | .rpc_release = nfs4_layoutget_release, |
| 8490 | }; |
| 8491 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8492 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8493 | 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] | 8494 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8495 | struct inode *inode = lgp->args.inode; |
| 8496 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8497 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8498 | struct rpc_task *task; |
| 8499 | struct rpc_message msg = { |
| 8500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8501 | .rpc_argp = &lgp->args, |
| 8502 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8503 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8504 | }; |
| 8505 | struct rpc_task_setup task_setup_data = { |
| 8506 | .rpc_client = server->client, |
| 8507 | .rpc_message = &msg, |
| 8508 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8509 | .callback_data = lgp, |
| 8510 | .flags = RPC_TASK_ASYNC, |
| 8511 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8512 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8513 | struct nfs4_exception exception = { |
| 8514 | .inode = inode, |
| 8515 | .timeout = *timeout, |
| 8516 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8517 | int status = 0; |
| 8518 | |
| 8519 | dprintk("--> %s\n", __func__); |
| 8520 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8521 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8522 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8523 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8524 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8525 | if (!lgp->args.layout.pages) { |
| 8526 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8527 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8528 | } |
| 8529 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8530 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8531 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8532 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8533 | 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] | 8534 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8535 | task = rpc_run_task(&task_setup_data); |
| 8536 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8537 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8538 | status = rpc_wait_for_completion_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8539 | if (status == 0) { |
| 8540 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8541 | *timeout = exception.timeout; |
| 8542 | } |
| 8543 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8544 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8545 | &lgp->args.range, |
| 8546 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8547 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8548 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8549 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8550 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8551 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8552 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8553 | rpc_put_task(task); |
| 8554 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8555 | if (status) |
| 8556 | return ERR_PTR(status); |
| 8557 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8558 | } |
| 8559 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8560 | static void |
| 8561 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8562 | { |
| 8563 | struct nfs4_layoutreturn *lrp = calldata; |
| 8564 | |
| 8565 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8566 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8567 | &lrp->args.seq_args, |
| 8568 | &lrp->res.seq_res, |
| 8569 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8570 | } |
| 8571 | |
| 8572 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8573 | { |
| 8574 | struct nfs4_layoutreturn *lrp = calldata; |
| 8575 | struct nfs_server *server; |
| 8576 | |
| 8577 | dprintk("--> %s\n", __func__); |
| 8578 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8579 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8580 | return; |
| 8581 | |
| 8582 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8583 | switch (task->tk_status) { |
| 8584 | default: |
| 8585 | task->tk_status = 0; |
| 8586 | case 0: |
| 8587 | break; |
| 8588 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8589 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8590 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8591 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8592 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8593 | return; |
| 8594 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8595 | dprintk("<-- %s\n", __func__); |
| 8596 | } |
| 8597 | |
| 8598 | static void nfs4_layoutreturn_release(void *calldata) |
| 8599 | { |
| 8600 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8601 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8602 | |
| 8603 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8604 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8605 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8606 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8607 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8608 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8609 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8610 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8611 | kfree(calldata); |
| 8612 | dprintk("<-- %s\n", __func__); |
| 8613 | } |
| 8614 | |
| 8615 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8616 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8617 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8618 | .rpc_release = nfs4_layoutreturn_release, |
| 8619 | }; |
| 8620 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8621 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8622 | { |
| 8623 | struct rpc_task *task; |
| 8624 | struct rpc_message msg = { |
| 8625 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8626 | .rpc_argp = &lrp->args, |
| 8627 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8628 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8629 | }; |
| 8630 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8631 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8632 | .rpc_message = &msg, |
| 8633 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8634 | .callback_data = lrp, |
| 8635 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8636 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8637 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8638 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8639 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8640 | &task_setup_data.rpc_client, &msg); |
| 8641 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8642 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8643 | if (!sync) { |
| 8644 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8645 | if (!lrp->inode) { |
| 8646 | nfs4_layoutreturn_release(lrp); |
| 8647 | return -EAGAIN; |
| 8648 | } |
| 8649 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8650 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8651 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8652 | task = rpc_run_task(&task_setup_data); |
| 8653 | if (IS_ERR(task)) |
| 8654 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8655 | if (sync) |
| 8656 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8657 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8658 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8659 | rpc_put_task(task); |
| 8660 | return status; |
| 8661 | } |
| 8662 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8663 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8664 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8665 | struct pnfs_device *pdev, |
| 8666 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8667 | { |
| 8668 | struct nfs4_getdeviceinfo_args args = { |
| 8669 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8670 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8671 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8672 | }; |
| 8673 | struct nfs4_getdeviceinfo_res res = { |
| 8674 | .pdev = pdev, |
| 8675 | }; |
| 8676 | struct rpc_message msg = { |
| 8677 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8678 | .rpc_argp = &args, |
| 8679 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8680 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8681 | }; |
| 8682 | int status; |
| 8683 | |
| 8684 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8685 | 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] | 8686 | if (res.notification & ~args.notify_types) |
| 8687 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8688 | if (res.notification != args.notify_types) |
| 8689 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8690 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8691 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8692 | |
| 8693 | return status; |
| 8694 | } |
| 8695 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8696 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8697 | struct pnfs_device *pdev, |
| 8698 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8699 | { |
| 8700 | struct nfs4_exception exception = { }; |
| 8701 | int err; |
| 8702 | |
| 8703 | do { |
| 8704 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8705 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8706 | &exception); |
| 8707 | } while (exception.retry); |
| 8708 | return err; |
| 8709 | } |
| 8710 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8711 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8712 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8713 | { |
| 8714 | struct nfs4_layoutcommit_data *data = calldata; |
| 8715 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8716 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8717 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8718 | &data->args.seq_args, |
| 8719 | &data->res.seq_res, |
| 8720 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8721 | } |
| 8722 | |
| 8723 | static void |
| 8724 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8725 | { |
| 8726 | struct nfs4_layoutcommit_data *data = calldata; |
| 8727 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8728 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8729 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8730 | return; |
| 8731 | |
| 8732 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8733 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8734 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8735 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8736 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8737 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8738 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8739 | break; |
| 8740 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8741 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8742 | rpc_restart_call_prepare(task); |
| 8743 | return; |
| 8744 | } |
| 8745 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8746 | } |
| 8747 | |
| 8748 | static void nfs4_layoutcommit_release(void *calldata) |
| 8749 | { |
| 8750 | struct nfs4_layoutcommit_data *data = calldata; |
| 8751 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8752 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8753 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8754 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8755 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8756 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8757 | kfree(data); |
| 8758 | } |
| 8759 | |
| 8760 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8761 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8762 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8763 | .rpc_release = nfs4_layoutcommit_release, |
| 8764 | }; |
| 8765 | |
| 8766 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8767 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8768 | { |
| 8769 | struct rpc_message msg = { |
| 8770 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8771 | .rpc_argp = &data->args, |
| 8772 | .rpc_resp = &data->res, |
| 8773 | .rpc_cred = data->cred, |
| 8774 | }; |
| 8775 | struct rpc_task_setup task_setup_data = { |
| 8776 | .task = &data->task, |
| 8777 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8778 | .rpc_message = &msg, |
| 8779 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8780 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8781 | }; |
| 8782 | struct rpc_task *task; |
| 8783 | int status = 0; |
| 8784 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8785 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8786 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8787 | data->args.lastbytewritten, |
| 8788 | data->args.inode->i_ino); |
| 8789 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8790 | if (!sync) { |
| 8791 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8792 | if (data->inode == NULL) { |
| 8793 | nfs4_layoutcommit_release(data); |
| 8794 | return -EAGAIN; |
| 8795 | } |
| 8796 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8797 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8798 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8799 | task = rpc_run_task(&task_setup_data); |
| 8800 | if (IS_ERR(task)) |
| 8801 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8802 | if (sync) |
| 8803 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8804 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8805 | dprintk("%s: status %d\n", __func__, status); |
| 8806 | rpc_put_task(task); |
| 8807 | return status; |
| 8808 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8809 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8810 | /** |
| 8811 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8812 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8813 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8814 | static int |
| 8815 | _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] | 8816 | struct nfs_fsinfo *info, |
| 8817 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8818 | { |
| 8819 | struct nfs41_secinfo_no_name_args args = { |
| 8820 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8821 | }; |
| 8822 | struct nfs4_secinfo_res res = { |
| 8823 | .flavors = flavors, |
| 8824 | }; |
| 8825 | struct rpc_message msg = { |
| 8826 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8827 | .rpc_argp = &args, |
| 8828 | .rpc_resp = &res, |
| 8829 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8830 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8831 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8832 | int status; |
| 8833 | |
| 8834 | if (use_integrity) { |
| 8835 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8836 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8837 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8838 | } |
| 8839 | |
| 8840 | dprintk("--> %s\n", __func__); |
| 8841 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8842 | &res.seq_res, 0); |
| 8843 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8844 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8845 | if (cred) |
| 8846 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8847 | |
| 8848 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8849 | } |
| 8850 | |
| 8851 | static int |
| 8852 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8853 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8854 | { |
| 8855 | struct nfs4_exception exception = { }; |
| 8856 | int err; |
| 8857 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8858 | /* first try using integrity protection */ |
| 8859 | err = -NFS4ERR_WRONGSEC; |
| 8860 | |
| 8861 | /* try to use integrity protection with machine cred */ |
| 8862 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8863 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8864 | flavors, true); |
| 8865 | |
| 8866 | /* |
| 8867 | * if unable to use integrity protection, or SECINFO with |
| 8868 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8869 | * disallowed by spec, but exists in deployed servers) use |
| 8870 | * the current filesystem's rpc_client and the user cred. |
| 8871 | */ |
| 8872 | if (err == -NFS4ERR_WRONGSEC) |
| 8873 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8874 | flavors, false); |
| 8875 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8876 | switch (err) { |
| 8877 | case 0: |
| 8878 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8879 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8880 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8881 | default: |
| 8882 | err = nfs4_handle_exception(server, err, &exception); |
| 8883 | } |
| 8884 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8885 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8886 | return err; |
| 8887 | } |
| 8888 | |
| 8889 | static int |
| 8890 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8891 | struct nfs_fsinfo *info) |
| 8892 | { |
| 8893 | int err; |
| 8894 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8895 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8896 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8897 | struct nfs4_secinfo4 *secinfo; |
| 8898 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8899 | |
| 8900 | page = alloc_page(GFP_KERNEL); |
| 8901 | if (!page) { |
| 8902 | err = -ENOMEM; |
| 8903 | goto out; |
| 8904 | } |
| 8905 | |
| 8906 | flavors = page_address(page); |
| 8907 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8908 | |
| 8909 | /* |
| 8910 | * Fall back on "guess and check" method if |
| 8911 | * the server doesn't support SECINFO_NO_NAME |
| 8912 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8913 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8914 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8915 | goto out_freepage; |
| 8916 | } |
| 8917 | if (err) |
| 8918 | goto out_freepage; |
| 8919 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8920 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8921 | secinfo = &flavors->flavors[i]; |
| 8922 | |
| 8923 | switch (secinfo->flavor) { |
| 8924 | case RPC_AUTH_NULL: |
| 8925 | case RPC_AUTH_UNIX: |
| 8926 | case RPC_AUTH_GSS: |
| 8927 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8928 | &secinfo->flavor_info); |
| 8929 | break; |
| 8930 | default: |
| 8931 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8932 | break; |
| 8933 | } |
| 8934 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8935 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8936 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8937 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8938 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8939 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8940 | info, flavor); |
| 8941 | if (!err) |
| 8942 | break; |
| 8943 | } |
| 8944 | } |
| 8945 | |
| 8946 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8947 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8948 | |
| 8949 | out_freepage: |
| 8950 | put_page(page); |
| 8951 | if (err == -EACCES) |
| 8952 | return -EPERM; |
| 8953 | out: |
| 8954 | return err; |
| 8955 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8956 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8957 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8958 | nfs4_stateid *stateid, |
| 8959 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8960 | { |
| 8961 | int status; |
| 8962 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8963 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8964 | }; |
| 8965 | struct nfs41_test_stateid_res res; |
| 8966 | struct rpc_message msg = { |
| 8967 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8968 | .rpc_argp = &args, |
| 8969 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8970 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8971 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8972 | struct rpc_clnt *rpc_client = server->client; |
| 8973 | |
| 8974 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8975 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8976 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8977 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8978 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8979 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8980 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8981 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8982 | if (status != NFS_OK) { |
| 8983 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8984 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8985 | } |
| 8986 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8987 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8988 | } |
| 8989 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8990 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8991 | int err, struct nfs4_exception *exception) |
| 8992 | { |
| 8993 | exception->retry = 0; |
| 8994 | switch(err) { |
| 8995 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 8996 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8997 | nfs4_handle_exception(server, err, exception); |
| 8998 | break; |
| 8999 | case -NFS4ERR_BADSESSION: |
| 9000 | case -NFS4ERR_BADSLOT: |
| 9001 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9002 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9003 | case -NFS4ERR_DEADSESSION: |
| 9004 | nfs4_do_handle_exception(server, err, exception); |
| 9005 | } |
| 9006 | } |
| 9007 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9008 | /** |
| 9009 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9010 | * |
| 9011 | * @server: server / transport on which to perform the operation |
| 9012 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9013 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9014 | * |
| 9015 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9016 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9017 | * failed or the state ID is not currently valid. |
| 9018 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9019 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9020 | nfs4_stateid *stateid, |
| 9021 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9022 | { |
| 9023 | struct nfs4_exception exception = { }; |
| 9024 | int err; |
| 9025 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9026 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9027 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9028 | } while (exception.retry); |
| 9029 | return err; |
| 9030 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9031 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9032 | struct nfs_free_stateid_data { |
| 9033 | struct nfs_server *server; |
| 9034 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9035 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9036 | }; |
| 9037 | |
| 9038 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9039 | { |
| 9040 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9041 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9042 | &data->args.seq_args, |
| 9043 | &data->res.seq_res, |
| 9044 | task); |
| 9045 | } |
| 9046 | |
| 9047 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9048 | { |
| 9049 | struct nfs_free_stateid_data *data = calldata; |
| 9050 | |
| 9051 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9052 | |
| 9053 | switch (task->tk_status) { |
| 9054 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9055 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9056 | rpc_restart_call_prepare(task); |
| 9057 | } |
| 9058 | } |
| 9059 | |
| 9060 | static void nfs41_free_stateid_release(void *calldata) |
| 9061 | { |
| 9062 | kfree(calldata); |
| 9063 | } |
| 9064 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9065 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9066 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9067 | .rpc_call_done = nfs41_free_stateid_done, |
| 9068 | .rpc_release = nfs41_free_stateid_release, |
| 9069 | }; |
| 9070 | |
| 9071 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9072 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9073 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9074 | bool privileged) |
| 9075 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9076 | struct rpc_message msg = { |
| 9077 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9078 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9079 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9080 | struct rpc_task_setup task_setup = { |
| 9081 | .rpc_client = server->client, |
| 9082 | .rpc_message = &msg, |
| 9083 | .callback_ops = &nfs41_free_stateid_ops, |
| 9084 | .flags = RPC_TASK_ASYNC, |
| 9085 | }; |
| 9086 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9087 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9088 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9089 | &task_setup.rpc_client, &msg); |
| 9090 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9091 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9092 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9093 | if (!data) |
| 9094 | return ERR_PTR(-ENOMEM); |
| 9095 | data->server = server; |
| 9096 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9097 | |
| 9098 | task_setup.callback_data = data; |
| 9099 | |
| 9100 | msg.rpc_argp = &data->args; |
| 9101 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9102 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9103 | if (privileged) |
| 9104 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9105 | |
| 9106 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9107 | } |
| 9108 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9109 | /** |
| 9110 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9111 | * |
| 9112 | * @server: server / transport on which to perform the operation |
| 9113 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9114 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9115 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9116 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9117 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9118 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9119 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9120 | const nfs4_stateid *stateid, |
| 9121 | struct rpc_cred *cred, |
| 9122 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9123 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9124 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9125 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9126 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9127 | if (IS_ERR(task)) |
| 9128 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9129 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9130 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9131 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9132 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9133 | static void |
| 9134 | 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] | 9135 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9136 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9137 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9138 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9139 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9140 | } |
| 9141 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9142 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9143 | const nfs4_stateid *s2) |
| 9144 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9145 | if (s1->type != s2->type) |
| 9146 | return false; |
| 9147 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9148 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9149 | return false; |
| 9150 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9151 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9152 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9153 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9154 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9155 | } |
| 9156 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9157 | #endif /* CONFIG_NFS_V4_1 */ |
| 9158 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9159 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9160 | const nfs4_stateid *s2) |
| 9161 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9162 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9163 | } |
| 9164 | |
| 9165 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9166 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9167 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9168 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9169 | .recover_open = nfs4_open_reclaim, |
| 9170 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9171 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9172 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9173 | }; |
| 9174 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9175 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9176 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9177 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9178 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9179 | .recover_open = nfs4_open_reclaim, |
| 9180 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9181 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9182 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9183 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9184 | }; |
| 9185 | #endif /* CONFIG_NFS_V4_1 */ |
| 9186 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9187 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9188 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9189 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9190 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9191 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9192 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9193 | }; |
| 9194 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9195 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9196 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9197 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9198 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9199 | .recover_open = nfs41_open_expired, |
| 9200 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9201 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9202 | }; |
| 9203 | #endif /* CONFIG_NFS_V4_1 */ |
| 9204 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9205 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9206 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9207 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9208 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9209 | }; |
| 9210 | |
| 9211 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9212 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9213 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9214 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9215 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9216 | }; |
| 9217 | #endif |
| 9218 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9219 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9220 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9221 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9222 | }; |
| 9223 | |
| 9224 | #if defined(CONFIG_NFS_V4_1) |
| 9225 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9226 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9227 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9228 | }; |
| 9229 | #endif /* CONFIG_NFS_V4_1 */ |
| 9230 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9231 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9232 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9233 | .init_caps = NFS_CAP_READDIRPLUS |
| 9234 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9235 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9236 | .init_client = nfs40_init_client, |
| 9237 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9238 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9239 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9240 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9241 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9242 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9243 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9244 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9245 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9246 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9247 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9248 | }; |
| 9249 | |
| 9250 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9251 | static struct nfs_seqid * |
| 9252 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9253 | { |
| 9254 | return NULL; |
| 9255 | } |
| 9256 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9257 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9258 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9259 | .init_caps = NFS_CAP_READDIRPLUS |
| 9260 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9261 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9262 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9263 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9264 | .init_client = nfs41_init_client, |
| 9265 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9266 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9267 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9268 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9269 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9270 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9271 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9272 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9273 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9274 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9275 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9276 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9277 | }; |
| 9278 | #endif |
| 9279 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9280 | #if defined(CONFIG_NFS_V4_2) |
| 9281 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9282 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9283 | .init_caps = NFS_CAP_READDIRPLUS |
| 9284 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9285 | | NFS_CAP_POSIX_LOCK |
| 9286 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9287 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9288 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9289 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9290 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9291 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9292 | | NFS_CAP_LAYOUTSTATS |
| 9293 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9294 | .init_client = nfs41_init_client, |
| 9295 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9296 | .match_stateid = nfs41_match_stateid, |
| 9297 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9298 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9299 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9300 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9301 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9302 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9303 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9304 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9305 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9306 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9307 | }; |
| 9308 | #endif |
| 9309 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9310 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9311 | [0] = &nfs_v4_0_minor_ops, |
| 9312 | #if defined(CONFIG_NFS_V4_1) |
| 9313 | [1] = &nfs_v4_1_minor_ops, |
| 9314 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9315 | #if defined(CONFIG_NFS_V4_2) |
| 9316 | [2] = &nfs_v4_2_minor_ops, |
| 9317 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9318 | }; |
| 9319 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9320 | 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] | 9321 | { |
| 9322 | ssize_t error, error2; |
| 9323 | |
| 9324 | error = generic_listxattr(dentry, list, size); |
| 9325 | if (error < 0) |
| 9326 | return error; |
| 9327 | if (list) { |
| 9328 | list += error; |
| 9329 | size -= error; |
| 9330 | } |
| 9331 | |
| 9332 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9333 | if (error2 < 0) |
| 9334 | return error2; |
| 9335 | return error + error2; |
| 9336 | } |
| 9337 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9338 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9339 | .create = nfs_create, |
| 9340 | .lookup = nfs_lookup, |
| 9341 | .atomic_open = nfs_atomic_open, |
| 9342 | .link = nfs_link, |
| 9343 | .unlink = nfs_unlink, |
| 9344 | .symlink = nfs_symlink, |
| 9345 | .mkdir = nfs_mkdir, |
| 9346 | .rmdir = nfs_rmdir, |
| 9347 | .mknod = nfs_mknod, |
| 9348 | .rename = nfs_rename, |
| 9349 | .permission = nfs_permission, |
| 9350 | .getattr = nfs_getattr, |
| 9351 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9352 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9353 | }; |
| 9354 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9355 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9356 | .permission = nfs_permission, |
| 9357 | .getattr = nfs_getattr, |
| 9358 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9359 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9360 | }; |
| 9361 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9362 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9363 | .version = 4, /* protocol version */ |
| 9364 | .dentry_ops = &nfs4_dentry_operations, |
| 9365 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9366 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9367 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9368 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9369 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9370 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9371 | .getattr = nfs4_proc_getattr, |
| 9372 | .setattr = nfs4_proc_setattr, |
| 9373 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9374 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9375 | .access = nfs4_proc_access, |
| 9376 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9377 | .create = nfs4_proc_create, |
| 9378 | .remove = nfs4_proc_remove, |
| 9379 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9380 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9381 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9382 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9383 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9384 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9385 | .link = nfs4_proc_link, |
| 9386 | .symlink = nfs4_proc_symlink, |
| 9387 | .mkdir = nfs4_proc_mkdir, |
| 9388 | .rmdir = nfs4_proc_remove, |
| 9389 | .readdir = nfs4_proc_readdir, |
| 9390 | .mknod = nfs4_proc_mknod, |
| 9391 | .statfs = nfs4_proc_statfs, |
| 9392 | .fsinfo = nfs4_proc_fsinfo, |
| 9393 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9394 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9395 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9396 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9397 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9398 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9399 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9400 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9401 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9402 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9403 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9404 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9405 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9406 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9407 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9408 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9409 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9410 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9411 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9412 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9413 | .create_server = nfs4_create_server, |
| 9414 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9415 | }; |
| 9416 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9417 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9418 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9419 | .list = nfs4_xattr_list_nfs4_acl, |
| 9420 | .get = nfs4_xattr_get_nfs4_acl, |
| 9421 | .set = nfs4_xattr_set_nfs4_acl, |
| 9422 | }; |
| 9423 | |
| 9424 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9425 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9426 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9427 | &nfs4_xattr_nfs4_label_handler, |
| 9428 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9429 | NULL |
| 9430 | }; |
| 9431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9432 | /* |
| 9433 | * Local variables: |
| 9434 | * c-basic-offset: 8 |
| 9435 | * End: |
| 9436 | */ |