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 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 278 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 281 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | readdir->cookie = 0; |
| 287 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 288 | if (cookie == 2) |
| 289 | return; |
| 290 | |
| 291 | /* |
| 292 | * NFSv4 servers do not return entries for '.' and '..' |
| 293 | * Therefore, we fake these entries here. We let '.' |
| 294 | * have cookie 0 and '..' have cookie 1. Note that |
| 295 | * when talking to the server, we always send cookie 0 |
| 296 | * instead of 1 or 2. |
| 297 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 298 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | if (cookie == 0) { |
| 301 | *p++ = xdr_one; /* next */ |
| 302 | *p++ = xdr_zero; /* cookie, first word */ |
| 303 | *p++ = xdr_one; /* cookie, second word */ |
| 304 | *p++ = xdr_one; /* entry len */ |
| 305 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 306 | p++; |
| 307 | *p++ = xdr_one; /* bitmap length */ |
| 308 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 309 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | *p++ = xdr_one; /* next */ |
| 314 | *p++ = xdr_zero; /* cookie, first word */ |
| 315 | *p++ = xdr_two; /* cookie, second word */ |
| 316 | *p++ = xdr_two; /* entry len */ |
| 317 | memcpy(p, "..\0\0", 4); /* entry */ |
| 318 | p++; |
| 319 | *p++ = xdr_one; /* bitmap length */ |
| 320 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 321 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 322 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | readdir->pgbase = (char *)p - (char *)start; |
| 325 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 326 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 329 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 330 | nfs4_stateid *stateid, |
| 331 | struct rpc_cred *cred) |
| 332 | { |
| 333 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 334 | |
| 335 | ops->test_and_free_expired(server, stateid, cred); |
| 336 | } |
| 337 | |
| 338 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 339 | nfs4_stateid *stateid, |
| 340 | struct rpc_cred *cred) |
| 341 | { |
| 342 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 343 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 344 | } |
| 345 | |
| 346 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 347 | const nfs4_stateid *stateid, |
| 348 | struct rpc_cred *cred) |
| 349 | { |
| 350 | nfs4_stateid tmp; |
| 351 | |
| 352 | nfs4_stateid_copy(&tmp, stateid); |
| 353 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 354 | } |
| 355 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 356 | static long nfs4_update_delay(long *timeout) |
| 357 | { |
| 358 | long ret; |
| 359 | if (!timeout) |
| 360 | return NFS4_POLL_RETRY_MAX; |
| 361 | if (*timeout <= 0) |
| 362 | *timeout = NFS4_POLL_RETRY_MIN; |
| 363 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 364 | *timeout = NFS4_POLL_RETRY_MAX; |
| 365 | ret = *timeout; |
| 366 | *timeout <<= 1; |
| 367 | return ret; |
| 368 | } |
| 369 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 370 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 371 | { |
| 372 | int res = 0; |
| 373 | |
| 374 | might_sleep(); |
| 375 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 376 | freezable_schedule_timeout_killable_unsafe( |
| 377 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 378 | if (fatal_signal_pending(current)) |
| 379 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | return res; |
| 381 | } |
| 382 | |
| 383 | /* This is the error handling routine for processes that are allowed |
| 384 | * to sleep. |
| 385 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 386 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 387 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 388 | { |
| 389 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 390 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 391 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 392 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 393 | int ret = errorcode; |
| 394 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 395 | exception->delay = 0; |
| 396 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 397 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 398 | |
| 399 | if (stateid == NULL && state != NULL) |
| 400 | stateid = &state->stateid; |
| 401 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 402 | switch(errorcode) { |
| 403 | case 0: |
| 404 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 405 | case -NFS4ERR_DELEG_REVOKED: |
| 406 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 407 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 408 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 409 | if (inode != NULL && stateid != NULL) { |
| 410 | nfs_inode_find_state_and_recover(inode, |
| 411 | stateid); |
| 412 | goto wait_on_recovery; |
| 413 | } |
| 414 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 415 | if (inode) { |
| 416 | int err; |
| 417 | |
| 418 | err = nfs_async_inode_return_delegation(inode, |
| 419 | stateid); |
| 420 | if (err == 0) |
| 421 | goto wait_on_recovery; |
| 422 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 423 | exception->retry = 1; |
| 424 | break; |
| 425 | } |
| 426 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 427 | if (state == NULL) |
| 428 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 429 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 430 | if (ret < 0) |
| 431 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 432 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 433 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 434 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 435 | nfs4_schedule_lease_recovery(clp); |
| 436 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 437 | case -NFS4ERR_MOVED: |
| 438 | ret = nfs4_schedule_migration_recovery(server); |
| 439 | if (ret < 0) |
| 440 | break; |
| 441 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 442 | case -NFS4ERR_LEASE_MOVED: |
| 443 | nfs4_schedule_lease_moved_recovery(clp); |
| 444 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 445 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 446 | case -NFS4ERR_BADSESSION: |
| 447 | case -NFS4ERR_BADSLOT: |
| 448 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 449 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 450 | case -NFS4ERR_DEADSESSION: |
| 451 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 452 | case -NFS4ERR_SEQ_MISORDERED: |
| 453 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 454 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 455 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 456 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 457 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 458 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 459 | if (exception->timeout > HZ) { |
| 460 | /* We have retried a decent amount, time to |
| 461 | * fail |
| 462 | */ |
| 463 | ret = -EBUSY; |
| 464 | break; |
| 465 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 466 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 467 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 468 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 469 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 470 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 471 | exception->delay = 1; |
| 472 | return 0; |
| 473 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 474 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 475 | case -NFS4ERR_OLD_STATEID: |
| 476 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 477 | break; |
| 478 | case -NFS4ERR_BADOWNER: |
| 479 | /* The following works around a Linux server bug! */ |
| 480 | case -NFS4ERR_BADNAME: |
| 481 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 482 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 483 | exception->retry = 1; |
| 484 | printk(KERN_WARNING "NFS: v4 server %s " |
| 485 | "does not accept raw " |
| 486 | "uid/gids. " |
| 487 | "Reenabling the idmapper.\n", |
| 488 | server->nfs_client->cl_hostname); |
| 489 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 490 | } |
| 491 | /* We failed to handle the error */ |
| 492 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 493 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 494 | exception->recovering = 1; |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* This is the error handling routine for processes that are allowed |
| 499 | * to sleep. |
| 500 | */ |
| 501 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 502 | { |
| 503 | struct nfs_client *clp = server->nfs_client; |
| 504 | int ret; |
| 505 | |
| 506 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 507 | if (exception->delay) { |
| 508 | ret = nfs4_delay(server->client, &exception->timeout); |
| 509 | goto out_retry; |
| 510 | } |
| 511 | if (exception->recovering) { |
| 512 | ret = nfs4_wait_clnt_recover(clp); |
| 513 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 514 | return -EIO; |
| 515 | goto out_retry; |
| 516 | } |
| 517 | return ret; |
| 518 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 519 | if (ret == 0) |
| 520 | exception->retry = 1; |
| 521 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 524 | static int |
| 525 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 526 | int errorcode, struct nfs4_exception *exception) |
| 527 | { |
| 528 | struct nfs_client *clp = server->nfs_client; |
| 529 | int ret; |
| 530 | |
| 531 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 532 | if (exception->delay) { |
| 533 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 534 | goto out_retry; |
| 535 | } |
| 536 | if (exception->recovering) { |
| 537 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 538 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 539 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 540 | goto out_retry; |
| 541 | } |
| 542 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 543 | ret = -EIO; |
| 544 | return ret; |
| 545 | out_retry: |
| 546 | if (ret == 0) |
| 547 | exception->retry = 1; |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | static int |
| 552 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 553 | struct nfs4_state *state, long *timeout) |
| 554 | { |
| 555 | struct nfs4_exception exception = { |
| 556 | .state = state, |
| 557 | }; |
| 558 | |
| 559 | if (task->tk_status >= 0) |
| 560 | return 0; |
| 561 | if (timeout) |
| 562 | exception.timeout = *timeout; |
| 563 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 564 | task->tk_status, |
| 565 | &exception); |
| 566 | if (exception.delay && timeout) |
| 567 | *timeout = exception.timeout; |
| 568 | if (exception.retry) |
| 569 | return -EAGAIN; |
| 570 | return 0; |
| 571 | } |
| 572 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 573 | /* |
| 574 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 575 | * or 'false' otherwise. |
| 576 | */ |
| 577 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 578 | { |
| 579 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 580 | |
| 581 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 582 | flavor == RPC_AUTH_GSS_KRB5P) |
| 583 | return true; |
| 584 | |
| 585 | return false; |
| 586 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 587 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 588 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | spin_lock(&clp->cl_lock); |
| 591 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 592 | clp->cl_last_renewal = timestamp; |
| 593 | spin_unlock(&clp->cl_lock); |
| 594 | } |
| 595 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 596 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 597 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 598 | struct nfs_client *clp = server->nfs_client; |
| 599 | |
| 600 | if (!nfs4_has_session(clp)) |
| 601 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 604 | struct nfs4_call_sync_data { |
| 605 | const struct nfs_server *seq_server; |
| 606 | struct nfs4_sequence_args *seq_args; |
| 607 | struct nfs4_sequence_res *seq_res; |
| 608 | }; |
| 609 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 610 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 611 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 612 | { |
| 613 | args->sa_slot = NULL; |
| 614 | args->sa_cache_this = cache_reply; |
| 615 | args->sa_privileged = 0; |
| 616 | |
| 617 | res->sr_slot = NULL; |
| 618 | } |
| 619 | |
| 620 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 621 | { |
| 622 | args->sa_privileged = 1; |
| 623 | } |
| 624 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 625 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 626 | struct nfs4_sequence_args *args, |
| 627 | struct nfs4_sequence_res *res, |
| 628 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 629 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 630 | struct nfs4_slot *slot; |
| 631 | |
| 632 | /* slot already allocated? */ |
| 633 | if (res->sr_slot != NULL) |
| 634 | goto out_start; |
| 635 | |
| 636 | spin_lock(&tbl->slot_tbl_lock); |
| 637 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 638 | goto out_sleep; |
| 639 | |
| 640 | slot = nfs4_alloc_slot(tbl); |
| 641 | if (IS_ERR(slot)) { |
| 642 | if (slot == ERR_PTR(-ENOMEM)) |
| 643 | task->tk_timeout = HZ >> 2; |
| 644 | goto out_sleep; |
| 645 | } |
| 646 | spin_unlock(&tbl->slot_tbl_lock); |
| 647 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 648 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 649 | args->sa_slot = slot; |
| 650 | res->sr_slot = slot; |
| 651 | |
| 652 | out_start: |
| 653 | rpc_call_start(task); |
| 654 | return 0; |
| 655 | |
| 656 | out_sleep: |
| 657 | if (args->sa_privileged) |
| 658 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 659 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 660 | else |
| 661 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 662 | spin_unlock(&tbl->slot_tbl_lock); |
| 663 | return -EAGAIN; |
| 664 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 665 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 666 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 667 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 668 | { |
| 669 | struct nfs4_slot *slot = res->sr_slot; |
| 670 | struct nfs4_slot_table *tbl; |
| 671 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 672 | tbl = slot->table; |
| 673 | spin_lock(&tbl->slot_tbl_lock); |
| 674 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 675 | nfs4_free_slot(tbl, slot); |
| 676 | spin_unlock(&tbl->slot_tbl_lock); |
| 677 | |
| 678 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static int nfs40_sequence_done(struct rpc_task *task, |
| 682 | struct nfs4_sequence_res *res) |
| 683 | { |
| 684 | if (res->sr_slot != NULL) |
| 685 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 686 | return 1; |
| 687 | } |
| 688 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 689 | #if defined(CONFIG_NFS_V4_1) |
| 690 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 691 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 692 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 693 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 694 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 695 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 696 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 697 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 698 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 699 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 700 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 701 | /* Bump the slot sequence number */ |
| 702 | if (slot->seq_done) |
| 703 | slot->seq_nr++; |
| 704 | slot->seq_done = 0; |
| 705 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 706 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 707 | /* Be nice to the server: try to ensure that the last transmitted |
| 708 | * value for highest_user_slotid <= target_highest_slotid |
| 709 | */ |
| 710 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 711 | send_new_highest_used_slotid = true; |
| 712 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 713 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 714 | send_new_highest_used_slotid = false; |
| 715 | goto out_unlock; |
| 716 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 717 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 718 | |
| 719 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 720 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 721 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 722 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 723 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 724 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 725 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 726 | if (waitqueue_active(&tbl->slot_waitq)) |
| 727 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 730 | static int nfs41_sequence_process(struct rpc_task *task, |
| 731 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 732 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 733 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 734 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 735 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 736 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 737 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 738 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 739 | if (slot == NULL) |
| 740 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 741 | /* don't increment the sequence number if the task wasn't sent */ |
| 742 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 743 | goto out; |
| 744 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 745 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 746 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 747 | if (slot->interrupted) { |
| 748 | slot->interrupted = 0; |
| 749 | interrupted = true; |
| 750 | } |
| 751 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 752 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 753 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 754 | switch (res->sr_status) { |
| 755 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 756 | /* If previous op on slot was interrupted and we reused |
| 757 | * the seq# and got a reply from the cache, then retry |
| 758 | */ |
| 759 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 760 | ++slot->seq_nr; |
| 761 | goto retry_nowait; |
| 762 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 763 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 764 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 765 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 766 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 767 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 768 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 769 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 770 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 771 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 772 | case 1: |
| 773 | /* |
| 774 | * sr_status remains 1 if an RPC level error occurred. |
| 775 | * The server may or may not have processed the sequence |
| 776 | * operation.. |
| 777 | * Mark the slot as having hosted an interrupted RPC call. |
| 778 | */ |
| 779 | slot->interrupted = 1; |
| 780 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 781 | case -NFS4ERR_DELAY: |
| 782 | /* The server detected a resend of the RPC call and |
| 783 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 784 | * of RFC5661. |
| 785 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 786 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 787 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 788 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 789 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 790 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 791 | case -NFS4ERR_BADSLOT: |
| 792 | /* |
| 793 | * The slot id we used was probably retired. Try again |
| 794 | * using a different slot id. |
| 795 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 796 | goto retry_nowait; |
| 797 | case -NFS4ERR_SEQ_MISORDERED: |
| 798 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 799 | * Was the last operation on this sequence interrupted? |
| 800 | * If so, retry after bumping the sequence number. |
| 801 | */ |
| 802 | if (interrupted) { |
| 803 | ++slot->seq_nr; |
| 804 | goto retry_nowait; |
| 805 | } |
| 806 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 807 | * Could this slot have been previously retired? |
| 808 | * If so, then the server may be expecting seq_nr = 1! |
| 809 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 810 | if (slot->seq_nr != 1) { |
| 811 | slot->seq_nr = 1; |
| 812 | goto retry_nowait; |
| 813 | } |
| 814 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 815 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 816 | ++slot->seq_nr; |
| 817 | goto retry_nowait; |
Trond Myklebust | 2cf10cd | 2016-12-04 19:26:40 -0500 | [diff] [blame] | 818 | case -NFS4ERR_DEADSESSION: |
| 819 | case -NFS4ERR_BADSESSION: |
| 820 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 821 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 822 | default: |
| 823 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 824 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 825 | } |
| 826 | out: |
| 827 | /* The session may be reset by one of the error handlers. */ |
| 828 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 829 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 830 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 831 | retry_nowait: |
| 832 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 833 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 834 | task->tk_status = 0; |
| 835 | ret = 0; |
| 836 | } |
| 837 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 838 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 839 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 840 | goto out; |
| 841 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 842 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 843 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 844 | |
| 845 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 846 | { |
| 847 | if (!nfs41_sequence_process(task, res)) |
| 848 | return 0; |
| 849 | if (res->sr_slot != NULL) |
| 850 | nfs41_sequence_free_slot(res); |
| 851 | return 1; |
| 852 | |
| 853 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 854 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 855 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 856 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 857 | { |
| 858 | if (res->sr_slot == NULL) |
| 859 | return 1; |
| 860 | if (res->sr_slot->table->session != NULL) |
| 861 | return nfs41_sequence_process(task, res); |
| 862 | return nfs40_sequence_done(task, res); |
| 863 | } |
| 864 | |
| 865 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 866 | { |
| 867 | if (res->sr_slot != NULL) { |
| 868 | if (res->sr_slot->table->session != NULL) |
| 869 | nfs41_sequence_free_slot(res); |
| 870 | else |
| 871 | nfs40_sequence_free_slot(res); |
| 872 | } |
| 873 | } |
| 874 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 875 | 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] | 876 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 877 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 878 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 879 | if (!res->sr_slot->table->session) |
| 880 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 881 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 882 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 883 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 884 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 885 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 886 | struct nfs4_sequence_args *args, |
| 887 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 888 | struct rpc_task *task) |
| 889 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 890 | struct nfs4_slot *slot; |
| 891 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 892 | |
| 893 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 894 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 895 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 896 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 898 | tbl = &session->fc_slot_table; |
| 899 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 900 | task->tk_timeout = 0; |
| 901 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 902 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 903 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 904 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 905 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 906 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 907 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 908 | } |
| 909 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 910 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 911 | if (IS_ERR(slot)) { |
| 912 | /* If out of memory, try again in 1/4 second */ |
| 913 | if (slot == ERR_PTR(-ENOMEM)) |
| 914 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 915 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 916 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 917 | } |
| 918 | spin_unlock(&tbl->slot_tbl_lock); |
| 919 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 920 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 921 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 922 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 923 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 924 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 925 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 926 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 927 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 928 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 929 | /* |
| 930 | * sr_status is only set in decode_sequence, and so will remain |
| 931 | * set to 1 if an rpc level failure occurs. |
| 932 | */ |
| 933 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 934 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 935 | out_success: |
| 936 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 937 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 938 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 939 | /* Privileged tasks are queued with top priority */ |
| 940 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 941 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 942 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 943 | else |
| 944 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 945 | spin_unlock(&tbl->slot_tbl_lock); |
| 946 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 947 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 948 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 949 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 950 | static int nfs4_setup_sequence(const struct nfs_client *client, |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 951 | struct nfs4_sequence_args *args, |
| 952 | struct nfs4_sequence_res *res, |
| 953 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 954 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 955 | struct nfs4_session *session = nfs4_get_session(client); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 956 | int ret = 0; |
| 957 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 958 | if (!session) |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 959 | return nfs40_setup_sequence(client->cl_slot_tbl, |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 960 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 961 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 962 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 963 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 964 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 965 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 966 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 967 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 968 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 969 | return ret; |
| 970 | } |
| 971 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 972 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 973 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 974 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 172d9de | 2015-05-14 10:56:10 -0400 | [diff] [blame] | 975 | struct nfs4_session *session = nfs4_get_session(data->seq_server->nfs_client); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 976 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 977 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 978 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 979 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 980 | } |
| 981 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 982 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 983 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 984 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 985 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 986 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 987 | } |
| 988 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 989 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 990 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 991 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 992 | }; |
| 993 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 994 | #else /* !CONFIG_NFS_V4_1 */ |
| 995 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 996 | static int nfs4_setup_sequence(const struct nfs_client *client, |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 997 | struct nfs4_sequence_args *args, |
| 998 | struct nfs4_sequence_res *res, |
| 999 | struct rpc_task *task) |
| 1000 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 1001 | return nfs40_setup_sequence(client->cl_slot_tbl, args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 1002 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1003 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1004 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1005 | { |
| 1006 | return nfs40_sequence_done(task, res); |
| 1007 | } |
| 1008 | |
| 1009 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1010 | { |
| 1011 | if (res->sr_slot != NULL) |
| 1012 | nfs40_sequence_free_slot(res); |
| 1013 | } |
| 1014 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1015 | int nfs4_sequence_done(struct rpc_task *task, |
| 1016 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1017 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1018 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1019 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1020 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1021 | |
| 1022 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1023 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1024 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1025 | { |
| 1026 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 1027 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1028 | data->seq_args, data->seq_res, task); |
| 1029 | } |
| 1030 | |
| 1031 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1032 | { |
| 1033 | struct nfs4_call_sync_data *data = calldata; |
| 1034 | nfs4_sequence_done(task, data->seq_res); |
| 1035 | } |
| 1036 | |
| 1037 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1038 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1039 | .rpc_call_done = nfs40_call_sync_done, |
| 1040 | }; |
| 1041 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1042 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1043 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1044 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1045 | struct nfs4_sequence_args *args, |
| 1046 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1047 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1048 | int ret; |
| 1049 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1050 | struct nfs_client *clp = server->nfs_client; |
| 1051 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1052 | .seq_server = server, |
| 1053 | .seq_args = args, |
| 1054 | .seq_res = res, |
| 1055 | }; |
| 1056 | struct rpc_task_setup task_setup = { |
| 1057 | .rpc_client = clnt, |
| 1058 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1059 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1060 | .callback_data = &data |
| 1061 | }; |
| 1062 | |
| 1063 | task = rpc_run_task(&task_setup); |
| 1064 | if (IS_ERR(task)) |
| 1065 | ret = PTR_ERR(task); |
| 1066 | else { |
| 1067 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1068 | rpc_put_task(task); |
| 1069 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1070 | return ret; |
| 1071 | } |
| 1072 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1073 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1074 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1075 | struct rpc_message *msg, |
| 1076 | struct nfs4_sequence_args *args, |
| 1077 | struct nfs4_sequence_res *res, |
| 1078 | int cache_reply) |
| 1079 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1080 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1081 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1084 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1085 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | { |
| 1087 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1088 | |
| 1089 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1090 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1091 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1092 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1093 | nfsi->attrtimeo_timestamp = jiffies; |
| 1094 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1096 | if (cinfo->before != dir->i_version) |
| 1097 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1098 | NFS_INO_INVALID_ACL; |
| 1099 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1100 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1101 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1102 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1103 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | spin_unlock(&dir->i_lock); |
| 1105 | } |
| 1106 | |
| 1107 | struct nfs4_opendata { |
| 1108 | struct kref kref; |
| 1109 | struct nfs_openargs o_arg; |
| 1110 | struct nfs_openres o_res; |
| 1111 | struct nfs_open_confirmargs c_arg; |
| 1112 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1113 | struct nfs4_string owner_name; |
| 1114 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1115 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1117 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1119 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | struct nfs4_state_owner *owner; |
| 1121 | struct nfs4_state *state; |
| 1122 | struct iattr attrs; |
| 1123 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1124 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1125 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1126 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1127 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | int cancelled; |
| 1129 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1130 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1131 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1132 | int err, struct nfs4_exception *exception) |
| 1133 | { |
| 1134 | if (err != -EINVAL) |
| 1135 | return false; |
| 1136 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1137 | return false; |
| 1138 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1139 | exception->retry = 1; |
| 1140 | return true; |
| 1141 | } |
| 1142 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1143 | static u32 |
| 1144 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1145 | fmode_t fmode, int openflags) |
| 1146 | { |
| 1147 | u32 res = 0; |
| 1148 | |
| 1149 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1150 | case FMODE_READ: |
| 1151 | res = NFS4_SHARE_ACCESS_READ; |
| 1152 | break; |
| 1153 | case FMODE_WRITE: |
| 1154 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1155 | break; |
| 1156 | case FMODE_READ|FMODE_WRITE: |
| 1157 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1158 | } |
| 1159 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1160 | goto out; |
| 1161 | /* Want no delegation if we're using O_DIRECT */ |
| 1162 | if (openflags & O_DIRECT) |
| 1163 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1164 | out: |
| 1165 | return res; |
| 1166 | } |
| 1167 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1168 | static enum open_claim_type4 |
| 1169 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1170 | enum open_claim_type4 claim) |
| 1171 | { |
| 1172 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1173 | return claim; |
| 1174 | switch (claim) { |
| 1175 | default: |
| 1176 | return claim; |
| 1177 | case NFS4_OPEN_CLAIM_FH: |
| 1178 | return NFS4_OPEN_CLAIM_NULL; |
| 1179 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1180 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1181 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1182 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1183 | } |
| 1184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
| 1186 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1187 | { |
| 1188 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1189 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1190 | p->o_res.seqid = p->o_arg.seqid; |
| 1191 | p->c_res.seqid = p->c_arg.seqid; |
| 1192 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1193 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1194 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1195 | 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] | 1196 | } |
| 1197 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1198 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1199 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1200 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1201 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1202 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1203 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1204 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1205 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1206 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1207 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1208 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1209 | struct nfs4_opendata *p; |
| 1210 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1211 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1212 | if (p == NULL) |
| 1213 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1214 | |
| 1215 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1216 | if (IS_ERR(p->f_label)) |
| 1217 | goto err_free_p; |
| 1218 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1219 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1220 | if (IS_ERR(p->a_label)) |
| 1221 | goto err_free_f; |
| 1222 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1223 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1224 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1225 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1226 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1227 | nfs_sb_active(dentry->d_sb); |
| 1228 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1229 | p->dir = parent; |
| 1230 | p->owner = sp; |
| 1231 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1232 | p->o_arg.open_flags = flags; |
| 1233 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1234 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1235 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1236 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1237 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1238 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1239 | * will return permission denied for all bits until close */ |
| 1240 | if (!(flags & O_EXCL)) { |
| 1241 | /* ask server to check for all possible rights as results |
| 1242 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1243 | switch (p->o_arg.claim) { |
| 1244 | default: |
| 1245 | break; |
| 1246 | case NFS4_OPEN_CLAIM_NULL: |
| 1247 | case NFS4_OPEN_CLAIM_FH: |
| 1248 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1249 | NFS4_ACCESS_MODIFY | |
| 1250 | NFS4_ACCESS_EXTEND | |
| 1251 | NFS4_ACCESS_EXECUTE; |
| 1252 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1253 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1254 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1255 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1256 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1257 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1258 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1259 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1260 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1261 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1262 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1263 | case NFS4_OPEN_CLAIM_NULL: |
| 1264 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1265 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1266 | p->o_arg.fh = NFS_FH(dir); |
| 1267 | break; |
| 1268 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1269 | case NFS4_OPEN_CLAIM_FH: |
| 1270 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1271 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1272 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1273 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1274 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1275 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1276 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1277 | p->o_arg.u.attrs = &p->attrs; |
| 1278 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1279 | |
| 1280 | verf[0] = jiffies; |
| 1281 | verf[1] = current->pid; |
| 1282 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1283 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1284 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1285 | p->c_arg.fh = &p->o_res.fh; |
| 1286 | p->c_arg.stateid = &p->o_res.stateid; |
| 1287 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1288 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1289 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1290 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1291 | |
| 1292 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1293 | nfs4_label_free(p->a_label); |
| 1294 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1295 | nfs4_label_free(p->f_label); |
| 1296 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1297 | kfree(p); |
| 1298 | err: |
| 1299 | dput(parent); |
| 1300 | return NULL; |
| 1301 | } |
| 1302 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1303 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1304 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1305 | struct nfs4_opendata *p = container_of(kref, |
| 1306 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1307 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1308 | |
| 1309 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1310 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1311 | if (p->state != NULL) |
| 1312 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1313 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1314 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1315 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1316 | nfs4_label_free(p->f_label); |
| 1317 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1318 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1319 | dput(p->dentry); |
| 1320 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1321 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1322 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1323 | kfree(p); |
| 1324 | } |
| 1325 | |
| 1326 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1327 | { |
| 1328 | if (p != NULL) |
| 1329 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1332 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1333 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1334 | int ret; |
| 1335 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1336 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1337 | return ret; |
| 1338 | } |
| 1339 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1340 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1341 | fmode_t fmode) |
| 1342 | { |
| 1343 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1344 | case FMODE_READ|FMODE_WRITE: |
| 1345 | return state->n_rdwr != 0; |
| 1346 | case FMODE_WRITE: |
| 1347 | return state->n_wronly != 0; |
| 1348 | case FMODE_READ: |
| 1349 | return state->n_rdonly != 0; |
| 1350 | } |
| 1351 | WARN_ON_ONCE(1); |
| 1352 | return false; |
| 1353 | } |
| 1354 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | 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] | 1356 | { |
| 1357 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1358 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1359 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1360 | goto out; |
| 1361 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1362 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1363 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1364 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1365 | break; |
| 1366 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1367 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1368 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1369 | break; |
| 1370 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1371 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1372 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1373 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1374 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1375 | return ret; |
| 1376 | } |
| 1377 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1378 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1379 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1380 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1381 | if (delegation == NULL) |
| 1382 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1383 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1384 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1385 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1386 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1387 | switch (claim) { |
| 1388 | case NFS4_OPEN_CLAIM_NULL: |
| 1389 | case NFS4_OPEN_CLAIM_FH: |
| 1390 | break; |
| 1391 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1392 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1393 | break; |
| 1394 | default: |
| 1395 | return 0; |
| 1396 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1397 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1398 | return 1; |
| 1399 | } |
| 1400 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1401 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1402 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1403 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1404 | case FMODE_WRITE: |
| 1405 | state->n_wronly++; |
| 1406 | break; |
| 1407 | case FMODE_READ: |
| 1408 | state->n_rdonly++; |
| 1409 | break; |
| 1410 | case FMODE_READ|FMODE_WRITE: |
| 1411 | state->n_rdwr++; |
| 1412 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1413 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1414 | } |
| 1415 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1416 | #ifdef CONFIG_NFS_V4_1 |
| 1417 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1418 | { |
| 1419 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1420 | return true; |
| 1421 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1422 | return true; |
| 1423 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1424 | return true; |
| 1425 | return false; |
| 1426 | } |
| 1427 | #endif /* CONFIG_NFS_V4_1 */ |
| 1428 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1429 | 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] | 1430 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1431 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1432 | bool need_recover = false; |
| 1433 | |
| 1434 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1435 | need_recover = true; |
| 1436 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1437 | need_recover = true; |
| 1438 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1439 | need_recover = true; |
| 1440 | if (need_recover) |
| 1441 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1442 | } |
| 1443 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1444 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1445 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1446 | { |
| 1447 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1448 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1449 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1450 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1451 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1452 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1453 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1454 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1455 | return true; |
| 1456 | return false; |
| 1457 | } |
| 1458 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1459 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1460 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1461 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1462 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1463 | if (state->n_wronly) |
| 1464 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1465 | if (state->n_rdonly) |
| 1466 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1467 | if (state->n_rdwr) |
| 1468 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1469 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1470 | } |
| 1471 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1472 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1473 | nfs4_stateid *stateid, fmode_t fmode) |
| 1474 | { |
| 1475 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1476 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1477 | case FMODE_WRITE: |
| 1478 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1479 | break; |
| 1480 | case FMODE_READ: |
| 1481 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1482 | break; |
| 1483 | case 0: |
| 1484 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1485 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1486 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1487 | } |
| 1488 | if (stateid == NULL) |
| 1489 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1490 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1491 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1492 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1493 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1494 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1495 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1496 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1497 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1498 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1501 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1502 | nfs4_stateid *arg_stateid, |
| 1503 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1504 | { |
| 1505 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1506 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1507 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1508 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1509 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1510 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1511 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1512 | } |
| 1513 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1514 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1515 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1516 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1517 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1518 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1519 | case FMODE_READ: |
| 1520 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1521 | break; |
| 1522 | case FMODE_WRITE: |
| 1523 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1524 | break; |
| 1525 | case FMODE_READ|FMODE_WRITE: |
| 1526 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1527 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1528 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1529 | return; |
| 1530 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1531 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1532 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1533 | } |
| 1534 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1535 | static void __update_open_stateid(struct nfs4_state *state, |
| 1536 | const nfs4_stateid *open_stateid, |
| 1537 | const nfs4_stateid *deleg_stateid, |
| 1538 | fmode_t fmode, |
| 1539 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1541 | /* |
| 1542 | * Protect the call to nfs4_state_set_mode_locked and |
| 1543 | * serialise the stateid update |
| 1544 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1545 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1546 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1547 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1548 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1549 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1550 | } |
| 1551 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1552 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1553 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1554 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1555 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1558 | static int update_open_stateid(struct nfs4_state *state, |
| 1559 | const nfs4_stateid *open_stateid, |
| 1560 | const nfs4_stateid *delegation, |
| 1561 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1562 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1563 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1564 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1565 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1566 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1567 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1568 | int ret = 0; |
| 1569 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1570 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1571 | |
| 1572 | rcu_read_lock(); |
| 1573 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1574 | if (deleg_cur == NULL) |
| 1575 | goto no_delegation; |
| 1576 | |
| 1577 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1578 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1579 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1580 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1581 | goto no_delegation_unlock; |
| 1582 | |
| 1583 | if (delegation == NULL) |
| 1584 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1585 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1586 | goto no_delegation_unlock; |
| 1587 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1588 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1589 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1590 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1591 | ret = 1; |
| 1592 | no_delegation_unlock: |
| 1593 | spin_unlock(&deleg_cur->lock); |
| 1594 | no_delegation: |
| 1595 | rcu_read_unlock(); |
| 1596 | |
| 1597 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1598 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1599 | ret = 1; |
| 1600 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1601 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1602 | nfs4_schedule_state_manager(clp); |
| 1603 | if (freeme.type != 0) |
| 1604 | nfs4_test_and_free_stateid(server, &freeme, |
| 1605 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1606 | |
| 1607 | return ret; |
| 1608 | } |
| 1609 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1610 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1611 | const nfs4_stateid *stateid) |
| 1612 | { |
| 1613 | struct nfs4_state *state = lsp->ls_state; |
| 1614 | bool ret = false; |
| 1615 | |
| 1616 | spin_lock(&state->state_lock); |
| 1617 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1618 | goto out_noupdate; |
| 1619 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1620 | goto out_noupdate; |
| 1621 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1622 | ret = true; |
| 1623 | out_noupdate: |
| 1624 | spin_unlock(&state->state_lock); |
| 1625 | return ret; |
| 1626 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1627 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1628 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1629 | { |
| 1630 | struct nfs_delegation *delegation; |
| 1631 | |
| 1632 | rcu_read_lock(); |
| 1633 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1634 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1635 | rcu_read_unlock(); |
| 1636 | return; |
| 1637 | } |
| 1638 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1639 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1642 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1643 | { |
| 1644 | struct nfs4_state *state = opendata->state; |
| 1645 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1646 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1647 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1648 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1649 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1650 | nfs4_stateid stateid; |
| 1651 | int ret = -EAGAIN; |
| 1652 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1653 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1654 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1655 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1656 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1657 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1658 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1659 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1660 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1661 | rcu_read_lock(); |
| 1662 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1663 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1664 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1665 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1666 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1667 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1668 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1669 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1670 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1671 | if (!opendata->is_recover) { |
| 1672 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1673 | if (ret != 0) |
| 1674 | goto out; |
| 1675 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1676 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1677 | |
| 1678 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1679 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1680 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1681 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1682 | out: |
| 1683 | return ERR_PTR(ret); |
| 1684 | out_return_state: |
| 1685 | atomic_inc(&state->count); |
| 1686 | return state; |
| 1687 | } |
| 1688 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1689 | static void |
| 1690 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1691 | { |
| 1692 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1693 | struct nfs_delegation *delegation; |
| 1694 | int delegation_flags = 0; |
| 1695 | |
| 1696 | rcu_read_lock(); |
| 1697 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1698 | if (delegation) |
| 1699 | delegation_flags = delegation->flags; |
| 1700 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1701 | switch (data->o_arg.claim) { |
| 1702 | default: |
| 1703 | break; |
| 1704 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1705 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1706 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1707 | "returning a delegation for " |
| 1708 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1709 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1710 | return; |
| 1711 | } |
| 1712 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1713 | nfs_inode_set_delegation(state->inode, |
| 1714 | data->owner->so_cred, |
| 1715 | &data->o_res); |
| 1716 | else |
| 1717 | nfs_inode_reclaim_delegation(state->inode, |
| 1718 | data->owner->so_cred, |
| 1719 | &data->o_res); |
| 1720 | } |
| 1721 | |
| 1722 | /* |
| 1723 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1724 | * and update the nfs4_state. |
| 1725 | */ |
| 1726 | static struct nfs4_state * |
| 1727 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1728 | { |
| 1729 | struct inode *inode = data->state->inode; |
| 1730 | struct nfs4_state *state = data->state; |
| 1731 | int ret; |
| 1732 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1733 | if (!data->rpc_done) { |
| 1734 | if (data->rpc_status) { |
| 1735 | ret = data->rpc_status; |
| 1736 | goto err; |
| 1737 | } |
| 1738 | /* cached opens have already been processed */ |
| 1739 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1742 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1743 | if (ret) |
| 1744 | goto err; |
| 1745 | |
| 1746 | if (data->o_res.delegation_type != 0) |
| 1747 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1748 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1749 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1750 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1751 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1752 | |
| 1753 | return state; |
| 1754 | err: |
| 1755 | return ERR_PTR(ret); |
| 1756 | |
| 1757 | } |
| 1758 | |
| 1759 | static struct nfs4_state * |
| 1760 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1761 | { |
| 1762 | struct inode *inode; |
| 1763 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1764 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1765 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1766 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1767 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1768 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1769 | goto out; |
| 1770 | } |
| 1771 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1772 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1773 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1774 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1775 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr, data->f_label); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1776 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1777 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1778 | goto err; |
| 1779 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1780 | state = nfs4_get_open_state(inode, data->owner); |
| 1781 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1782 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1783 | if (data->o_res.delegation_type != 0) |
| 1784 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1785 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1786 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1787 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1788 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1789 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1790 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1791 | err_put_inode: |
| 1792 | iput(inode); |
| 1793 | err: |
| 1794 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1797 | static struct nfs4_state * |
| 1798 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1799 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1800 | struct nfs4_state *ret; |
| 1801 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1802 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1803 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1804 | else |
| 1805 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1806 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1807 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1810 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1811 | { |
| 1812 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1813 | struct nfs_open_context *ctx; |
| 1814 | |
| 1815 | spin_lock(&state->inode->i_lock); |
| 1816 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1817 | if (ctx->state != state) |
| 1818 | continue; |
| 1819 | get_nfs_open_context(ctx); |
| 1820 | spin_unlock(&state->inode->i_lock); |
| 1821 | return ctx; |
| 1822 | } |
| 1823 | spin_unlock(&state->inode->i_lock); |
| 1824 | return ERR_PTR(-ENOENT); |
| 1825 | } |
| 1826 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1827 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1828 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1829 | { |
| 1830 | struct nfs4_opendata *opendata; |
| 1831 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1832 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1833 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1834 | if (opendata == NULL) |
| 1835 | return ERR_PTR(-ENOMEM); |
| 1836 | opendata->state = state; |
| 1837 | atomic_inc(&state->count); |
| 1838 | return opendata; |
| 1839 | } |
| 1840 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1841 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1842 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1843 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1844 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1845 | int ret; |
| 1846 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1847 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1848 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1849 | opendata->o_arg.open_flags = 0; |
| 1850 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1851 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1852 | NFS_SB(opendata->dentry->d_sb), |
| 1853 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1854 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1855 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1856 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1857 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1858 | if (ret != 0) |
| 1859 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1860 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1861 | if (IS_ERR(newstate)) |
| 1862 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1863 | if (newstate != opendata->state) |
| 1864 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1865 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1866 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1870 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1871 | int ret; |
| 1872 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1873 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1874 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1875 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1876 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1877 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1878 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1879 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1880 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1881 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1882 | if (ret != 0) |
| 1883 | return ret; |
| 1884 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1885 | if (ret != 0) |
| 1886 | return ret; |
| 1887 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1888 | if (ret != 0) |
| 1889 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1890 | /* |
| 1891 | * We may have performed cached opens for all three recoveries. |
| 1892 | * Check if we need to update the current stateid. |
| 1893 | */ |
| 1894 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1895 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1896 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1897 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1898 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1899 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1900 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1901 | return 0; |
| 1902 | } |
| 1903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | /* |
| 1905 | * OPEN_RECLAIM: |
| 1906 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1908 | 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] | 1909 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1910 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1911 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1912 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | int status; |
| 1914 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1915 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1916 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1917 | if (IS_ERR(opendata)) |
| 1918 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1919 | rcu_read_lock(); |
| 1920 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1921 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1922 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1923 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1924 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1925 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1926 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | return status; |
| 1928 | } |
| 1929 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1930 | 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] | 1931 | { |
| 1932 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1933 | struct nfs4_exception exception = { }; |
| 1934 | int err; |
| 1935 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1936 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1937 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1938 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1939 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1940 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1941 | break; |
| 1942 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } while (exception.retry); |
| 1944 | return err; |
| 1945 | } |
| 1946 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1947 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1948 | { |
| 1949 | struct nfs_open_context *ctx; |
| 1950 | int ret; |
| 1951 | |
| 1952 | ctx = nfs4_state_find_open_context(state); |
| 1953 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1954 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1955 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1956 | put_nfs_open_context(ctx); |
| 1957 | return ret; |
| 1958 | } |
| 1959 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1960 | 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] | 1961 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1962 | switch (err) { |
| 1963 | default: |
| 1964 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1965 | "%d.\n", __func__, err); |
| 1966 | case 0: |
| 1967 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1968 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1969 | case -ESTALE: |
| 1970 | break; |
| 1971 | case -NFS4ERR_BADSESSION: |
| 1972 | case -NFS4ERR_BADSLOT: |
| 1973 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1974 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1975 | case -NFS4ERR_DEADSESSION: |
| 1976 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1977 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1978 | return -EAGAIN; |
| 1979 | case -NFS4ERR_STALE_CLIENTID: |
| 1980 | case -NFS4ERR_STALE_STATEID: |
| 1981 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1982 | /* Don't recall a delegation if it was lost */ |
| 1983 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1984 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1985 | case -NFS4ERR_MOVED: |
| 1986 | nfs4_schedule_migration_recovery(server); |
| 1987 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1988 | case -NFS4ERR_LEASE_MOVED: |
| 1989 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1990 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1991 | case -NFS4ERR_DELEG_REVOKED: |
| 1992 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1993 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1994 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1995 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1996 | nfs_inode_find_state_and_recover(state->inode, |
| 1997 | stateid); |
| 1998 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1999 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2000 | case -NFS4ERR_DELAY: |
| 2001 | case -NFS4ERR_GRACE: |
| 2002 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2003 | ssleep(1); |
| 2004 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2005 | case -ENOMEM: |
| 2006 | case -NFS4ERR_DENIED: |
| 2007 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 2008 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | return err; |
| 2011 | } |
| 2012 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2013 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2014 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2015 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2016 | { |
| 2017 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2018 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2019 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2020 | |
| 2021 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2022 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2023 | if (IS_ERR(opendata)) |
| 2024 | return PTR_ERR(opendata); |
| 2025 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2026 | write_seqlock(&state->seqlock); |
| 2027 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2028 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2029 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2030 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2031 | case FMODE_READ|FMODE_WRITE: |
| 2032 | case FMODE_WRITE: |
| 2033 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2034 | if (err) |
| 2035 | break; |
| 2036 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2037 | if (err) |
| 2038 | break; |
| 2039 | case FMODE_READ: |
| 2040 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2041 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2042 | nfs4_opendata_put(opendata); |
| 2043 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2044 | } |
| 2045 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2046 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2047 | { |
| 2048 | struct nfs4_opendata *data = calldata; |
| 2049 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2050 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2051 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2052 | } |
| 2053 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2054 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2055 | { |
| 2056 | struct nfs4_opendata *data = calldata; |
| 2057 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2058 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2059 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2060 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2061 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2062 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2063 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2064 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2065 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2066 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | static void nfs4_open_confirm_release(void *calldata) |
| 2070 | { |
| 2071 | struct nfs4_opendata *data = calldata; |
| 2072 | struct nfs4_state *state = NULL; |
| 2073 | |
| 2074 | /* If this request hasn't been cancelled, do nothing */ |
| 2075 | if (data->cancelled == 0) |
| 2076 | goto out_free; |
| 2077 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2078 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2079 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2080 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2081 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2082 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2083 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2084 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2088 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2089 | .rpc_call_done = nfs4_open_confirm_done, |
| 2090 | .rpc_release = nfs4_open_confirm_release, |
| 2091 | }; |
| 2092 | |
| 2093 | /* |
| 2094 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2095 | */ |
| 2096 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2097 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2098 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2099 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2100 | struct rpc_message msg = { |
| 2101 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2102 | .rpc_argp = &data->c_arg, |
| 2103 | .rpc_resp = &data->c_res, |
| 2104 | .rpc_cred = data->owner->so_cred, |
| 2105 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2106 | struct rpc_task_setup task_setup_data = { |
| 2107 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2108 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2109 | .callback_ops = &nfs4_open_confirm_ops, |
| 2110 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2111 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2112 | .flags = RPC_TASK_ASYNC, |
| 2113 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | int status; |
| 2115 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2116 | 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] | 2117 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2118 | data->rpc_done = 0; |
| 2119 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2120 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2121 | if (data->is_recover) |
| 2122 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2123 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2124 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2125 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2126 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2127 | if (status != 0) { |
| 2128 | data->cancelled = 1; |
| 2129 | smp_wmb(); |
| 2130 | } else |
| 2131 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2132 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | return status; |
| 2134 | } |
| 2135 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2136 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2138 | struct nfs4_opendata *data = calldata; |
| 2139 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2140 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2141 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2142 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2144 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2145 | /* |
| 2146 | * Check if we still need to send an OPEN call, or if we can use |
| 2147 | * a delegation instead. |
| 2148 | */ |
| 2149 | if (data->state != NULL) { |
| 2150 | struct nfs_delegation *delegation; |
| 2151 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2152 | 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] | 2153 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2154 | rcu_read_lock(); |
| 2155 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2156 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2157 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2158 | rcu_read_unlock(); |
| 2159 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2160 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2161 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2162 | switch (claim) { |
| 2163 | default: |
| 2164 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2165 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2166 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2167 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2168 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2169 | case NFS4_OPEN_CLAIM_FH: |
| 2170 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2171 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2172 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2173 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 2174 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2175 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2176 | &data->o_res.seq_res, |
| 2177 | task) != 0) |
| 2178 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2179 | |
| 2180 | /* Set the create mode (note dependency on the session type) */ |
| 2181 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2182 | if (data->o_arg.open_flags & O_EXCL) { |
| 2183 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2184 | if (nfs4_has_persistent_session(clp)) |
| 2185 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2186 | else if (clp->cl_mvops->minor_version > 0) |
| 2187 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2188 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2189 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2190 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2191 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2192 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2193 | out_no_action: |
| 2194 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2195 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2196 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2197 | } |
| 2198 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2199 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2200 | { |
| 2201 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2203 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2204 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2205 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2206 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2207 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2208 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2209 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2210 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2211 | case S_IFREG: |
| 2212 | break; |
| 2213 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2214 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2215 | break; |
| 2216 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2217 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2218 | break; |
| 2219 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2220 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2221 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2222 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2223 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2224 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2225 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2226 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2227 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2228 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2229 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2230 | static void nfs4_open_release(void *calldata) |
| 2231 | { |
| 2232 | struct nfs4_opendata *data = calldata; |
| 2233 | struct nfs4_state *state = NULL; |
| 2234 | |
| 2235 | /* If this request hasn't been cancelled, do nothing */ |
| 2236 | if (data->cancelled == 0) |
| 2237 | goto out_free; |
| 2238 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2239 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2240 | goto out_free; |
| 2241 | /* In case we need an open_confirm, no cleanup! */ |
| 2242 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2243 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2244 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2245 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2246 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2247 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2248 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2252 | .rpc_call_prepare = nfs4_open_prepare, |
| 2253 | .rpc_call_done = nfs4_open_done, |
| 2254 | .rpc_release = nfs4_open_release, |
| 2255 | }; |
| 2256 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2257 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2258 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2259 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2260 | struct nfs_server *server = NFS_SERVER(dir); |
| 2261 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2262 | struct nfs_openres *o_res = &data->o_res; |
| 2263 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2264 | struct rpc_message msg = { |
| 2265 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2266 | .rpc_argp = o_arg, |
| 2267 | .rpc_resp = o_res, |
| 2268 | .rpc_cred = data->owner->so_cred, |
| 2269 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2270 | struct rpc_task_setup task_setup_data = { |
| 2271 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2272 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2273 | .callback_ops = &nfs4_open_ops, |
| 2274 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2275 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2276 | .flags = RPC_TASK_ASYNC, |
| 2277 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2278 | int status; |
| 2279 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2280 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2281 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2282 | data->rpc_done = 0; |
| 2283 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2284 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2285 | data->is_recover = 0; |
| 2286 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2287 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2288 | data->is_recover = 1; |
| 2289 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2290 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2291 | if (IS_ERR(task)) |
| 2292 | return PTR_ERR(task); |
| 2293 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2294 | if (status != 0) { |
| 2295 | data->cancelled = 1; |
| 2296 | smp_wmb(); |
| 2297 | } else |
| 2298 | status = data->rpc_status; |
| 2299 | rpc_put_task(task); |
| 2300 | |
| 2301 | return status; |
| 2302 | } |
| 2303 | |
| 2304 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2305 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2306 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2307 | struct nfs_openres *o_res = &data->o_res; |
| 2308 | int status; |
| 2309 | |
| 2310 | status = nfs4_run_open_task(data, 1); |
| 2311 | if (status != 0 || !data->rpc_done) |
| 2312 | return status; |
| 2313 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2314 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2315 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2316 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2317 | status = _nfs4_proc_open_confirm(data); |
| 2318 | if (status != 0) |
| 2319 | return status; |
| 2320 | } |
| 2321 | |
| 2322 | return status; |
| 2323 | } |
| 2324 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2325 | /* |
| 2326 | * Additional permission checks in order to distinguish between an |
| 2327 | * open for read, and an open for execute. This works around the |
| 2328 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2329 | * the same. |
| 2330 | * Note that in the non-execute case, we want to turn off permission |
| 2331 | * checking if we just created a new file (POSIX open() semantics). |
| 2332 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2333 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2334 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2335 | struct nfs4_state *state, fmode_t fmode, |
| 2336 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2337 | { |
| 2338 | struct nfs_access_entry cache; |
| 2339 | u32 mask; |
| 2340 | |
| 2341 | /* access call failed or for some reason the server doesn't |
| 2342 | * support any access modes -- defer access call until later */ |
| 2343 | if (opendata->o_res.access_supported == 0) |
| 2344 | return 0; |
| 2345 | |
| 2346 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2347 | /* |
| 2348 | * Use openflags to check for exec, because fmode won't |
| 2349 | * always have FMODE_EXEC set when file open for exec. |
| 2350 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2351 | if (openflags & __FMODE_EXEC) { |
| 2352 | /* ONLY check for exec rights */ |
| 2353 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2354 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2355 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2356 | |
| 2357 | cache.cred = cred; |
| 2358 | cache.jiffies = jiffies; |
| 2359 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2360 | nfs_access_add_cache(state->inode, &cache); |
| 2361 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2362 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2363 | return 0; |
| 2364 | |
| 2365 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2366 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2367 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2368 | } |
| 2369 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2370 | /* |
| 2371 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2372 | */ |
| 2373 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2374 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2375 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2376 | struct nfs_server *server = NFS_SERVER(dir); |
| 2377 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2378 | struct nfs_openres *o_res = &data->o_res; |
| 2379 | int status; |
| 2380 | |
| 2381 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2382 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2383 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2384 | if (status != 0) { |
| 2385 | if (status == -NFS4ERR_BADNAME && |
| 2386 | !(o_arg->open_flags & O_CREAT)) |
| 2387 | return -ENOENT; |
| 2388 | return status; |
| 2389 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2390 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2391 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2392 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2393 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2394 | if (o_arg->open_flags & O_EXCL) |
| 2395 | data->file_created = 1; |
| 2396 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2397 | data->file_created = 1; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2398 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2399 | update_changeattr(dir, &o_res->cinfo, |
| 2400 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2401 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2402 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2403 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2405 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2407 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | } |
| 2409 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2410 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2411 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2414 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2415 | { |
| 2416 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2417 | } |
| 2418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | /* |
| 2420 | * OPEN_EXPIRED: |
| 2421 | * reclaim state on the server after a network partition. |
| 2422 | * Assumes caller holds the appropriate lock |
| 2423 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2424 | 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] | 2425 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2426 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2427 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2429 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2430 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2431 | if (IS_ERR(opendata)) |
| 2432 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2433 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2434 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2435 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2436 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2437 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2440 | 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] | 2441 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2442 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2443 | struct nfs4_exception exception = { }; |
| 2444 | int err; |
| 2445 | |
| 2446 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2447 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2448 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2449 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2450 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2451 | switch (err) { |
| 2452 | default: |
| 2453 | goto out; |
| 2454 | case -NFS4ERR_GRACE: |
| 2455 | case -NFS4ERR_DELAY: |
| 2456 | nfs4_handle_exception(server, err, &exception); |
| 2457 | err = 0; |
| 2458 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2459 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2460 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2461 | return err; |
| 2462 | } |
| 2463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2465 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2467 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2469 | ctx = nfs4_state_find_open_context(state); |
| 2470 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2471 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2472 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2473 | put_nfs_open_context(ctx); |
| 2474 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2477 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2478 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2479 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2480 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2481 | write_seqlock(&state->seqlock); |
| 2482 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2483 | write_sequnlock(&state->seqlock); |
| 2484 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2485 | } |
| 2486 | |
| 2487 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2488 | { |
| 2489 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2490 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2494 | { |
| 2495 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2496 | nfs40_clear_delegation_stateid(state); |
| 2497 | return nfs4_open_expired(sp, state); |
| 2498 | } |
| 2499 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2500 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2501 | nfs4_stateid *stateid, |
| 2502 | struct rpc_cred *cred) |
| 2503 | { |
| 2504 | return -NFS4ERR_BAD_STATEID; |
| 2505 | } |
| 2506 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2507 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2508 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2509 | nfs4_stateid *stateid, |
| 2510 | struct rpc_cred *cred) |
| 2511 | { |
| 2512 | int status; |
| 2513 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2514 | switch (stateid->type) { |
| 2515 | default: |
| 2516 | break; |
| 2517 | case NFS4_INVALID_STATEID_TYPE: |
| 2518 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2519 | return -NFS4ERR_BAD_STATEID; |
| 2520 | case NFS4_REVOKED_STATEID_TYPE: |
| 2521 | goto out_free; |
| 2522 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2523 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2524 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2525 | switch (status) { |
| 2526 | case -NFS4ERR_EXPIRED: |
| 2527 | case -NFS4ERR_ADMIN_REVOKED: |
| 2528 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2529 | break; |
| 2530 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2531 | return status; |
| 2532 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2533 | out_free: |
| 2534 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2535 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2536 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2537 | } |
| 2538 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2539 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2540 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2541 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2542 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2543 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2544 | struct rpc_cred *cred; |
| 2545 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2546 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2547 | /* Get the delegation credential for use by test/free_stateid */ |
| 2548 | rcu_read_lock(); |
| 2549 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2550 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2551 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2552 | return; |
| 2553 | } |
| 2554 | |
| 2555 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2556 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2557 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2558 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2559 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2560 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2561 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2562 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2563 | rcu_read_unlock(); |
| 2564 | return; |
| 2565 | } |
| 2566 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2567 | cred = get_rpccred(delegation->cred); |
| 2568 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2569 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2570 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2571 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2572 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2573 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2574 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2578 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2579 | * |
| 2580 | * @state: NFSv4 state for an inode |
| 2581 | * |
| 2582 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2583 | * Otherwise a negative NFS4ERR value is returned. |
| 2584 | */ |
| 2585 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2586 | { |
| 2587 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2588 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2589 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2590 | |
| 2591 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2592 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2593 | |
| 2594 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2595 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2596 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2597 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2598 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2599 | atomic_inc(&lsp->ls_count); |
| 2600 | spin_unlock(&state->state_lock); |
| 2601 | |
| 2602 | nfs4_put_lock_state(prev); |
| 2603 | prev = lsp; |
| 2604 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2605 | status = nfs41_test_and_free_expired_stateid(server, |
| 2606 | &lsp->ls_stateid, |
| 2607 | cred); |
| 2608 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2609 | if (status == -NFS4ERR_EXPIRED || |
| 2610 | status == -NFS4ERR_BAD_STATEID) { |
| 2611 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2612 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2613 | if (!recover_lost_locks) |
| 2614 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2615 | } else if (status != NFS_OK) { |
| 2616 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2617 | nfs4_put_lock_state(prev); |
| 2618 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2619 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2620 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2621 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2622 | } |
| 2623 | spin_unlock(&state->state_lock); |
| 2624 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2625 | out: |
| 2626 | return ret; |
| 2627 | } |
| 2628 | |
| 2629 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2630 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2631 | * |
| 2632 | * @state: NFSv4 state for an inode |
| 2633 | * |
| 2634 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2635 | * Otherwise a negative NFS4ERR value is returned. |
| 2636 | */ |
| 2637 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2638 | { |
| 2639 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2640 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2641 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2642 | int status; |
| 2643 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2644 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2645 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2646 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2647 | return NFS_OK; |
| 2648 | return -NFS4ERR_OPENMODE; |
| 2649 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2650 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2651 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2652 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2653 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2654 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2655 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2656 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2657 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2658 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2659 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2660 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2661 | if (status != NFS_OK) |
| 2662 | return status; |
| 2663 | if (nfs_open_stateid_recover_openmode(state)) |
| 2664 | return -NFS4ERR_OPENMODE; |
| 2665 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2669 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2670 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2671 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2672 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2673 | status = nfs41_check_expired_locks(state); |
| 2674 | if (status != NFS_OK) |
| 2675 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2676 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2677 | if (status != NFS_OK) |
| 2678 | status = nfs4_open_expired(sp, state); |
| 2679 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2680 | } |
| 2681 | #endif |
| 2682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2684 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2685 | * fields corresponding to attributes that were used to store the verifier. |
| 2686 | * Make sure we clobber those fields in the later setattr call |
| 2687 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2688 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2689 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2690 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2691 | const u32 *attrset = opendata->o_res.attrset; |
| 2692 | |
| 2693 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2694 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2695 | sattr->ia_valid |= ATTR_ATIME; |
| 2696 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2697 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2698 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2699 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2700 | |
| 2701 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2702 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
| 2703 | attrset[1] & FATTR4_WORD1_MODE) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2704 | sattr->ia_valid &= ~ATTR_MODE; |
| 2705 | |
| 2706 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2707 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2708 | } |
| 2709 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2710 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2711 | fmode_t fmode, |
| 2712 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2713 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2714 | { |
| 2715 | struct nfs4_state_owner *sp = opendata->owner; |
| 2716 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2717 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2718 | struct nfs4_state *state; |
| 2719 | unsigned int seq; |
| 2720 | int ret; |
| 2721 | |
| 2722 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2723 | |
| 2724 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2725 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2726 | goto out; |
| 2727 | |
| 2728 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2729 | ret = PTR_ERR(state); |
| 2730 | if (IS_ERR(state)) |
| 2731 | goto out; |
| 2732 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2733 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2734 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2735 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2736 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2737 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2738 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2739 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2740 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2741 | alias = d_exact_alias(dentry, state->inode); |
| 2742 | if (!alias) |
| 2743 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2744 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2745 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2746 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2747 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2748 | } |
| 2749 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2750 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2751 | } |
| 2752 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2753 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2754 | if (ret != 0) |
| 2755 | goto out; |
| 2756 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2757 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2758 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2759 | nfs_inode_attach_open_context(ctx); |
| 2760 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2761 | nfs4_schedule_stateid_recovery(server, state); |
| 2762 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2763 | out: |
| 2764 | return ret; |
| 2765 | } |
| 2766 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2767 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2768 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2770 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2771 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2772 | int flags, |
| 2773 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2774 | struct nfs4_label *label, |
| 2775 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | { |
| 2777 | struct nfs4_state_owner *sp; |
| 2778 | struct nfs4_state *state = NULL; |
| 2779 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2780 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2781 | struct dentry *dentry = ctx->dentry; |
| 2782 | struct rpc_cred *cred = ctx->cred; |
| 2783 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2784 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2785 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2786 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2787 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | |
| 2789 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2791 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2792 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2794 | goto out_err; |
| 2795 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2796 | status = nfs4_recover_expired_lease(server); |
| 2797 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2798 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2799 | if (d_really_is_positive(dentry)) |
| 2800 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2801 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2802 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2803 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2804 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2805 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2806 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2807 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2809 | if (label) { |
| 2810 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2811 | if (IS_ERR(olabel)) { |
| 2812 | status = PTR_ERR(olabel); |
| 2813 | goto err_opendata_put; |
| 2814 | } |
| 2815 | } |
| 2816 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2817 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2818 | if (!opendata->f_attr.mdsthreshold) { |
| 2819 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2820 | if (!opendata->f_attr.mdsthreshold) |
| 2821 | goto err_free_label; |
| 2822 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2823 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2824 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2825 | if (d_really_is_positive(dentry)) |
| 2826 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2827 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2828 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2829 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2830 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2831 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2832 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2833 | 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] | 2834 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2835 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2836 | /* |
| 2837 | * send create attributes which was not set by open |
| 2838 | * with an extra setattr. |
| 2839 | */ |
| 2840 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2841 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2842 | status = nfs4_do_setattr(state->inode, cred, |
| 2843 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2844 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2845 | if (status == 0) { |
| 2846 | nfs_setattr_update_inode(state->inode, sattr, |
| 2847 | opendata->o_res.f_attr); |
| 2848 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2849 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2850 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2851 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2852 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2853 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2854 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2855 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2856 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2857 | opendata->f_attr.mdsthreshold = NULL; |
| 2858 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2859 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2860 | nfs4_label_free(olabel); |
| 2861 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2862 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2865 | err_free_label: |
| 2866 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2867 | err_opendata_put: |
| 2868 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2869 | err_put_state_owner: |
| 2870 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | return status; |
| 2873 | } |
| 2874 | |
| 2875 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2876 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2877 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2878 | int flags, |
| 2879 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2880 | struct nfs4_label *label, |
| 2881 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2883 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | struct nfs4_exception exception = { }; |
| 2885 | struct nfs4_state *res; |
| 2886 | int status; |
| 2887 | |
| 2888 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2889 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2890 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2891 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | if (status == 0) |
| 2893 | break; |
| 2894 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2895 | * book-keeping w.r.t. state-changing operations |
| 2896 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2897 | * It is actually a sign of a bug on the client or on the server. |
| 2898 | * |
| 2899 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2900 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | * have unhashed the old state_owner for us, and that we can |
| 2902 | * therefore safely retry using a new one. We should still warn |
| 2903 | * the user though... |
| 2904 | */ |
| 2905 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2906 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2907 | " returned a bad sequence-id error!\n", |
| 2908 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | exception.retry = 1; |
| 2910 | continue; |
| 2911 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2912 | /* |
| 2913 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2914 | * state before it received the OPEN_CONFIRM. |
| 2915 | * Recover by retrying the request as per the discussion |
| 2916 | * on Page 181 of RFC3530. |
| 2917 | */ |
| 2918 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2919 | exception.retry = 1; |
| 2920 | continue; |
| 2921 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2922 | if (status == -EAGAIN) { |
| 2923 | /* We must have found a delegation */ |
| 2924 | exception.retry = 1; |
| 2925 | continue; |
| 2926 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2927 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2928 | continue; |
| 2929 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | status, &exception)); |
| 2931 | } while (exception.retry); |
| 2932 | return res; |
| 2933 | } |
| 2934 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2935 | static int _nfs4_do_setattr(struct inode *inode, |
| 2936 | struct nfs_setattrargs *arg, |
| 2937 | struct nfs_setattrres *res, |
| 2938 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2939 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2940 | { |
| 2941 | struct nfs_server *server = NFS_SERVER(inode); |
| 2942 | struct rpc_message msg = { |
| 2943 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2944 | .rpc_argp = arg, |
| 2945 | .rpc_resp = res, |
| 2946 | .rpc_cred = cred, |
| 2947 | }; |
| 2948 | struct rpc_cred *delegation_cred = NULL; |
| 2949 | unsigned long timestamp = jiffies; |
| 2950 | fmode_t fmode; |
| 2951 | bool truncate; |
| 2952 | int status; |
| 2953 | |
| 2954 | nfs_fattr_init(res->fattr); |
| 2955 | |
| 2956 | /* Servers should only apply open mode checks for file size changes */ |
| 2957 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2958 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2959 | |
| 2960 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2961 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2962 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2963 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2964 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2965 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2966 | l_ctx = nfs_get_lock_context(ctx); |
| 2967 | if (IS_ERR(l_ctx)) |
| 2968 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2969 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2970 | &arg->stateid, &delegation_cred); |
| 2971 | nfs_put_lock_context(l_ctx); |
| 2972 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2973 | return -EBADF; |
| 2974 | } else |
| 2975 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2976 | if (delegation_cred) |
| 2977 | msg.rpc_cred = delegation_cred; |
| 2978 | |
| 2979 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2980 | |
| 2981 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2982 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2983 | renew_lease(server, timestamp); |
| 2984 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2985 | return status; |
| 2986 | } |
| 2987 | |
| 2988 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2989 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2990 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2991 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2993 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2994 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2996 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | .iap = sattr, |
| 2998 | .server = server, |
| 2999 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3000 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | }; |
| 3002 | struct nfs_setattrres res = { |
| 3003 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3004 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | .server = server, |
| 3006 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3007 | struct nfs4_exception exception = { |
| 3008 | .state = state, |
| 3009 | .inode = inode, |
| 3010 | .stateid = &arg.stateid, |
| 3011 | }; |
| 3012 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3014 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 3015 | if (ilabel) |
| 3016 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 3017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3019 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3020 | switch (err) { |
| 3021 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3022 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3023 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3024 | "applying open mode checks to " |
| 3025 | "a SETATTR that is not " |
| 3026 | "changing file size.\n", |
| 3027 | server->nfs_client->cl_hostname); |
| 3028 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3029 | if (state && !(state->state & FMODE_WRITE)) { |
| 3030 | err = -EBADF; |
| 3031 | if (sattr->ia_valid & ATTR_OPEN) |
| 3032 | err = -EACCES; |
| 3033 | goto out; |
| 3034 | } |
| 3035 | } |
| 3036 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3038 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | return err; |
| 3040 | } |
| 3041 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3042 | static bool |
| 3043 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3044 | { |
| 3045 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3046 | return false; |
| 3047 | |
| 3048 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3049 | } |
| 3050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | struct nfs4_closedata { |
| 3052 | struct inode *inode; |
| 3053 | struct nfs4_state *state; |
| 3054 | struct nfs_closeargs arg; |
| 3055 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3056 | struct { |
| 3057 | struct nfs4_layoutreturn_args arg; |
| 3058 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3059 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3060 | u32 roc_barrier; |
| 3061 | bool roc; |
| 3062 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3063 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3064 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | }; |
| 3066 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3067 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3068 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3069 | struct nfs4_closedata *calldata = data; |
| 3070 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3071 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3072 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3073 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3074 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3075 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3076 | nfs4_put_open_state(calldata->state); |
| 3077 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3078 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3079 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3080 | kfree(calldata); |
| 3081 | } |
| 3082 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3083 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3085 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3088 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3090 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3091 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3092 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3093 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3094 | |
| 3095 | /* Handle Layoutreturn errors */ |
| 3096 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3097 | switch (calldata->res.lr_ret) { |
| 3098 | default: |
| 3099 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3100 | break; |
| 3101 | case 0: |
| 3102 | calldata->arg.lr_args = NULL; |
| 3103 | calldata->res.lr_res = NULL; |
| 3104 | break; |
| 3105 | case -NFS4ERR_ADMIN_REVOKED: |
| 3106 | case -NFS4ERR_DELEG_REVOKED: |
| 3107 | case -NFS4ERR_EXPIRED: |
| 3108 | case -NFS4ERR_BAD_STATEID: |
| 3109 | case -NFS4ERR_OLD_STATEID: |
| 3110 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3111 | case -NFS4ERR_WRONG_CRED: |
| 3112 | calldata->arg.lr_args = NULL; |
| 3113 | calldata->res.lr_res = NULL; |
| 3114 | calldata->res.lr_ret = 0; |
| 3115 | rpc_restart_call_prepare(task); |
| 3116 | return; |
| 3117 | } |
| 3118 | } |
| 3119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | /* hmm. we are done with the inode, and in the process of freeing |
| 3121 | * the state_owner. we keep this around to process errors |
| 3122 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | switch (task->tk_status) { |
| 3124 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3125 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3126 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3127 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3128 | case -NFS4ERR_ACCESS: |
| 3129 | if (calldata->arg.bitmask != NULL) { |
| 3130 | calldata->arg.bitmask = NULL; |
| 3131 | calldata->res.fattr = NULL; |
| 3132 | task->tk_status = 0; |
| 3133 | rpc_restart_call_prepare(task); |
| 3134 | goto out_release; |
| 3135 | |
| 3136 | } |
| 3137 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3138 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3140 | case -NFS4ERR_EXPIRED: |
| 3141 | nfs4_free_revoked_stateid(server, |
| 3142 | &calldata->arg.stateid, |
| 3143 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3144 | case -NFS4ERR_OLD_STATEID: |
| 3145 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3146 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3147 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3148 | rpc_restart_call_prepare(task); |
| 3149 | goto out_release; |
| 3150 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3151 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3152 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3154 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3155 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3156 | goto out_release; |
| 3157 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3159 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3160 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3161 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3162 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3163 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3164 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3167 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3169 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3170 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3171 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3172 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3173 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3174 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3175 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3176 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3177 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3178 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3179 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3180 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3181 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3182 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3183 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3184 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3185 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3186 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3187 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3188 | if (state->n_rdonly == 0) |
| 3189 | call_close |= is_rdonly; |
| 3190 | else if (is_rdonly) |
| 3191 | calldata->arg.fmode |= FMODE_READ; |
| 3192 | if (state->n_wronly == 0) |
| 3193 | call_close |= is_wronly; |
| 3194 | else if (is_wronly) |
| 3195 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3196 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3197 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3198 | } else if (is_rdwr) |
| 3199 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3200 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3201 | if (!nfs4_valid_open_stateid(state) || |
| 3202 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3203 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3204 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3205 | |
| 3206 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3207 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3208 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3209 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3210 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3211 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3212 | nfs_release_seqid(calldata->arg.seqid); |
| 3213 | goto out_wait; |
| 3214 | } |
| 3215 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3216 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3217 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3218 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3219 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3220 | /* Close-to-open cache consistency revalidation */ |
| 3221 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3222 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3223 | else |
| 3224 | calldata->arg.bitmask = NULL; |
| 3225 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3226 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3227 | calldata->arg.share_access = |
| 3228 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3229 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3230 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3231 | if (calldata->res.fattr == NULL) |
| 3232 | calldata->arg.bitmask = NULL; |
| 3233 | else if (calldata->arg.bitmask == NULL) |
| 3234 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3235 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 3236 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3237 | &calldata->arg.seq_args, |
| 3238 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3239 | task) != 0) |
| 3240 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3241 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3242 | return; |
| 3243 | out_no_action: |
| 3244 | task->tk_action = NULL; |
| 3245 | out_wait: |
| 3246 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3249 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3250 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3251 | .rpc_call_done = nfs4_close_done, |
| 3252 | .rpc_release = nfs4_free_closedata, |
| 3253 | }; |
| 3254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | /* |
| 3256 | * It is possible for data to be read/written from a mem-mapped file |
| 3257 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3258 | * This means that we can't safely call nfsv4 close on a file until |
| 3259 | * the inode is cleared. This in turn means that we are not good |
| 3260 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3261 | * share state even when we are done with one of the three share |
| 3262 | * stateid's in the inode. |
| 3263 | * |
| 3264 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3265 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3266 | 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] | 3267 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3268 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3269 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3271 | struct nfs4_state_owner *sp = state->owner; |
| 3272 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3273 | struct rpc_message msg = { |
| 3274 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3275 | .rpc_cred = state->owner->so_cred, |
| 3276 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3277 | struct rpc_task_setup task_setup_data = { |
| 3278 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3279 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3280 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3281 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3282 | .flags = RPC_TASK_ASYNC, |
| 3283 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3284 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3286 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3287 | &task_setup_data.rpc_client, &msg); |
| 3288 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3289 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3291 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3292 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3293 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3295 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3297 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3298 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3299 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3300 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3301 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3302 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3303 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3304 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3305 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3306 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3307 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3308 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3309 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3310 | if (calldata->lr.roc) { |
| 3311 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3312 | calldata->res.lr_res = &calldata->lr.res; |
| 3313 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3314 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3315 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3316 | msg.rpc_argp = &calldata->arg; |
| 3317 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3318 | task_setup_data.callback_data = calldata; |
| 3319 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3320 | if (IS_ERR(task)) |
| 3321 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3322 | status = 0; |
| 3323 | if (wait) |
| 3324 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3325 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3326 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3327 | out_free_calldata: |
| 3328 | kfree(calldata); |
| 3329 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3330 | nfs4_put_open_state(state); |
| 3331 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3332 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3335 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3336 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3337 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3340 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3341 | |
| 3342 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3344 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3345 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3346 | |
| 3347 | nfs4_label_release_security(label); |
| 3348 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3349 | if (IS_ERR(state)) |
| 3350 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3351 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3354 | 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] | 3355 | { |
| 3356 | if (ctx->state == NULL) |
| 3357 | return; |
| 3358 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3359 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3360 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3361 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3362 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3364 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3365 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3366 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3369 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3370 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3371 | struct nfs4_server_caps_arg args = { |
| 3372 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3373 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3374 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | struct nfs4_server_caps_res res = {}; |
| 3376 | struct rpc_message msg = { |
| 3377 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3378 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | .rpc_resp = &res, |
| 3380 | }; |
| 3381 | int status; |
| 3382 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3383 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3384 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3385 | FATTR4_WORD0_LINK_SUPPORT | |
| 3386 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3387 | FATTR4_WORD0_ACLSUPPORT; |
| 3388 | if (minorversion) |
| 3389 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3390 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3391 | 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] | 3392 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3393 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3394 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3395 | case 0: |
| 3396 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3397 | res.attr_bitmask[2] = 0; |
| 3398 | break; |
| 3399 | case 1: |
| 3400 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3401 | break; |
| 3402 | case 2: |
| 3403 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3406 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3407 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3408 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3409 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3410 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3411 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3412 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3413 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | server->caps |= NFS_CAP_ACLS; |
| 3415 | if (res.has_links != 0) |
| 3416 | server->caps |= NFS_CAP_HARDLINKS; |
| 3417 | if (res.has_symlinks != 0) |
| 3418 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3419 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3420 | server->caps |= NFS_CAP_FILEID; |
| 3421 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3422 | server->caps |= NFS_CAP_MODE; |
| 3423 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3424 | server->caps |= NFS_CAP_NLINK; |
| 3425 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3426 | server->caps |= NFS_CAP_OWNER; |
| 3427 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3428 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3429 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3430 | server->caps |= NFS_CAP_ATIME; |
| 3431 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3432 | server->caps |= NFS_CAP_CTIME; |
| 3433 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3434 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3435 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3436 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3437 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3438 | #endif |
| 3439 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3440 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3441 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3442 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3443 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3444 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3445 | 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] | 3446 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3447 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3448 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3450 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | return status; |
| 3454 | } |
| 3455 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3456 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | { |
| 3458 | struct nfs4_exception exception = { }; |
| 3459 | int err; |
| 3460 | do { |
| 3461 | err = nfs4_handle_exception(server, |
| 3462 | _nfs4_server_capabilities(server, fhandle), |
| 3463 | &exception); |
| 3464 | } while (exception.retry); |
| 3465 | return err; |
| 3466 | } |
| 3467 | |
| 3468 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3469 | struct nfs_fsinfo *info) |
| 3470 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3471 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3473 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | }; |
| 3475 | struct nfs4_lookup_res res = { |
| 3476 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3477 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | .fh = fhandle, |
| 3479 | }; |
| 3480 | struct rpc_message msg = { |
| 3481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3482 | .rpc_argp = &args, |
| 3483 | .rpc_resp = &res, |
| 3484 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3485 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3486 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3487 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3488 | /* |
| 3489 | * Process the label in the upcoming getfattr |
| 3490 | */ |
| 3491 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3492 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3493 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3494 | 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] | 3495 | } |
| 3496 | |
| 3497 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3498 | struct nfs_fsinfo *info) |
| 3499 | { |
| 3500 | struct nfs4_exception exception = { }; |
| 3501 | int err; |
| 3502 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3503 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3504 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3505 | switch (err) { |
| 3506 | case 0: |
| 3507 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3508 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3509 | default: |
| 3510 | err = nfs4_handle_exception(server, err, &exception); |
| 3511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3513 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | return err; |
| 3515 | } |
| 3516 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3517 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3518 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3519 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3520 | struct rpc_auth_create_args auth_args = { |
| 3521 | .pseudoflavor = flavor, |
| 3522 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3523 | struct rpc_auth *auth; |
| 3524 | int ret; |
| 3525 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3526 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3527 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3528 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3529 | goto out; |
| 3530 | } |
| 3531 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3532 | out: |
| 3533 | return ret; |
| 3534 | } |
| 3535 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3536 | /* |
| 3537 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3538 | * |
| 3539 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3540 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3541 | * |
| 3542 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3543 | * negative errno value. |
| 3544 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3545 | 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] | 3546 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3548 | /* Per 3530bis 15.33.5 */ |
| 3549 | static const rpc_authflavor_t flav_array[] = { |
| 3550 | RPC_AUTH_GSS_KRB5P, |
| 3551 | RPC_AUTH_GSS_KRB5I, |
| 3552 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3553 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3554 | RPC_AUTH_NULL, |
| 3555 | }; |
| 3556 | int status = -EPERM; |
| 3557 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3559 | if (server->auth_info.flavor_len > 0) { |
| 3560 | /* try each flavor specified by user */ |
| 3561 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3562 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3563 | server->auth_info.flavors[i]); |
| 3564 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3565 | continue; |
| 3566 | break; |
| 3567 | } |
| 3568 | } else { |
| 3569 | /* no flavors specified by user, try default list */ |
| 3570 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3571 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3572 | flav_array[i]); |
| 3573 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3574 | continue; |
| 3575 | break; |
| 3576 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3577 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3578 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3579 | /* |
| 3580 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3581 | * to access the mount. It could also mean that we tried to mount |
| 3582 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3583 | * existing mount programs don't handle -EACCES very well so it should |
| 3584 | * be mapped to -EPERM instead. |
| 3585 | */ |
| 3586 | if (status == -EACCES) |
| 3587 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3588 | return status; |
| 3589 | } |
| 3590 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3591 | /** |
| 3592 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3593 | * @server: initialized nfs_server handle |
| 3594 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3595 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3596 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3597 | * |
| 3598 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3599 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3600 | 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] | 3601 | struct nfs_fsinfo *info, |
| 3602 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3603 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3604 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3605 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3606 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3607 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3608 | |
| 3609 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3610 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3611 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | if (status == 0) |
| 3614 | status = nfs4_server_capabilities(server, fhandle); |
| 3615 | if (status == 0) |
| 3616 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3617 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3618 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3621 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3622 | struct nfs_fsinfo *info) |
| 3623 | { |
| 3624 | int error; |
| 3625 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3626 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3627 | |
| 3628 | error = nfs4_server_capabilities(server, mntfh); |
| 3629 | if (error < 0) { |
| 3630 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3631 | return error; |
| 3632 | } |
| 3633 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3634 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3635 | if (IS_ERR(label)) |
| 3636 | return PTR_ERR(label); |
| 3637 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3638 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3639 | if (error < 0) { |
| 3640 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3641 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3645 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3646 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3647 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3648 | err_free_label: |
| 3649 | nfs4_label_free(label); |
| 3650 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3651 | return error; |
| 3652 | } |
| 3653 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3654 | /* |
| 3655 | * Get locations and (maybe) other attributes of a referral. |
| 3656 | * Note that we'll actually follow the referral later when |
| 3657 | * we detect fsid mismatch in inode revalidation |
| 3658 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3659 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3660 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3661 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3662 | { |
| 3663 | int status = -ENOMEM; |
| 3664 | struct page *page = NULL; |
| 3665 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3666 | |
| 3667 | page = alloc_page(GFP_KERNEL); |
| 3668 | if (page == NULL) |
| 3669 | goto out; |
| 3670 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3671 | if (locations == NULL) |
| 3672 | goto out; |
| 3673 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3674 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3675 | if (status != 0) |
| 3676 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3677 | |
| 3678 | /* |
| 3679 | * If the fsid didn't change, this is a migration event, not a |
| 3680 | * referral. Cause us to drop into the exception handler, which |
| 3681 | * will kick off migration recovery. |
| 3682 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3683 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3684 | dprintk("%s: server did not return a different fsid for" |
| 3685 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3686 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3687 | goto out; |
| 3688 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3689 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3690 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3691 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3692 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3693 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3694 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3695 | out: |
| 3696 | if (page) |
| 3697 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3698 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3699 | return status; |
| 3700 | } |
| 3701 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3702 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3703 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | { |
| 3705 | struct nfs4_getattr_arg args = { |
| 3706 | .fh = fhandle, |
| 3707 | .bitmask = server->attr_bitmask, |
| 3708 | }; |
| 3709 | struct nfs4_getattr_res res = { |
| 3710 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3711 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | .server = server, |
| 3713 | }; |
| 3714 | struct rpc_message msg = { |
| 3715 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3716 | .rpc_argp = &args, |
| 3717 | .rpc_resp = &res, |
| 3718 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3719 | |
| 3720 | args.bitmask = nfs4_bitmask(server, label); |
| 3721 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3722 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3723 | 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] | 3724 | } |
| 3725 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3726 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3727 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | { |
| 3729 | struct nfs4_exception exception = { }; |
| 3730 | int err; |
| 3731 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3732 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3733 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3734 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | &exception); |
| 3736 | } while (exception.retry); |
| 3737 | return err; |
| 3738 | } |
| 3739 | |
| 3740 | /* |
| 3741 | * The file is not closed if it is opened due to the a request to change |
| 3742 | * the size of the file. The open call will not be needed once the |
| 3743 | * VFS layer lookup-intents are implemented. |
| 3744 | * |
| 3745 | * Close is called when the inode is destroyed. |
| 3746 | * If we haven't opened the file for O_WRONLY, we |
| 3747 | * need to in the size_change case to obtain a stateid. |
| 3748 | * |
| 3749 | * Got race? |
| 3750 | * Because OPEN is always done by name in nfsv4, it is |
| 3751 | * possible that we opened a different file by the same |
| 3752 | * name. We can recognize this race condition, but we |
| 3753 | * can't do anything about it besides returning an error. |
| 3754 | * |
| 3755 | * This will be fixed with VFS changes (lookup-intent). |
| 3756 | */ |
| 3757 | static int |
| 3758 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3759 | struct iattr *sattr) |
| 3760 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3761 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3762 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3763 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3764 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | int status; |
| 3766 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3767 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3768 | sattr->ia_valid & ATTR_SIZE && |
| 3769 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3770 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3771 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3772 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3774 | /* Deal with open(O_TRUNC) */ |
| 3775 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3776 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3777 | |
| 3778 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3779 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3780 | return 0; |
| 3781 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3782 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3783 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3784 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3785 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3786 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3787 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3788 | } |
| 3789 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3790 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3791 | if (IS_ERR(label)) |
| 3792 | return PTR_ERR(label); |
| 3793 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3794 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3795 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3796 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3797 | nfs_setsecurity(inode, fattr, label); |
| 3798 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3799 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | return status; |
| 3801 | } |
| 3802 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3803 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3804 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3805 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3806 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3807 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3808 | int status; |
| 3809 | struct nfs4_lookup_arg args = { |
| 3810 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3811 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3812 | .name = name, |
| 3813 | }; |
| 3814 | struct nfs4_lookup_res res = { |
| 3815 | .server = server, |
| 3816 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3817 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3818 | .fh = fhandle, |
| 3819 | }; |
| 3820 | struct rpc_message msg = { |
| 3821 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3822 | .rpc_argp = &args, |
| 3823 | .rpc_resp = &res, |
| 3824 | }; |
| 3825 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3826 | args.bitmask = nfs4_bitmask(server, label); |
| 3827 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3828 | nfs_fattr_init(fattr); |
| 3829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3831 | 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] | 3832 | dprintk("NFS reply lookup: %d\n", status); |
| 3833 | return status; |
| 3834 | } |
| 3835 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3836 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3837 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3838 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3839 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3840 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3841 | fattr->nlink = 2; |
| 3842 | } |
| 3843 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3844 | 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] | 3845 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3846 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3847 | { |
| 3848 | struct nfs4_exception exception = { }; |
| 3849 | struct rpc_clnt *client = *clnt; |
| 3850 | int err; |
| 3851 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3852 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3853 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3854 | switch (err) { |
| 3855 | case -NFS4ERR_BADNAME: |
| 3856 | err = -ENOENT; |
| 3857 | goto out; |
| 3858 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3859 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3860 | if (err == -NFS4ERR_MOVED) |
| 3861 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3862 | goto out; |
| 3863 | case -NFS4ERR_WRONGSEC: |
| 3864 | err = -EPERM; |
| 3865 | if (client != *clnt) |
| 3866 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3867 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3868 | if (IS_ERR(client)) |
| 3869 | return PTR_ERR(client); |
| 3870 | |
| 3871 | exception.retry = 1; |
| 3872 | break; |
| 3873 | default: |
| 3874 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3875 | } |
| 3876 | } while (exception.retry); |
| 3877 | |
| 3878 | out: |
| 3879 | if (err == 0) |
| 3880 | *clnt = client; |
| 3881 | else if (client != *clnt) |
| 3882 | rpc_shutdown_client(client); |
| 3883 | |
| 3884 | return err; |
| 3885 | } |
| 3886 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3887 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3888 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3889 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3891 | int status; |
| 3892 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3893 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3894 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3895 | if (client != NFS_CLIENT(dir)) { |
| 3896 | rpc_shutdown_client(client); |
| 3897 | nfs_fixup_secinfo_attributes(fattr); |
| 3898 | } |
| 3899 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3902 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3903 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3904 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3905 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3906 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3907 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3908 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3909 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3910 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3911 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3912 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3913 | } |
| 3914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3916 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3917 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | struct nfs4_accessargs args = { |
| 3919 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3920 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3922 | struct nfs4_accessres res = { |
| 3923 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3924 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | struct rpc_message msg = { |
| 3926 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3927 | .rpc_argp = &args, |
| 3928 | .rpc_resp = &res, |
| 3929 | .rpc_cred = entry->cred, |
| 3930 | }; |
| 3931 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3932 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | |
| 3934 | /* |
| 3935 | * Determine which access bits we want to ask for... |
| 3936 | */ |
| 3937 | if (mode & MAY_READ) |
| 3938 | args.access |= NFS4_ACCESS_READ; |
| 3939 | if (S_ISDIR(inode->i_mode)) { |
| 3940 | if (mode & MAY_WRITE) |
| 3941 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3942 | if (mode & MAY_EXEC) |
| 3943 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3944 | } else { |
| 3945 | if (mode & MAY_WRITE) |
| 3946 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3947 | if (mode & MAY_EXEC) |
| 3948 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3949 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3950 | |
| 3951 | res.fattr = nfs_alloc_fattr(); |
| 3952 | if (res.fattr == NULL) |
| 3953 | return -ENOMEM; |
| 3954 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3955 | 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] | 3956 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3957 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3958 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3960 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | return status; |
| 3962 | } |
| 3963 | |
| 3964 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3965 | { |
| 3966 | struct nfs4_exception exception = { }; |
| 3967 | int err; |
| 3968 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3969 | err = _nfs4_proc_access(inode, entry); |
| 3970 | trace_nfs4_access(inode, err); |
| 3971 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | &exception); |
| 3973 | } while (exception.retry); |
| 3974 | return err; |
| 3975 | } |
| 3976 | |
| 3977 | /* |
| 3978 | * TODO: For the time being, we don't try to get any attributes |
| 3979 | * along with any of the zero-copy operations READ, READDIR, |
| 3980 | * READLINK, WRITE. |
| 3981 | * |
| 3982 | * In the case of the first three, we want to put the GETATTR |
| 3983 | * after the read-type operation -- this is because it is hard |
| 3984 | * to predict the length of a GETATTR response in v4, and thus |
| 3985 | * align the READ data correctly. This means that the GETATTR |
| 3986 | * may end up partially falling into the page cache, and we should |
| 3987 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3988 | * To do this efficiently, we need to know the total length |
| 3989 | * of data received, which doesn't seem to be available outside |
| 3990 | * of the RPC layer. |
| 3991 | * |
| 3992 | * In the case of WRITE, we also want to put the GETATTR after |
| 3993 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3994 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | * |
| 3996 | * Both of these changes to the XDR layer would in fact be quite |
| 3997 | * minor, but I decided to leave them for a subsequent patch. |
| 3998 | */ |
| 3999 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4000 | unsigned int pgbase, unsigned int pglen) |
| 4001 | { |
| 4002 | struct nfs4_readlink args = { |
| 4003 | .fh = NFS_FH(inode), |
| 4004 | .pgbase = pgbase, |
| 4005 | .pglen = pglen, |
| 4006 | .pages = &page, |
| 4007 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4008 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | struct rpc_message msg = { |
| 4010 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4011 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4012 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | }; |
| 4014 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4015 | 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] | 4016 | } |
| 4017 | |
| 4018 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4019 | unsigned int pgbase, unsigned int pglen) |
| 4020 | { |
| 4021 | struct nfs4_exception exception = { }; |
| 4022 | int err; |
| 4023 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4024 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4025 | trace_nfs4_readlink(inode, err); |
| 4026 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | &exception); |
| 4028 | } while (exception.retry); |
| 4029 | return err; |
| 4030 | } |
| 4031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4033 | * 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] | 4034 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | static int |
| 4036 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4037 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4039 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4040 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4041 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | int status = 0; |
| 4044 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4045 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4046 | if (IS_ERR(ctx)) |
| 4047 | return PTR_ERR(ctx); |
| 4048 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4049 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4050 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4051 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4052 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4053 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | if (IS_ERR(state)) { |
| 4055 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4056 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4059 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4060 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | return status; |
| 4062 | } |
| 4063 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4064 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4066 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4067 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4069 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4071 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4072 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4073 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4075 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4076 | .rpc_argp = &args, |
| 4077 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4079 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4080 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4081 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4082 | 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] | 4083 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4084 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | return status; |
| 4086 | } |
| 4087 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4088 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | { |
| 4090 | struct nfs4_exception exception = { }; |
| 4091 | int err; |
| 4092 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4093 | err = _nfs4_proc_remove(dir, name); |
| 4094 | trace_nfs4_remove(dir, name, err); |
| 4095 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | &exception); |
| 4097 | } while (exception.retry); |
| 4098 | return err; |
| 4099 | } |
| 4100 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4101 | 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] | 4102 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4103 | struct nfs_server *server = NFS_SERVER(dir); |
| 4104 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4105 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4107 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4109 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4110 | |
| 4111 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | } |
| 4113 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4114 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4115 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 4116 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4117 | &data->args.seq_args, |
| 4118 | &data->res.seq_res, |
| 4119 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4122 | 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] | 4123 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4124 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4125 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4126 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4127 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4128 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4129 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4130 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4131 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4132 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4133 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4134 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4137 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4138 | { |
| 4139 | struct nfs_server *server = NFS_SERVER(dir); |
| 4140 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4141 | struct nfs_renameres *res = msg->rpc_resp; |
| 4142 | |
| 4143 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4144 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4145 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4146 | } |
| 4147 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4148 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4149 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 4150 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4151 | &data->args.seq_args, |
| 4152 | &data->res.seq_res, |
| 4153 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4154 | } |
| 4155 | |
| 4156 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4157 | struct inode *new_dir) |
| 4158 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4159 | struct nfs_renamedata *data = task->tk_calldata; |
| 4160 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4161 | |
| 4162 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4163 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4164 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4165 | return 0; |
| 4166 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4167 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4168 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4169 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4170 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4171 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4172 | return 1; |
| 4173 | } |
| 4174 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4175 | 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] | 4176 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4177 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | struct nfs4_link_arg arg = { |
| 4179 | .fh = NFS_FH(inode), |
| 4180 | .dir_fh = NFS_FH(dir), |
| 4181 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4182 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4184 | struct nfs4_link_res res = { |
| 4185 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4186 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4187 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | struct rpc_message msg = { |
| 4189 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4190 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4191 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4193 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4195 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4196 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4197 | goto out; |
| 4198 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4199 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4200 | if (IS_ERR(res.label)) { |
| 4201 | status = PTR_ERR(res.label); |
| 4202 | goto out; |
| 4203 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4204 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4205 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4206 | 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] | 4207 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4208 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4209 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4210 | if (!status) |
| 4211 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4212 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4213 | |
| 4214 | |
| 4215 | nfs4_label_free(res.label); |
| 4216 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4217 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4218 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | return status; |
| 4220 | } |
| 4221 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4222 | 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] | 4223 | { |
| 4224 | struct nfs4_exception exception = { }; |
| 4225 | int err; |
| 4226 | do { |
| 4227 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4228 | _nfs4_proc_link(inode, dir, name), |
| 4229 | &exception); |
| 4230 | } while (exception.retry); |
| 4231 | return err; |
| 4232 | } |
| 4233 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4234 | struct nfs4_createdata { |
| 4235 | struct rpc_message msg; |
| 4236 | struct nfs4_create_arg arg; |
| 4237 | struct nfs4_create_res res; |
| 4238 | struct nfs_fh fh; |
| 4239 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4240 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4241 | }; |
| 4242 | |
| 4243 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4244 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4245 | { |
| 4246 | struct nfs4_createdata *data; |
| 4247 | |
| 4248 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4249 | if (data != NULL) { |
| 4250 | struct nfs_server *server = NFS_SERVER(dir); |
| 4251 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4252 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4253 | if (IS_ERR(data->label)) |
| 4254 | goto out_free; |
| 4255 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4256 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4257 | data->msg.rpc_argp = &data->arg; |
| 4258 | data->msg.rpc_resp = &data->res; |
| 4259 | data->arg.dir_fh = NFS_FH(dir); |
| 4260 | data->arg.server = server; |
| 4261 | data->arg.name = name; |
| 4262 | data->arg.attrs = sattr; |
| 4263 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4264 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4265 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4266 | data->res.server = server; |
| 4267 | data->res.fh = &data->fh; |
| 4268 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4269 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4270 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4271 | } |
| 4272 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4273 | out_free: |
| 4274 | kfree(data); |
| 4275 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4279 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4280 | 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] | 4281 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4282 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4283 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4284 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4285 | 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] | 4286 | } |
| 4287 | return status; |
| 4288 | } |
| 4289 | |
| 4290 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4291 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4292 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4293 | kfree(data); |
| 4294 | } |
| 4295 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4296 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4297 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4298 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4300 | struct nfs4_createdata *data; |
| 4301 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4303 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4304 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4305 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4306 | status = -ENOMEM; |
| 4307 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4308 | if (data == NULL) |
| 4309 | goto out; |
| 4310 | |
| 4311 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4312 | data->arg.u.symlink.pages = &page; |
| 4313 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4314 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4316 | status = nfs4_do_create(dir, dentry, data); |
| 4317 | |
| 4318 | nfs4_free_createdata(data); |
| 4319 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | return status; |
| 4321 | } |
| 4322 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4323 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4324 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | { |
| 4326 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4327 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4329 | |
| 4330 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4333 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4334 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4335 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | &exception); |
| 4337 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4338 | |
| 4339 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | return err; |
| 4341 | } |
| 4342 | |
| 4343 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4344 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4346 | struct nfs4_createdata *data; |
| 4347 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4349 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4350 | if (data == NULL) |
| 4351 | goto out; |
| 4352 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4353 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4354 | status = nfs4_do_create(dir, dentry, data); |
| 4355 | |
| 4356 | nfs4_free_createdata(data); |
| 4357 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | return status; |
| 4359 | } |
| 4360 | |
| 4361 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4362 | struct iattr *sattr) |
| 4363 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4364 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4366 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4368 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4369 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4370 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4371 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4372 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4374 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4375 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4376 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | &exception); |
| 4378 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4379 | nfs4_label_release_security(label); |
| 4380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | return err; |
| 4382 | } |
| 4383 | |
| 4384 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4385 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4387 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | struct nfs4_readdir_arg args = { |
| 4389 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4390 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | .pgbase = 0, |
| 4392 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4393 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4394 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | }; |
| 4396 | struct nfs4_readdir_res res; |
| 4397 | struct rpc_message msg = { |
| 4398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4399 | .rpc_argp = &args, |
| 4400 | .rpc_resp = &res, |
| 4401 | .rpc_cred = cred, |
| 4402 | }; |
| 4403 | int status; |
| 4404 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4405 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4406 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4407 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4408 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4410 | 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] | 4411 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4412 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4413 | status += args.pgbase; |
| 4414 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4415 | |
| 4416 | nfs_invalidate_atime(dir); |
| 4417 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4418 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | return status; |
| 4420 | } |
| 4421 | |
| 4422 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4423 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | { |
| 4425 | struct nfs4_exception exception = { }; |
| 4426 | int err; |
| 4427 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4428 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4429 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4430 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4431 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | &exception); |
| 4433 | } while (exception.retry); |
| 4434 | return err; |
| 4435 | } |
| 4436 | |
| 4437 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4438 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4440 | struct nfs4_createdata *data; |
| 4441 | int mode = sattr->ia_mode; |
| 4442 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4444 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4445 | if (data == NULL) |
| 4446 | goto out; |
| 4447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4449 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4451 | data->arg.ftype = NF4BLK; |
| 4452 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4453 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | } |
| 4455 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4456 | data->arg.ftype = NF4CHR; |
| 4457 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4458 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4459 | } else if (!S_ISSOCK(mode)) { |
| 4460 | status = -EINVAL; |
| 4461 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4463 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4464 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4465 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4466 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4467 | nfs4_free_createdata(data); |
| 4468 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | return status; |
| 4470 | } |
| 4471 | |
| 4472 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4473 | struct iattr *sattr, dev_t rdev) |
| 4474 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4475 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4477 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4479 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4480 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4481 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4482 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4483 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4485 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4486 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4487 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | &exception); |
| 4489 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4490 | |
| 4491 | nfs4_label_release_security(label); |
| 4492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | return err; |
| 4494 | } |
| 4495 | |
| 4496 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4497 | struct nfs_fsstat *fsstat) |
| 4498 | { |
| 4499 | struct nfs4_statfs_arg args = { |
| 4500 | .fh = fhandle, |
| 4501 | .bitmask = server->attr_bitmask, |
| 4502 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4503 | struct nfs4_statfs_res res = { |
| 4504 | .fsstat = fsstat, |
| 4505 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | struct rpc_message msg = { |
| 4507 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4508 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4509 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | }; |
| 4511 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4512 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4513 | 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] | 4514 | } |
| 4515 | |
| 4516 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4517 | { |
| 4518 | struct nfs4_exception exception = { }; |
| 4519 | int err; |
| 4520 | do { |
| 4521 | err = nfs4_handle_exception(server, |
| 4522 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4523 | &exception); |
| 4524 | } while (exception.retry); |
| 4525 | return err; |
| 4526 | } |
| 4527 | |
| 4528 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4529 | struct nfs_fsinfo *fsinfo) |
| 4530 | { |
| 4531 | struct nfs4_fsinfo_arg args = { |
| 4532 | .fh = fhandle, |
| 4533 | .bitmask = server->attr_bitmask, |
| 4534 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4535 | struct nfs4_fsinfo_res res = { |
| 4536 | .fsinfo = fsinfo, |
| 4537 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | struct rpc_message msg = { |
| 4539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4540 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4541 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | }; |
| 4543 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4544 | 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] | 4545 | } |
| 4546 | |
| 4547 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4548 | { |
| 4549 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4550 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | int err; |
| 4552 | |
| 4553 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4554 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4555 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4556 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4557 | nfs4_set_lease_period(server->nfs_client, |
| 4558 | fsinfo->lease_time * HZ, |
| 4559 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4560 | break; |
| 4561 | } |
| 4562 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | } while (exception.retry); |
| 4564 | return err; |
| 4565 | } |
| 4566 | |
| 4567 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4568 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4569 | int error; |
| 4570 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4571 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4572 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4573 | if (error == 0) { |
| 4574 | /* block layout checks this! */ |
| 4575 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4576 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4577 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4578 | |
| 4579 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4583 | struct nfs_pathconf *pathconf) |
| 4584 | { |
| 4585 | struct nfs4_pathconf_arg args = { |
| 4586 | .fh = fhandle, |
| 4587 | .bitmask = server->attr_bitmask, |
| 4588 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4589 | struct nfs4_pathconf_res res = { |
| 4590 | .pathconf = pathconf, |
| 4591 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | struct rpc_message msg = { |
| 4593 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4594 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4595 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | }; |
| 4597 | |
| 4598 | /* None of the pathconf attributes are mandatory to implement */ |
| 4599 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4600 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4601 | return 0; |
| 4602 | } |
| 4603 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4604 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4605 | 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] | 4606 | } |
| 4607 | |
| 4608 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4609 | struct nfs_pathconf *pathconf) |
| 4610 | { |
| 4611 | struct nfs4_exception exception = { }; |
| 4612 | int err; |
| 4613 | |
| 4614 | do { |
| 4615 | err = nfs4_handle_exception(server, |
| 4616 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4617 | &exception); |
| 4618 | } while (exception.retry); |
| 4619 | return err; |
| 4620 | } |
| 4621 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4622 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4623 | const struct nfs_open_context *ctx, |
| 4624 | const struct nfs_lock_context *l_ctx, |
| 4625 | fmode_t fmode) |
| 4626 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4627 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4628 | } |
| 4629 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4630 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4631 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4632 | const struct nfs_open_context *ctx, |
| 4633 | const struct nfs_lock_context *l_ctx, |
| 4634 | fmode_t fmode) |
| 4635 | { |
| 4636 | nfs4_stateid current_stateid; |
| 4637 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4638 | /* If the current stateid represents a lost lock, then exit */ |
| 4639 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4640 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4641 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4642 | } |
| 4643 | |
| 4644 | static bool nfs4_error_stateid_expired(int err) |
| 4645 | { |
| 4646 | switch (err) { |
| 4647 | case -NFS4ERR_DELEG_REVOKED: |
| 4648 | case -NFS4ERR_ADMIN_REVOKED: |
| 4649 | case -NFS4ERR_BAD_STATEID: |
| 4650 | case -NFS4ERR_STALE_STATEID: |
| 4651 | case -NFS4ERR_OLD_STATEID: |
| 4652 | case -NFS4ERR_OPENMODE: |
| 4653 | case -NFS4ERR_EXPIRED: |
| 4654 | return true; |
| 4655 | } |
| 4656 | return false; |
| 4657 | } |
| 4658 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4659 | 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] | 4660 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4661 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4663 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4664 | if (task->tk_status < 0) { |
| 4665 | struct nfs4_exception exception = { |
| 4666 | .inode = hdr->inode, |
| 4667 | .state = hdr->args.context->state, |
| 4668 | .stateid = &hdr->args.stateid, |
| 4669 | }; |
| 4670 | task->tk_status = nfs4_async_handle_exception(task, |
| 4671 | server, task->tk_status, &exception); |
| 4672 | if (exception.retry) { |
| 4673 | rpc_restart_call_prepare(task); |
| 4674 | return -EAGAIN; |
| 4675 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4679 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4680 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | } |
| 4682 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4683 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4684 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4685 | { |
| 4686 | |
| 4687 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4688 | nfs4_stateid_is_current(&args->stateid, |
| 4689 | args->context, |
| 4690 | args->lock_context, |
| 4691 | FMODE_READ)) |
| 4692 | return false; |
| 4693 | rpc_restart_call_prepare(task); |
| 4694 | return true; |
| 4695 | } |
| 4696 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4697 | 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] | 4698 | { |
| 4699 | |
| 4700 | dprintk("--> %s\n", __func__); |
| 4701 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4702 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4703 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4704 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4705 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4706 | if (task->tk_status > 0) |
| 4707 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4708 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4709 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4712 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4713 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4715 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4716 | if (!hdr->pgio_done_cb) |
| 4717 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4718 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4719 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4722 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4723 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4724 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 4725 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4726 | &hdr->args.seq_args, |
| 4727 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4728 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4729 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4730 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4731 | hdr->args.lock_context, |
| 4732 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4733 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4734 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4735 | return -EIO; |
| 4736 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | } |
| 4738 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4739 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4740 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4742 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4743 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4744 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4745 | if (task->tk_status < 0) { |
| 4746 | struct nfs4_exception exception = { |
| 4747 | .inode = hdr->inode, |
| 4748 | .state = hdr->args.context->state, |
| 4749 | .stateid = &hdr->args.stateid, |
| 4750 | }; |
| 4751 | task->tk_status = nfs4_async_handle_exception(task, |
| 4752 | NFS_SERVER(inode), task->tk_status, |
| 4753 | &exception); |
| 4754 | if (exception.retry) { |
| 4755 | rpc_restart_call_prepare(task); |
| 4756 | return -EAGAIN; |
| 4757 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4759 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4760 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4761 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4762 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4763 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | } |
| 4765 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4766 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4767 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4768 | { |
| 4769 | |
| 4770 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4771 | nfs4_stateid_is_current(&args->stateid, |
| 4772 | args->context, |
| 4773 | args->lock_context, |
| 4774 | FMODE_WRITE)) |
| 4775 | return false; |
| 4776 | rpc_restart_call_prepare(task); |
| 4777 | return true; |
| 4778 | } |
| 4779 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4780 | 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] | 4781 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4782 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4783 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4784 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4785 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4786 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4787 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4788 | } |
| 4789 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4790 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4791 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4792 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4793 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4794 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4795 | return false; |
| 4796 | /* Otherwise, request attributes if and only if we don't hold |
| 4797 | * a delegation |
| 4798 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4799 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4800 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4801 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4802 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4803 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4805 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4806 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4807 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4808 | hdr->args.bitmask = NULL; |
| 4809 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4810 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4811 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4812 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4813 | if (!hdr->pgio_done_cb) |
| 4814 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4815 | hdr->res.server = server; |
| 4816 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4818 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4819 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | } |
| 4821 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4822 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4823 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 4824 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4825 | &data->args.seq_args, |
| 4826 | &data->res.seq_res, |
| 4827 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | } |
| 4829 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4830 | 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] | 4831 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4833 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4834 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4835 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4836 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4837 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4838 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4840 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4843 | 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] | 4844 | { |
| 4845 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4846 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4847 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4848 | } |
| 4849 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4850 | 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] | 4851 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4852 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4853 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4854 | if (data->commit_done_cb == NULL) |
| 4855 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4856 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4857 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4858 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | } |
| 4860 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4861 | struct nfs4_renewdata { |
| 4862 | struct nfs_client *client; |
| 4863 | unsigned long timestamp; |
| 4864 | }; |
| 4865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | /* |
| 4867 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4868 | * standalone procedure for queueing an asynchronous RENEW. |
| 4869 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4870 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4871 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4872 | struct nfs4_renewdata *data = calldata; |
| 4873 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4874 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4875 | if (atomic_read(&clp->cl_count) > 1) |
| 4876 | nfs4_schedule_state_renewal(clp); |
| 4877 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4878 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4879 | } |
| 4880 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4881 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4883 | struct nfs4_renewdata *data = calldata; |
| 4884 | struct nfs_client *clp = data->client; |
| 4885 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4887 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4888 | switch (task->tk_status) { |
| 4889 | case 0: |
| 4890 | break; |
| 4891 | case -NFS4ERR_LEASE_MOVED: |
| 4892 | nfs4_schedule_lease_moved_recovery(clp); |
| 4893 | break; |
| 4894 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4895 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4896 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4897 | return; |
| 4898 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4899 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4900 | return; |
| 4901 | } |
| 4902 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4904 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | } |
| 4906 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4907 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4908 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4909 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4910 | }; |
| 4911 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4912 | 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] | 4913 | { |
| 4914 | struct rpc_message msg = { |
| 4915 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4916 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4917 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4919 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4921 | if (renew_flags == 0) |
| 4922 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4923 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4924 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4925 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4926 | if (data == NULL) |
| 4927 | return -ENOMEM; |
| 4928 | data->client = clp; |
| 4929 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4930 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4931 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4934 | 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] | 4935 | { |
| 4936 | struct rpc_message msg = { |
| 4937 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4938 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4939 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | }; |
| 4941 | unsigned long now = jiffies; |
| 4942 | int status; |
| 4943 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4944 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | if (status < 0) |
| 4946 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4947 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | return 0; |
| 4949 | } |
| 4950 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4951 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4952 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4953 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4956 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4957 | * 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] | 4958 | * the stack. |
| 4959 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4960 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4961 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4962 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4963 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4964 | { |
| 4965 | struct page *newpage, **spages; |
| 4966 | int rc = 0; |
| 4967 | size_t len; |
| 4968 | spages = pages; |
| 4969 | |
| 4970 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4971 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4972 | newpage = alloc_page(GFP_KERNEL); |
| 4973 | |
| 4974 | if (newpage == NULL) |
| 4975 | goto unwind; |
| 4976 | memcpy(page_address(newpage), buf, len); |
| 4977 | buf += len; |
| 4978 | buflen -= len; |
| 4979 | *pages++ = newpage; |
| 4980 | rc++; |
| 4981 | } while (buflen != 0); |
| 4982 | |
| 4983 | return rc; |
| 4984 | |
| 4985 | unwind: |
| 4986 | for(; rc > 0; rc--) |
| 4987 | __free_page(spages[rc-1]); |
| 4988 | return -ENOMEM; |
| 4989 | } |
| 4990 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4991 | struct nfs4_cached_acl { |
| 4992 | int cached; |
| 4993 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4994 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4995 | }; |
| 4996 | |
| 4997 | 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] | 4998 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4999 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5000 | |
| 5001 | spin_lock(&inode->i_lock); |
| 5002 | kfree(nfsi->nfs4_acl); |
| 5003 | nfsi->nfs4_acl = acl; |
| 5004 | spin_unlock(&inode->i_lock); |
| 5005 | } |
| 5006 | |
| 5007 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5008 | { |
| 5009 | nfs4_set_cached_acl(inode, NULL); |
| 5010 | } |
| 5011 | |
| 5012 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5013 | { |
| 5014 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5015 | struct nfs4_cached_acl *acl; |
| 5016 | int ret = -ENOENT; |
| 5017 | |
| 5018 | spin_lock(&inode->i_lock); |
| 5019 | acl = nfsi->nfs4_acl; |
| 5020 | if (acl == NULL) |
| 5021 | goto out; |
| 5022 | if (buf == NULL) /* user is just asking for length */ |
| 5023 | goto out_len; |
| 5024 | if (acl->cached == 0) |
| 5025 | goto out; |
| 5026 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5027 | if (acl->len > buflen) |
| 5028 | goto out; |
| 5029 | memcpy(buf, acl->data, acl->len); |
| 5030 | out_len: |
| 5031 | ret = acl->len; |
| 5032 | out: |
| 5033 | spin_unlock(&inode->i_lock); |
| 5034 | return ret; |
| 5035 | } |
| 5036 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5037 | 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] | 5038 | { |
| 5039 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5040 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5041 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5042 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5043 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5044 | if (acl == NULL) |
| 5045 | goto out; |
| 5046 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5047 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5048 | } else { |
| 5049 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5050 | if (acl == NULL) |
| 5051 | goto out; |
| 5052 | acl->cached = 0; |
| 5053 | } |
| 5054 | acl->len = acl_len; |
| 5055 | out: |
| 5056 | nfs4_set_cached_acl(inode, acl); |
| 5057 | } |
| 5058 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5059 | /* |
| 5060 | * The getxattr API returns the required buffer length when called with a |
| 5061 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5062 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5063 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5064 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5065 | * the cache. If not so, we throw away the page, and cache the required |
| 5066 | * length. The next getxattr call will then produce another round trip to |
| 5067 | * the server, this time with the input buf of the required size. |
| 5068 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5069 | 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] | 5070 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5071 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5072 | struct nfs_getaclargs args = { |
| 5073 | .fh = NFS_FH(inode), |
| 5074 | .acl_pages = pages, |
| 5075 | .acl_len = buflen, |
| 5076 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5077 | struct nfs_getaclres res = { |
| 5078 | .acl_len = buflen, |
| 5079 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5080 | struct rpc_message msg = { |
| 5081 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5082 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5083 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5084 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5085 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 5086 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5087 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5088 | /* As long as we're doing a round trip to the server anyway, |
| 5089 | * let's be prepared for a page of acl data. */ |
| 5090 | if (npages == 0) |
| 5091 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5092 | if (npages > ARRAY_SIZE(pages)) |
| 5093 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5094 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5095 | for (i = 0; i < npages; i++) { |
| 5096 | pages[i] = alloc_page(GFP_KERNEL); |
| 5097 | if (!pages[i]) |
| 5098 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5099 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5100 | |
| 5101 | /* for decoding across pages */ |
| 5102 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5103 | if (!res.acl_scratch) |
| 5104 | goto out_free; |
| 5105 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5106 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5107 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5108 | 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] | 5109 | __func__, buf, buflen, npages, args.acl_len); |
| 5110 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5111 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5112 | if (ret) |
| 5113 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5114 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5115 | /* Handle the case where the passed-in buffer is too short */ |
| 5116 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5117 | /* Did the user only issue a request for the acl length? */ |
| 5118 | if (buf == NULL) |
| 5119 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5120 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5121 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5122 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5123 | 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] | 5124 | if (buf) { |
| 5125 | if (res.acl_len > buflen) { |
| 5126 | ret = -ERANGE; |
| 5127 | goto out_free; |
| 5128 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5129 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5130 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5131 | out_ok: |
| 5132 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5133 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5134 | for (i = 0; i < npages; i++) |
| 5135 | if (pages[i]) |
| 5136 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5137 | if (res.acl_scratch) |
| 5138 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5139 | return ret; |
| 5140 | } |
| 5141 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5142 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5143 | { |
| 5144 | struct nfs4_exception exception = { }; |
| 5145 | ssize_t ret; |
| 5146 | do { |
| 5147 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5148 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5149 | if (ret >= 0) |
| 5150 | break; |
| 5151 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5152 | } while (exception.retry); |
| 5153 | return ret; |
| 5154 | } |
| 5155 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5156 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5157 | { |
| 5158 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5159 | int ret; |
| 5160 | |
| 5161 | if (!nfs4_server_supports_acls(server)) |
| 5162 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5163 | ret = nfs_revalidate_inode(server, inode); |
| 5164 | if (ret < 0) |
| 5165 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5166 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5167 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5168 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5169 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5170 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5171 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5172 | return ret; |
| 5173 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5174 | } |
| 5175 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5176 | 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] | 5177 | { |
| 5178 | struct nfs_server *server = NFS_SERVER(inode); |
| 5179 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5180 | struct nfs_setaclargs arg = { |
| 5181 | .fh = NFS_FH(inode), |
| 5182 | .acl_pages = pages, |
| 5183 | .acl_len = buflen, |
| 5184 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5185 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5186 | struct rpc_message msg = { |
| 5187 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5188 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5189 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5190 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5191 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5192 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5193 | |
| 5194 | if (!nfs4_server_supports_acls(server)) |
| 5195 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5196 | if (npages > ARRAY_SIZE(pages)) |
| 5197 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5198 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5199 | if (i < 0) |
| 5200 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5201 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5202 | 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] | 5203 | |
| 5204 | /* |
| 5205 | * Free each page after tx, so the only ref left is |
| 5206 | * held by the network stack |
| 5207 | */ |
| 5208 | for (; i > 0; i--) |
| 5209 | put_page(pages[i-1]); |
| 5210 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5211 | /* |
| 5212 | * Acl update can result in inode attribute update. |
| 5213 | * so mark the attribute cache invalid. |
| 5214 | */ |
| 5215 | spin_lock(&inode->i_lock); |
| 5216 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5217 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5218 | nfs_access_zap_cache(inode); |
| 5219 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5220 | return ret; |
| 5221 | } |
| 5222 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5223 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5224 | { |
| 5225 | struct nfs4_exception exception = { }; |
| 5226 | int err; |
| 5227 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5228 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5229 | trace_nfs4_set_acl(inode, err); |
| 5230 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5231 | &exception); |
| 5232 | } while (exception.retry); |
| 5233 | return err; |
| 5234 | } |
| 5235 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5236 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5237 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5238 | size_t buflen) |
| 5239 | { |
| 5240 | struct nfs_server *server = NFS_SERVER(inode); |
| 5241 | struct nfs_fattr fattr; |
| 5242 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5243 | |
| 5244 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5245 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5246 | .fh = NFS_FH(inode), |
| 5247 | .bitmask = bitmask, |
| 5248 | }; |
| 5249 | struct nfs4_getattr_res res = { |
| 5250 | .fattr = &fattr, |
| 5251 | .label = &label, |
| 5252 | .server = server, |
| 5253 | }; |
| 5254 | struct rpc_message msg = { |
| 5255 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5256 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5257 | .rpc_resp = &res, |
| 5258 | }; |
| 5259 | int ret; |
| 5260 | |
| 5261 | nfs_fattr_init(&fattr); |
| 5262 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5263 | 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] | 5264 | if (ret) |
| 5265 | return ret; |
| 5266 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5267 | return -ENOENT; |
| 5268 | if (buflen < label.len) |
| 5269 | return -ERANGE; |
| 5270 | return 0; |
| 5271 | } |
| 5272 | |
| 5273 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5274 | size_t buflen) |
| 5275 | { |
| 5276 | struct nfs4_exception exception = { }; |
| 5277 | int err; |
| 5278 | |
| 5279 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5280 | return -EOPNOTSUPP; |
| 5281 | |
| 5282 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5283 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5284 | trace_nfs4_get_security_label(inode, err); |
| 5285 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5286 | &exception); |
| 5287 | } while (exception.retry); |
| 5288 | return err; |
| 5289 | } |
| 5290 | |
| 5291 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5292 | struct nfs4_label *ilabel, |
| 5293 | struct nfs_fattr *fattr, |
| 5294 | struct nfs4_label *olabel) |
| 5295 | { |
| 5296 | |
| 5297 | struct iattr sattr = {0}; |
| 5298 | struct nfs_server *server = NFS_SERVER(inode); |
| 5299 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5300 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5301 | .fh = NFS_FH(inode), |
| 5302 | .iap = &sattr, |
| 5303 | .server = server, |
| 5304 | .bitmask = bitmask, |
| 5305 | .label = ilabel, |
| 5306 | }; |
| 5307 | struct nfs_setattrres res = { |
| 5308 | .fattr = fattr, |
| 5309 | .label = olabel, |
| 5310 | .server = server, |
| 5311 | }; |
| 5312 | struct rpc_message msg = { |
| 5313 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5314 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5315 | .rpc_resp = &res, |
| 5316 | }; |
| 5317 | int status; |
| 5318 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5319 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5320 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5321 | 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] | 5322 | if (status) |
| 5323 | dprintk("%s failed: %d\n", __func__, status); |
| 5324 | |
| 5325 | return status; |
| 5326 | } |
| 5327 | |
| 5328 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5329 | struct nfs4_label *ilabel, |
| 5330 | struct nfs_fattr *fattr, |
| 5331 | struct nfs4_label *olabel) |
| 5332 | { |
| 5333 | struct nfs4_exception exception = { }; |
| 5334 | int err; |
| 5335 | |
| 5336 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5337 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5338 | fattr, olabel); |
| 5339 | trace_nfs4_set_security_label(inode, err); |
| 5340 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5341 | &exception); |
| 5342 | } while (exception.retry); |
| 5343 | return err; |
| 5344 | } |
| 5345 | |
| 5346 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5347 | 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] | 5348 | { |
| 5349 | struct nfs4_label ilabel, *olabel = NULL; |
| 5350 | struct nfs_fattr fattr; |
| 5351 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5352 | int status; |
| 5353 | |
| 5354 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5355 | return -EOPNOTSUPP; |
| 5356 | |
| 5357 | nfs_fattr_init(&fattr); |
| 5358 | |
| 5359 | ilabel.pi = 0; |
| 5360 | ilabel.lfs = 0; |
| 5361 | ilabel.label = (char *)buf; |
| 5362 | ilabel.len = buflen; |
| 5363 | |
| 5364 | cred = rpc_lookup_cred(); |
| 5365 | if (IS_ERR(cred)) |
| 5366 | return PTR_ERR(cred); |
| 5367 | |
| 5368 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5369 | if (IS_ERR(olabel)) { |
| 5370 | status = -PTR_ERR(olabel); |
| 5371 | goto out; |
| 5372 | } |
| 5373 | |
| 5374 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5375 | if (status == 0) |
| 5376 | nfs_setsecurity(inode, &fattr, olabel); |
| 5377 | |
| 5378 | nfs4_label_free(olabel); |
| 5379 | out: |
| 5380 | put_rpccred(cred); |
| 5381 | return status; |
| 5382 | } |
| 5383 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5384 | |
| 5385 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5386 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5387 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5388 | { |
| 5389 | __be32 verf[2]; |
| 5390 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5391 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5392 | /* An impossible timestamp guarantees this value |
| 5393 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5394 | verf[0] = cpu_to_be32(U32_MAX); |
| 5395 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5396 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5397 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5398 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5399 | |
| 5400 | verf[0] = cpu_to_be32(ns >> 32); |
| 5401 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5402 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5403 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5404 | } |
| 5405 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5406 | static int |
| 5407 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5408 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5409 | size_t len; |
| 5410 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5411 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5412 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5413 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5414 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5415 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5416 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5417 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5418 | 1 + |
| 5419 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5420 | 1; |
| 5421 | rcu_read_unlock(); |
| 5422 | |
| 5423 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5424 | return -EINVAL; |
| 5425 | |
| 5426 | /* |
| 5427 | * Since this string is allocated at mount time, and held until the |
| 5428 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5429 | * about a memory-reclaim deadlock. |
| 5430 | */ |
| 5431 | str = kmalloc(len, GFP_KERNEL); |
| 5432 | if (!str) |
| 5433 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5434 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5435 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5436 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5437 | clp->cl_ipaddr, |
| 5438 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5439 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5440 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5441 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5442 | clp->cl_owner_id = str; |
| 5443 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5444 | } |
| 5445 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5446 | static int |
| 5447 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5448 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5449 | size_t len; |
| 5450 | char *str; |
| 5451 | |
| 5452 | len = 10 + 10 + 1 + 10 + 1 + |
| 5453 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5454 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5455 | |
| 5456 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5457 | return -EINVAL; |
| 5458 | |
| 5459 | /* |
| 5460 | * Since this string is allocated at mount time, and held until the |
| 5461 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5462 | * about a memory-reclaim deadlock. |
| 5463 | */ |
| 5464 | str = kmalloc(len, GFP_KERNEL); |
| 5465 | if (!str) |
| 5466 | return -ENOMEM; |
| 5467 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5468 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5469 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5470 | nfs4_client_id_uniquifier, |
| 5471 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5472 | clp->cl_owner_id = str; |
| 5473 | return 0; |
| 5474 | } |
| 5475 | |
| 5476 | static int |
| 5477 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5478 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5479 | size_t len; |
| 5480 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5481 | |
| 5482 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5483 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5484 | |
| 5485 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5486 | return nfs4_init_uniquifier_client_string(clp); |
| 5487 | |
| 5488 | len = 10 + 10 + 1 + 10 + 1 + |
| 5489 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5490 | |
| 5491 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5492 | return -EINVAL; |
| 5493 | |
| 5494 | /* |
| 5495 | * Since this string is allocated at mount time, and held until the |
| 5496 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5497 | * about a memory-reclaim deadlock. |
| 5498 | */ |
| 5499 | str = kmalloc(len, GFP_KERNEL); |
| 5500 | if (!str) |
| 5501 | return -ENOMEM; |
| 5502 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5503 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5504 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5505 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5506 | clp->cl_owner_id = str; |
| 5507 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5508 | } |
| 5509 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5510 | /* |
| 5511 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5512 | * services. Advertise one based on the address family of the |
| 5513 | * clientaddr. |
| 5514 | */ |
| 5515 | static unsigned int |
| 5516 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5517 | { |
| 5518 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5519 | return scnprintf(buf, len, "tcp6"); |
| 5520 | else |
| 5521 | return scnprintf(buf, len, "tcp"); |
| 5522 | } |
| 5523 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5524 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5525 | { |
| 5526 | struct nfs4_setclientid *sc = calldata; |
| 5527 | |
| 5528 | if (task->tk_status == 0) |
| 5529 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5530 | } |
| 5531 | |
| 5532 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5533 | .rpc_call_done = nfs4_setclientid_done, |
| 5534 | }; |
| 5535 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5536 | /** |
| 5537 | * nfs4_proc_setclientid - Negotiate client ID |
| 5538 | * @clp: state data structure |
| 5539 | * @program: RPC program for NFSv4 callback service |
| 5540 | * @port: IP port number for NFS4 callback service |
| 5541 | * @cred: RPC credential to use for this call |
| 5542 | * @res: where to place the result |
| 5543 | * |
| 5544 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5545 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5546 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5547 | unsigned short port, struct rpc_cred *cred, |
| 5548 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | { |
| 5550 | nfs4_verifier sc_verifier; |
| 5551 | struct nfs4_setclientid setclientid = { |
| 5552 | .sc_verifier = &sc_verifier, |
| 5553 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5554 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | }; |
| 5556 | struct rpc_message msg = { |
| 5557 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5558 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5559 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5560 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5561 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5562 | struct rpc_task *task; |
| 5563 | struct rpc_task_setup task_setup_data = { |
| 5564 | .rpc_client = clp->cl_rpcclient, |
| 5565 | .rpc_message = &msg, |
| 5566 | .callback_ops = &nfs4_setclientid_ops, |
| 5567 | .callback_data = &setclientid, |
| 5568 | .flags = RPC_TASK_TIMEOUT, |
| 5569 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5570 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5572 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5573 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5574 | |
| 5575 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5576 | status = nfs4_init_uniform_client_string(clp); |
| 5577 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5578 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5579 | |
| 5580 | if (status) |
| 5581 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5582 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5583 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5584 | setclientid.sc_netid_len = |
| 5585 | nfs4_init_callback_netid(clp, |
| 5586 | setclientid.sc_netid, |
| 5587 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5588 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5589 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5591 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5592 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5593 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5594 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5595 | task = rpc_run_task(&task_setup_data); |
| 5596 | if (IS_ERR(task)) { |
| 5597 | status = PTR_ERR(task); |
| 5598 | goto out; |
| 5599 | } |
| 5600 | status = task->tk_status; |
| 5601 | if (setclientid.sc_cred) { |
| 5602 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5603 | put_rpccred(setclientid.sc_cred); |
| 5604 | } |
| 5605 | rpc_put_task(task); |
| 5606 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5607 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5608 | dprintk("NFS reply setclientid: %d\n", status); |
| 5609 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | } |
| 5611 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5612 | /** |
| 5613 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5614 | * @clp: state data structure |
| 5615 | * @res: result of a previous SETCLIENTID |
| 5616 | * @cred: RPC credential to use for this call |
| 5617 | * |
| 5618 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5619 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5620 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5621 | struct nfs4_setclientid_res *arg, |
| 5622 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | struct rpc_message msg = { |
| 5625 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5626 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5627 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5629 | int status; |
| 5630 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5631 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5632 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5633 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5634 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5635 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5636 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5637 | return status; |
| 5638 | } |
| 5639 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5640 | struct nfs4_delegreturndata { |
| 5641 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5642 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5643 | struct nfs_fh fh; |
| 5644 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5645 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5646 | struct { |
| 5647 | struct nfs4_layoutreturn_args arg; |
| 5648 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5649 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5650 | u32 roc_barrier; |
| 5651 | bool roc; |
| 5652 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5653 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5654 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5655 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5656 | }; |
| 5657 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5658 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5659 | { |
| 5660 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5661 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5662 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5663 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5664 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5665 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5666 | |
| 5667 | /* Handle Layoutreturn errors */ |
| 5668 | if (data->args.lr_args && task->tk_status != 0) { |
| 5669 | switch(data->res.lr_ret) { |
| 5670 | default: |
| 5671 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5672 | break; |
| 5673 | case 0: |
| 5674 | data->args.lr_args = NULL; |
| 5675 | data->res.lr_res = NULL; |
| 5676 | break; |
| 5677 | case -NFS4ERR_ADMIN_REVOKED: |
| 5678 | case -NFS4ERR_DELEG_REVOKED: |
| 5679 | case -NFS4ERR_EXPIRED: |
| 5680 | case -NFS4ERR_BAD_STATEID: |
| 5681 | case -NFS4ERR_OLD_STATEID: |
| 5682 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5683 | case -NFS4ERR_WRONG_CRED: |
| 5684 | data->args.lr_args = NULL; |
| 5685 | data->res.lr_res = NULL; |
| 5686 | data->res.lr_ret = 0; |
| 5687 | rpc_restart_call_prepare(task); |
| 5688 | return; |
| 5689 | } |
| 5690 | } |
| 5691 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5692 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5693 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5694 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5695 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5696 | case -NFS4ERR_ADMIN_REVOKED: |
| 5697 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5698 | case -NFS4ERR_EXPIRED: |
| 5699 | nfs4_free_revoked_stateid(data->res.server, |
| 5700 | data->args.stateid, |
| 5701 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5702 | case -NFS4ERR_BAD_STATEID: |
| 5703 | case -NFS4ERR_OLD_STATEID: |
| 5704 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5705 | task->tk_status = 0; |
| 5706 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5707 | case -NFS4ERR_ACCESS: |
| 5708 | if (data->args.bitmask) { |
| 5709 | data->args.bitmask = NULL; |
| 5710 | data->res.fattr = NULL; |
| 5711 | task->tk_status = 0; |
| 5712 | rpc_restart_call_prepare(task); |
| 5713 | return; |
| 5714 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5715 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5716 | if (nfs4_async_handle_error(task, data->res.server, |
| 5717 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5718 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5719 | return; |
| 5720 | } |
| 5721 | } |
| 5722 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | static void nfs4_delegreturn_release(void *calldata) |
| 5726 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5727 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5728 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5729 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5730 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5731 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5732 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5733 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5734 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5735 | nfs_iput_and_deactive(inode); |
| 5736 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5737 | kfree(calldata); |
| 5738 | } |
| 5739 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5740 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5741 | { |
| 5742 | struct nfs4_delegreturndata *d_data; |
| 5743 | |
| 5744 | d_data = (struct nfs4_delegreturndata *)data; |
| 5745 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5746 | 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] | 5747 | return; |
| 5748 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 5749 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5750 | &d_data->args.seq_args, |
| 5751 | &d_data->res.seq_res, |
| 5752 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5753 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5754 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5755 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5756 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5757 | .rpc_call_done = nfs4_delegreturn_done, |
| 5758 | .rpc_release = nfs4_delegreturn_release, |
| 5759 | }; |
| 5760 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5761 | 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] | 5762 | { |
| 5763 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5764 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5765 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5766 | struct rpc_message msg = { |
| 5767 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5768 | .rpc_cred = cred, |
| 5769 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5770 | struct rpc_task_setup task_setup_data = { |
| 5771 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5772 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5773 | .callback_ops = &nfs4_delegreturn_ops, |
| 5774 | .flags = RPC_TASK_ASYNC, |
| 5775 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5776 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5777 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5778 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5779 | if (data == NULL) |
| 5780 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5781 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5782 | |
| 5783 | nfs4_state_protect(server->nfs_client, |
| 5784 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5785 | &task_setup_data.rpc_client, &msg); |
| 5786 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5787 | data->args.fhandle = &data->fh; |
| 5788 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5789 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5790 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5791 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5792 | data->res.fattr = &data->fattr; |
| 5793 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5794 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5795 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5796 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5797 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5798 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5799 | 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] | 5800 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5801 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5802 | if (data->lr.roc) { |
| 5803 | data->args.lr_args = &data->lr.arg; |
| 5804 | data->res.lr_res = &data->lr.res; |
| 5805 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5806 | } else if (data->lr.roc) { |
| 5807 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5808 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5809 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5810 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5811 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5812 | msg.rpc_argp = &data->args; |
| 5813 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5814 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5815 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5816 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5817 | if (!issync) |
| 5818 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5819 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5820 | if (status != 0) |
| 5821 | goto out; |
| 5822 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5823 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5824 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5825 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | } |
| 5827 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5828 | 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] | 5829 | { |
| 5830 | struct nfs_server *server = NFS_SERVER(inode); |
| 5831 | struct nfs4_exception exception = { }; |
| 5832 | int err; |
| 5833 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5834 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5835 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | switch (err) { |
| 5837 | case -NFS4ERR_STALE_STATEID: |
| 5838 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5839 | case 0: |
| 5840 | return 0; |
| 5841 | } |
| 5842 | err = nfs4_handle_exception(server, err, &exception); |
| 5843 | } while (exception.retry); |
| 5844 | return err; |
| 5845 | } |
| 5846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5848 | { |
| 5849 | struct inode *inode = state->inode; |
| 5850 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5851 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5852 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5854 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5855 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5856 | struct nfs_lockt_res res = { |
| 5857 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | }; |
| 5859 | struct rpc_message msg = { |
| 5860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5861 | .rpc_argp = &arg, |
| 5862 | .rpc_resp = &res, |
| 5863 | .rpc_cred = state->owner->so_cred, |
| 5864 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5865 | struct nfs4_lock_state *lsp; |
| 5866 | int status; |
| 5867 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5868 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5869 | status = nfs4_set_lock_state(state, request); |
| 5870 | if (status != 0) |
| 5871 | goto out; |
| 5872 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5873 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5874 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5875 | 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] | 5876 | switch (status) { |
| 5877 | case 0: |
| 5878 | request->fl_type = F_UNLCK; |
| 5879 | break; |
| 5880 | case -NFS4ERR_DENIED: |
| 5881 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5883 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5884 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5885 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5886 | return status; |
| 5887 | } |
| 5888 | |
| 5889 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5890 | { |
| 5891 | struct nfs4_exception exception = { }; |
| 5892 | int err; |
| 5893 | |
| 5894 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5895 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5896 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5897 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5898 | &exception); |
| 5899 | } while (exception.retry); |
| 5900 | return err; |
| 5901 | } |
| 5902 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5903 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5904 | struct nfs_locku_args arg; |
| 5905 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5906 | struct nfs4_lock_state *lsp; |
| 5907 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5908 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5909 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5910 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5911 | }; |
| 5912 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5913 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5914 | struct nfs_open_context *ctx, |
| 5915 | struct nfs4_lock_state *lsp, |
| 5916 | struct nfs_seqid *seqid) |
| 5917 | { |
| 5918 | struct nfs4_unlockdata *p; |
| 5919 | struct inode *inode = lsp->ls_state->inode; |
| 5920 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5921 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5922 | if (p == NULL) |
| 5923 | return NULL; |
| 5924 | p->arg.fh = NFS_FH(inode); |
| 5925 | p->arg.fl = &p->fl; |
| 5926 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5927 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5928 | p->lsp = lsp; |
| 5929 | atomic_inc(&lsp->ls_count); |
| 5930 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5931 | p->ctx = get_nfs_open_context(ctx); |
| 5932 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5933 | p->server = NFS_SERVER(inode); |
| 5934 | return p; |
| 5935 | } |
| 5936 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5937 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5938 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5939 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5940 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5941 | nfs4_put_lock_state(calldata->lsp); |
| 5942 | put_nfs_open_context(calldata->ctx); |
| 5943 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5944 | } |
| 5945 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5946 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5947 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5948 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5949 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5950 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5951 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5952 | switch (task->tk_status) { |
| 5953 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5954 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5955 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5956 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5957 | &calldata->res.stateid)) |
| 5958 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5959 | case -NFS4ERR_ADMIN_REVOKED: |
| 5960 | case -NFS4ERR_EXPIRED: |
| 5961 | nfs4_free_revoked_stateid(calldata->server, |
| 5962 | &calldata->arg.stateid, |
| 5963 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5964 | case -NFS4ERR_BAD_STATEID: |
| 5965 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5966 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5967 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5968 | &calldata->lsp->ls_stateid)) |
| 5969 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5970 | break; |
| 5971 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5972 | if (nfs4_async_handle_error(task, calldata->server, |
| 5973 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5974 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5975 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5976 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5977 | } |
| 5978 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5979 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5980 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5981 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5982 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5983 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5984 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5985 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5986 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5987 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5988 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5989 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5990 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 5991 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5992 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5993 | &calldata->res.seq_res, |
| 5994 | task) != 0) |
| 5995 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5996 | return; |
| 5997 | out_no_action: |
| 5998 | task->tk_action = NULL; |
| 5999 | out_wait: |
| 6000 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6003 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6004 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6005 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6006 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6007 | }; |
| 6008 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6009 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6010 | struct nfs_open_context *ctx, |
| 6011 | struct nfs4_lock_state *lsp, |
| 6012 | struct nfs_seqid *seqid) |
| 6013 | { |
| 6014 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6015 | struct rpc_message msg = { |
| 6016 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6017 | .rpc_cred = ctx->cred, |
| 6018 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6019 | struct rpc_task_setup task_setup_data = { |
| 6020 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6021 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6022 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6023 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6024 | .flags = RPC_TASK_ASYNC, |
| 6025 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6026 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6027 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6028 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6029 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6030 | /* Ensure this is an unlock - when canceling a lock, the |
| 6031 | * canceled lock is passed in, and it won't be an unlock. |
| 6032 | */ |
| 6033 | fl->fl_type = F_UNLCK; |
| 6034 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6035 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6036 | if (data == NULL) { |
| 6037 | nfs_free_seqid(seqid); |
| 6038 | return ERR_PTR(-ENOMEM); |
| 6039 | } |
| 6040 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6041 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6042 | msg.rpc_argp = &data->arg; |
| 6043 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6044 | task_setup_data.callback_data = data; |
| 6045 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6046 | } |
| 6047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6048 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6049 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6050 | struct inode *inode = state->inode; |
| 6051 | struct nfs4_state_owner *sp = state->owner; |
| 6052 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6053 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6054 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6055 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6056 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6057 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6058 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6060 | status = nfs4_set_lock_state(state, request); |
| 6061 | /* Unlock _before_ we do the RPC call */ |
| 6062 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6063 | /* Exclude nfs_delegation_claim_locks() */ |
| 6064 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6065 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6066 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6067 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6068 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6069 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6070 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6071 | } |
| 6072 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6073 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6074 | if (status != 0) |
| 6075 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6076 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6077 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6078 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6079 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6080 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6081 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6082 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6083 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6084 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6085 | 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] | 6086 | status = PTR_ERR(task); |
| 6087 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6088 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6089 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6090 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6091 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6092 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6093 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6094 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | } |
| 6096 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6097 | struct nfs4_lockdata { |
| 6098 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6099 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6100 | struct nfs4_lock_state *lsp; |
| 6101 | struct nfs_open_context *ctx; |
| 6102 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6103 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6104 | int rpc_status; |
| 6105 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6106 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6107 | }; |
| 6108 | |
| 6109 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6110 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6111 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6112 | { |
| 6113 | struct nfs4_lockdata *p; |
| 6114 | struct inode *inode = lsp->ls_state->inode; |
| 6115 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6116 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6117 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6118 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6119 | if (p == NULL) |
| 6120 | return NULL; |
| 6121 | |
| 6122 | p->arg.fh = NFS_FH(inode); |
| 6123 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6124 | 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] | 6125 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6126 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6127 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6128 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6129 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6130 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6131 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6132 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6133 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6134 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6135 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6136 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6137 | atomic_inc(&lsp->ls_count); |
| 6138 | p->ctx = get_nfs_open_context(ctx); |
| 6139 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6140 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6141 | out_free_seqid: |
| 6142 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6143 | out_free: |
| 6144 | kfree(p); |
| 6145 | return NULL; |
| 6146 | } |
| 6147 | |
| 6148 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6149 | { |
| 6150 | struct nfs4_lockdata *data = calldata; |
| 6151 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6153 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6154 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6155 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6156 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6157 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6158 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6159 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6160 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6161 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6162 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6163 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6164 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6165 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6166 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6167 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6168 | &data->lsp->ls_stateid); |
| 6169 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6170 | if (!nfs4_valid_open_stateid(state)) { |
| 6171 | data->rpc_status = -EBADF; |
| 6172 | task->tk_action = NULL; |
| 6173 | goto out_release_open_seqid; |
| 6174 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6175 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame^] | 6176 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6177 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6178 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6179 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6180 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6181 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6182 | nfs_release_seqid(data->arg.open_seqid); |
| 6183 | out_release_lock_seqid: |
| 6184 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6185 | out_wait: |
| 6186 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6187 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6188 | } |
| 6189 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6190 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6191 | { |
| 6192 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6193 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6194 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6195 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6196 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6197 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6198 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6199 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6200 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6201 | switch (task->tk_status) { |
| 6202 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6203 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6204 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6205 | if (data->arg.new_lock) { |
| 6206 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6207 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6208 | rpc_restart_call_prepare(task); |
| 6209 | break; |
| 6210 | } |
| 6211 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6212 | if (data->arg.new_lock_owner != 0) { |
| 6213 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6214 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6215 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6216 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6217 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6218 | break; |
| 6219 | case -NFS4ERR_BAD_STATEID: |
| 6220 | case -NFS4ERR_OLD_STATEID: |
| 6221 | case -NFS4ERR_STALE_STATEID: |
| 6222 | case -NFS4ERR_EXPIRED: |
| 6223 | if (data->arg.new_lock_owner != 0) { |
| 6224 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6225 | &lsp->ls_state->open_stateid)) |
| 6226 | rpc_restart_call_prepare(task); |
| 6227 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6228 | &lsp->ls_stateid)) |
| 6229 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6230 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6231 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | static void nfs4_lock_release(void *calldata) |
| 6235 | { |
| 6236 | struct nfs4_lockdata *data = calldata; |
| 6237 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6238 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6239 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6240 | if (data->cancelled != 0) { |
| 6241 | struct rpc_task *task; |
| 6242 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6243 | data->arg.lock_seqid); |
| 6244 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6245 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6246 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6247 | } else |
| 6248 | nfs_free_seqid(data->arg.lock_seqid); |
| 6249 | nfs4_put_lock_state(data->lsp); |
| 6250 | put_nfs_open_context(data->ctx); |
| 6251 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6252 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6256 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6257 | .rpc_call_done = nfs4_lock_done, |
| 6258 | .rpc_release = nfs4_lock_release, |
| 6259 | }; |
| 6260 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6261 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6262 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6263 | switch (error) { |
| 6264 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6265 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6266 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6267 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6268 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6269 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6270 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6271 | break; |
| 6272 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6273 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6274 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6275 | }; |
| 6276 | } |
| 6277 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6278 | 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] | 6279 | { |
| 6280 | struct nfs4_lockdata *data; |
| 6281 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6282 | struct rpc_message msg = { |
| 6283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6284 | .rpc_cred = state->owner->so_cred, |
| 6285 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6286 | struct rpc_task_setup task_setup_data = { |
| 6287 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6288 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6289 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6290 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6291 | .flags = RPC_TASK_ASYNC, |
| 6292 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6293 | int ret; |
| 6294 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6295 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6296 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6297 | fl->fl_u.nfs4_fl.owner, |
| 6298 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6299 | if (data == NULL) |
| 6300 | return -ENOMEM; |
| 6301 | if (IS_SETLKW(cmd)) |
| 6302 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6303 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6304 | msg.rpc_argp = &data->arg; |
| 6305 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6306 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6307 | if (recovery_type > NFS_LOCK_NEW) { |
| 6308 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6309 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6310 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6311 | } else |
| 6312 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6313 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6314 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6315 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6316 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6317 | if (ret == 0) { |
| 6318 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6319 | if (ret) |
| 6320 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6321 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6322 | } else |
| 6323 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6324 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6325 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6326 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6327 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6331 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6332 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6333 | struct nfs4_exception exception = { |
| 6334 | .inode = state->inode, |
| 6335 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6336 | int err; |
| 6337 | |
| 6338 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6339 | /* Cache the lock if possible... */ |
| 6340 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6341 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6342 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6343 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6344 | break; |
| 6345 | nfs4_handle_exception(server, err, &exception); |
| 6346 | } while (exception.retry); |
| 6347 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6351 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6352 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6353 | struct nfs4_exception exception = { |
| 6354 | .inode = state->inode, |
| 6355 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6356 | int err; |
| 6357 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6358 | err = nfs4_set_lock_state(state, request); |
| 6359 | if (err != 0) |
| 6360 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6361 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6362 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6363 | return 0; |
| 6364 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6365 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6366 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6367 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6368 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6369 | switch (err) { |
| 6370 | default: |
| 6371 | goto out; |
| 6372 | case -NFS4ERR_GRACE: |
| 6373 | case -NFS4ERR_DELAY: |
| 6374 | nfs4_handle_exception(server, err, &exception); |
| 6375 | err = 0; |
| 6376 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6377 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6378 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6379 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6380 | } |
| 6381 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6382 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6383 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6384 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6385 | struct nfs4_lock_state *lsp; |
| 6386 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6387 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6388 | status = nfs4_set_lock_state(state, request); |
| 6389 | if (status != 0) |
| 6390 | return status; |
| 6391 | lsp = request->fl_u.nfs4_fl.owner; |
| 6392 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6393 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6394 | return 0; |
| 6395 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6396 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6397 | } |
| 6398 | #endif |
| 6399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6400 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6401 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6402 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6403 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6404 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6405 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6406 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6407 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6408 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6409 | if (status < 0) |
| 6410 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6411 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6412 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6413 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6414 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6415 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6416 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6417 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6418 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6419 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6420 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6421 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6422 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6423 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6424 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6425 | out: |
| 6426 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6427 | return status; |
| 6428 | } |
| 6429 | |
| 6430 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6431 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6432 | struct nfs4_exception exception = { |
| 6433 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6434 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6435 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6436 | int err; |
| 6437 | |
| 6438 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6439 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6440 | if (err == -NFS4ERR_DENIED) |
| 6441 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6442 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6443 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6444 | } while (exception.retry); |
| 6445 | return err; |
| 6446 | } |
| 6447 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6448 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6449 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6450 | |
| 6451 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6452 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6453 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6454 | { |
| 6455 | int status = -ERESTARTSYS; |
| 6456 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6457 | |
| 6458 | while(!signalled()) { |
| 6459 | status = nfs4_proc_setlk(state, cmd, request); |
| 6460 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6461 | break; |
| 6462 | freezable_schedule_timeout_interruptible(timeout); |
| 6463 | timeout *= 2; |
| 6464 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6465 | status = -ERESTARTSYS; |
| 6466 | } |
| 6467 | return status; |
| 6468 | } |
| 6469 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6470 | #ifdef CONFIG_NFS_V4_1 |
| 6471 | struct nfs4_lock_waiter { |
| 6472 | struct task_struct *task; |
| 6473 | struct inode *inode; |
| 6474 | struct nfs_lowner *owner; |
| 6475 | bool notified; |
| 6476 | }; |
| 6477 | |
| 6478 | static int |
| 6479 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6480 | { |
| 6481 | int ret; |
| 6482 | struct cb_notify_lock_args *cbnl = key; |
| 6483 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6484 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6485 | *wowner = waiter->owner; |
| 6486 | |
| 6487 | /* Only wake if the callback was for the same owner */ |
| 6488 | if (lowner->clientid != wowner->clientid || |
| 6489 | lowner->id != wowner->id || |
| 6490 | lowner->s_dev != wowner->s_dev) |
| 6491 | return 0; |
| 6492 | |
| 6493 | /* Make sure it's for the right inode */ |
| 6494 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6495 | return 0; |
| 6496 | |
| 6497 | waiter->notified = true; |
| 6498 | |
| 6499 | /* override "private" so we can use default_wake_function */ |
| 6500 | wait->private = waiter->task; |
| 6501 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6502 | wait->private = waiter; |
| 6503 | return ret; |
| 6504 | } |
| 6505 | |
| 6506 | static int |
| 6507 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6508 | { |
| 6509 | int status = -ERESTARTSYS; |
| 6510 | unsigned long flags; |
| 6511 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6512 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6513 | struct nfs_client *clp = server->nfs_client; |
| 6514 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6515 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6516 | .id = lsp->ls_seqid.owner_id, |
| 6517 | .s_dev = server->s_dev }; |
| 6518 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6519 | .inode = state->inode, |
| 6520 | .owner = &owner, |
| 6521 | .notified = false }; |
| 6522 | wait_queue_t wait; |
| 6523 | |
| 6524 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6525 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6526 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6527 | |
| 6528 | init_wait(&wait); |
| 6529 | wait.private = &waiter; |
| 6530 | wait.func = nfs4_wake_lock_waiter; |
| 6531 | add_wait_queue(q, &wait); |
| 6532 | |
| 6533 | while(!signalled()) { |
| 6534 | status = nfs4_proc_setlk(state, cmd, request); |
| 6535 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6536 | break; |
| 6537 | |
| 6538 | status = -ERESTARTSYS; |
| 6539 | spin_lock_irqsave(&q->lock, flags); |
| 6540 | if (waiter.notified) { |
| 6541 | spin_unlock_irqrestore(&q->lock, flags); |
| 6542 | continue; |
| 6543 | } |
| 6544 | set_current_state(TASK_INTERRUPTIBLE); |
| 6545 | spin_unlock_irqrestore(&q->lock, flags); |
| 6546 | |
| 6547 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6548 | } |
| 6549 | |
| 6550 | finish_wait(q, &wait); |
| 6551 | return status; |
| 6552 | } |
| 6553 | #else /* !CONFIG_NFS_V4_1 */ |
| 6554 | static inline int |
| 6555 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6556 | { |
| 6557 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6558 | } |
| 6559 | #endif |
| 6560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6561 | static int |
| 6562 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6563 | { |
| 6564 | struct nfs_open_context *ctx; |
| 6565 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | int status; |
| 6567 | |
| 6568 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6569 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6570 | state = ctx->state; |
| 6571 | |
| 6572 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6573 | return -EINVAL; |
| 6574 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6575 | if (IS_GETLK(cmd)) { |
| 6576 | if (state != NULL) |
| 6577 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6578 | return 0; |
| 6579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6580 | |
| 6581 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6582 | return -EINVAL; |
| 6583 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6584 | if (request->fl_type == F_UNLCK) { |
| 6585 | if (state != NULL) |
| 6586 | return nfs4_proc_unlck(state, cmd, request); |
| 6587 | return 0; |
| 6588 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6589 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6590 | if (state == NULL) |
| 6591 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6592 | |
| 6593 | if ((request->fl_flags & FL_POSIX) && |
| 6594 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6595 | return -ENOLCK; |
| 6596 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6597 | /* |
| 6598 | * Don't rely on the VFS having checked the file open mode, |
| 6599 | * since it won't do this for flock() locks. |
| 6600 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6601 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6602 | case F_RDLCK: |
| 6603 | if (!(filp->f_mode & FMODE_READ)) |
| 6604 | return -EBADF; |
| 6605 | break; |
| 6606 | case F_WRLCK: |
| 6607 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6608 | return -EBADF; |
| 6609 | } |
| 6610 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6611 | status = nfs4_set_lock_state(state, request); |
| 6612 | if (status != 0) |
| 6613 | return status; |
| 6614 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6615 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6616 | } |
| 6617 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6618 | 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] | 6619 | { |
| 6620 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6621 | int err; |
| 6622 | |
| 6623 | err = nfs4_set_lock_state(state, fl); |
| 6624 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6625 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6626 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6627 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6628 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6629 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6630 | struct nfs_release_lockowner_data { |
| 6631 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6632 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6633 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6634 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6635 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6636 | }; |
| 6637 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6638 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6639 | { |
| 6640 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6641 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6642 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6643 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6644 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6645 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6649 | { |
| 6650 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6651 | struct nfs_server *server = data->server; |
| 6652 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6653 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6654 | |
| 6655 | switch (task->tk_status) { |
| 6656 | case 0: |
| 6657 | renew_lease(server, data->timestamp); |
| 6658 | break; |
| 6659 | case -NFS4ERR_STALE_CLIENTID: |
| 6660 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6661 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6662 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6663 | case -NFS4ERR_LEASE_MOVED: |
| 6664 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6665 | if (nfs4_async_handle_error(task, server, |
| 6666 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6667 | rpc_restart_call_prepare(task); |
| 6668 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6669 | } |
| 6670 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6671 | static void nfs4_release_lockowner_release(void *calldata) |
| 6672 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6673 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6674 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6675 | kfree(calldata); |
| 6676 | } |
| 6677 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6678 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6679 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6680 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6681 | .rpc_release = nfs4_release_lockowner_release, |
| 6682 | }; |
| 6683 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6684 | static void |
| 6685 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6686 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6687 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6688 | struct rpc_message msg = { |
| 6689 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6690 | }; |
| 6691 | |
| 6692 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6693 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6694 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6695 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6696 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6697 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6698 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6699 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6700 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6701 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6702 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6703 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6704 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6705 | msg.rpc_resp = &data->res; |
| 6706 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6707 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6708 | } |
| 6709 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6710 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6711 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6712 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6713 | struct dentry *unused, struct inode *inode, |
| 6714 | const char *key, const void *buf, |
| 6715 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6716 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6717 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6718 | } |
| 6719 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6720 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6721 | struct dentry *unused, struct inode *inode, |
| 6722 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6723 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6724 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6725 | } |
| 6726 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6727 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6728 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6729 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6730 | } |
| 6731 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6732 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6733 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6734 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6735 | struct dentry *unused, struct inode *inode, |
| 6736 | const char *key, const void *buf, |
| 6737 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6738 | { |
| 6739 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6740 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6741 | |
| 6742 | return -EOPNOTSUPP; |
| 6743 | } |
| 6744 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6745 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6746 | struct dentry *unused, struct inode *inode, |
| 6747 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6748 | { |
| 6749 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6750 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6751 | return -EOPNOTSUPP; |
| 6752 | } |
| 6753 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6754 | static ssize_t |
| 6755 | 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] | 6756 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6757 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6758 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6759 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6760 | len = security_inode_listsecurity(inode, list, list_len); |
| 6761 | if (list_len && len > list_len) |
| 6762 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6763 | } |
| 6764 | return len; |
| 6765 | } |
| 6766 | |
| 6767 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6768 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6769 | .get = nfs4_xattr_get_nfs4_label, |
| 6770 | .set = nfs4_xattr_set_nfs4_label, |
| 6771 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6772 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6773 | #else |
| 6774 | |
| 6775 | static ssize_t |
| 6776 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6777 | { |
| 6778 | return 0; |
| 6779 | } |
| 6780 | |
| 6781 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6782 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6783 | /* |
| 6784 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6785 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6786 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6787 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6788 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6789 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6790 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6791 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6792 | return; |
| 6793 | |
| 6794 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6795 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6796 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6797 | fattr->nlink = 2; |
| 6798 | } |
| 6799 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6800 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6801 | const struct qstr *name, |
| 6802 | struct nfs4_fs_locations *fs_locations, |
| 6803 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6804 | { |
| 6805 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6806 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6807 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6808 | }; |
| 6809 | struct nfs4_fs_locations_arg args = { |
| 6810 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6811 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6812 | .page = page, |
| 6813 | .bitmask = bitmask, |
| 6814 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6815 | struct nfs4_fs_locations_res res = { |
| 6816 | .fs_locations = fs_locations, |
| 6817 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6818 | struct rpc_message msg = { |
| 6819 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6820 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6821 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6822 | }; |
| 6823 | int status; |
| 6824 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6825 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6826 | |
| 6827 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6828 | * is not supported */ |
| 6829 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6830 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6831 | else |
| 6832 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6833 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6834 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6835 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6836 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6837 | 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] | 6838 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6839 | return status; |
| 6840 | } |
| 6841 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6842 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6843 | const struct qstr *name, |
| 6844 | struct nfs4_fs_locations *fs_locations, |
| 6845 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6846 | { |
| 6847 | struct nfs4_exception exception = { }; |
| 6848 | int err; |
| 6849 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6850 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6851 | fs_locations, page); |
| 6852 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6853 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6854 | &exception); |
| 6855 | } while (exception.retry); |
| 6856 | return err; |
| 6857 | } |
| 6858 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6859 | /* |
| 6860 | * This operation also signals the server that this client is |
| 6861 | * performing migration recovery. The server can stop returning |
| 6862 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6863 | * appended to this compound to identify the client ID which is |
| 6864 | * performing recovery. |
| 6865 | */ |
| 6866 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6867 | struct nfs4_fs_locations *locations, |
| 6868 | struct page *page, struct rpc_cred *cred) |
| 6869 | { |
| 6870 | struct nfs_server *server = NFS_SERVER(inode); |
| 6871 | struct rpc_clnt *clnt = server->client; |
| 6872 | u32 bitmask[2] = { |
| 6873 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6874 | }; |
| 6875 | struct nfs4_fs_locations_arg args = { |
| 6876 | .clientid = server->nfs_client->cl_clientid, |
| 6877 | .fh = NFS_FH(inode), |
| 6878 | .page = page, |
| 6879 | .bitmask = bitmask, |
| 6880 | .migration = 1, /* skip LOOKUP */ |
| 6881 | .renew = 1, /* append RENEW */ |
| 6882 | }; |
| 6883 | struct nfs4_fs_locations_res res = { |
| 6884 | .fs_locations = locations, |
| 6885 | .migration = 1, |
| 6886 | .renew = 1, |
| 6887 | }; |
| 6888 | struct rpc_message msg = { |
| 6889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6890 | .rpc_argp = &args, |
| 6891 | .rpc_resp = &res, |
| 6892 | .rpc_cred = cred, |
| 6893 | }; |
| 6894 | unsigned long now = jiffies; |
| 6895 | int status; |
| 6896 | |
| 6897 | nfs_fattr_init(&locations->fattr); |
| 6898 | locations->server = server; |
| 6899 | locations->nlocations = 0; |
| 6900 | |
| 6901 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6902 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6903 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6904 | &args.seq_args, &res.seq_res); |
| 6905 | if (status) |
| 6906 | return status; |
| 6907 | |
| 6908 | renew_lease(server, now); |
| 6909 | return 0; |
| 6910 | } |
| 6911 | |
| 6912 | #ifdef CONFIG_NFS_V4_1 |
| 6913 | |
| 6914 | /* |
| 6915 | * This operation also signals the server that this client is |
| 6916 | * performing migration recovery. The server can stop asserting |
| 6917 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6918 | * performing this operation is identified in the SEQUENCE |
| 6919 | * operation in this compound. |
| 6920 | * |
| 6921 | * When the client supports GETATTR(fs_locations_info), it can |
| 6922 | * be plumbed in here. |
| 6923 | */ |
| 6924 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6925 | struct nfs4_fs_locations *locations, |
| 6926 | struct page *page, struct rpc_cred *cred) |
| 6927 | { |
| 6928 | struct nfs_server *server = NFS_SERVER(inode); |
| 6929 | struct rpc_clnt *clnt = server->client; |
| 6930 | u32 bitmask[2] = { |
| 6931 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6932 | }; |
| 6933 | struct nfs4_fs_locations_arg args = { |
| 6934 | .fh = NFS_FH(inode), |
| 6935 | .page = page, |
| 6936 | .bitmask = bitmask, |
| 6937 | .migration = 1, /* skip LOOKUP */ |
| 6938 | }; |
| 6939 | struct nfs4_fs_locations_res res = { |
| 6940 | .fs_locations = locations, |
| 6941 | .migration = 1, |
| 6942 | }; |
| 6943 | struct rpc_message msg = { |
| 6944 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6945 | .rpc_argp = &args, |
| 6946 | .rpc_resp = &res, |
| 6947 | .rpc_cred = cred, |
| 6948 | }; |
| 6949 | int status; |
| 6950 | |
| 6951 | nfs_fattr_init(&locations->fattr); |
| 6952 | locations->server = server; |
| 6953 | locations->nlocations = 0; |
| 6954 | |
| 6955 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6956 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6957 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6958 | &args.seq_args, &res.seq_res); |
| 6959 | if (status == NFS4_OK && |
| 6960 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6961 | status = -NFS4ERR_LEASE_MOVED; |
| 6962 | return status; |
| 6963 | } |
| 6964 | |
| 6965 | #endif /* CONFIG_NFS_V4_1 */ |
| 6966 | |
| 6967 | /** |
| 6968 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6969 | * @inode: inode on FSID that is migrating |
| 6970 | * @locations: result of query |
| 6971 | * @page: buffer |
| 6972 | * @cred: credential to use for this operation |
| 6973 | * |
| 6974 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6975 | * operation failed, or a negative errno if a local error occurred. |
| 6976 | * |
| 6977 | * On success, "locations" is filled in, but if the server has |
| 6978 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6979 | * asserted. |
| 6980 | * |
| 6981 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6982 | * from this client that require migration recovery. |
| 6983 | */ |
| 6984 | int nfs4_proc_get_locations(struct inode *inode, |
| 6985 | struct nfs4_fs_locations *locations, |
| 6986 | struct page *page, struct rpc_cred *cred) |
| 6987 | { |
| 6988 | struct nfs_server *server = NFS_SERVER(inode); |
| 6989 | struct nfs_client *clp = server->nfs_client; |
| 6990 | const struct nfs4_mig_recovery_ops *ops = |
| 6991 | clp->cl_mvops->mig_recovery_ops; |
| 6992 | struct nfs4_exception exception = { }; |
| 6993 | int status; |
| 6994 | |
| 6995 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6996 | (unsigned long long)server->fsid.major, |
| 6997 | (unsigned long long)server->fsid.minor, |
| 6998 | clp->cl_hostname); |
| 6999 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7000 | |
| 7001 | do { |
| 7002 | status = ops->get_locations(inode, locations, page, cred); |
| 7003 | if (status != -NFS4ERR_DELAY) |
| 7004 | break; |
| 7005 | nfs4_handle_exception(server, status, &exception); |
| 7006 | } while (exception.retry); |
| 7007 | return status; |
| 7008 | } |
| 7009 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7010 | /* |
| 7011 | * This operation also signals the server that this client is |
| 7012 | * performing "lease moved" recovery. The server can stop |
| 7013 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7014 | * is appended to this compound to identify the client ID which is |
| 7015 | * performing recovery. |
| 7016 | */ |
| 7017 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7018 | { |
| 7019 | struct nfs_server *server = NFS_SERVER(inode); |
| 7020 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7021 | struct rpc_clnt *clnt = server->client; |
| 7022 | struct nfs4_fsid_present_arg args = { |
| 7023 | .fh = NFS_FH(inode), |
| 7024 | .clientid = clp->cl_clientid, |
| 7025 | .renew = 1, /* append RENEW */ |
| 7026 | }; |
| 7027 | struct nfs4_fsid_present_res res = { |
| 7028 | .renew = 1, |
| 7029 | }; |
| 7030 | struct rpc_message msg = { |
| 7031 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7032 | .rpc_argp = &args, |
| 7033 | .rpc_resp = &res, |
| 7034 | .rpc_cred = cred, |
| 7035 | }; |
| 7036 | unsigned long now = jiffies; |
| 7037 | int status; |
| 7038 | |
| 7039 | res.fh = nfs_alloc_fhandle(); |
| 7040 | if (res.fh == NULL) |
| 7041 | return -ENOMEM; |
| 7042 | |
| 7043 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7044 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7045 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7046 | &args.seq_args, &res.seq_res); |
| 7047 | nfs_free_fhandle(res.fh); |
| 7048 | if (status) |
| 7049 | return status; |
| 7050 | |
| 7051 | do_renew_lease(clp, now); |
| 7052 | return 0; |
| 7053 | } |
| 7054 | |
| 7055 | #ifdef CONFIG_NFS_V4_1 |
| 7056 | |
| 7057 | /* |
| 7058 | * This operation also signals the server that this client is |
| 7059 | * performing "lease moved" recovery. The server can stop asserting |
| 7060 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7061 | * this operation is identified in the SEQUENCE operation in this |
| 7062 | * compound. |
| 7063 | */ |
| 7064 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7065 | { |
| 7066 | struct nfs_server *server = NFS_SERVER(inode); |
| 7067 | struct rpc_clnt *clnt = server->client; |
| 7068 | struct nfs4_fsid_present_arg args = { |
| 7069 | .fh = NFS_FH(inode), |
| 7070 | }; |
| 7071 | struct nfs4_fsid_present_res res = { |
| 7072 | }; |
| 7073 | struct rpc_message msg = { |
| 7074 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7075 | .rpc_argp = &args, |
| 7076 | .rpc_resp = &res, |
| 7077 | .rpc_cred = cred, |
| 7078 | }; |
| 7079 | int status; |
| 7080 | |
| 7081 | res.fh = nfs_alloc_fhandle(); |
| 7082 | if (res.fh == NULL) |
| 7083 | return -ENOMEM; |
| 7084 | |
| 7085 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7086 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7087 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7088 | &args.seq_args, &res.seq_res); |
| 7089 | nfs_free_fhandle(res.fh); |
| 7090 | if (status == NFS4_OK && |
| 7091 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7092 | status = -NFS4ERR_LEASE_MOVED; |
| 7093 | return status; |
| 7094 | } |
| 7095 | |
| 7096 | #endif /* CONFIG_NFS_V4_1 */ |
| 7097 | |
| 7098 | /** |
| 7099 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7100 | * @inode: inode on FSID to check |
| 7101 | * @cred: credential to use for this operation |
| 7102 | * |
| 7103 | * Server indicates whether the FSID is present, moved, or not |
| 7104 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7105 | * condition for this client ID. |
| 7106 | * |
| 7107 | * Returns NFS4_OK if the FSID is present on this server, |
| 7108 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7109 | * NFS4ERR code if some error occurred on the server, or a |
| 7110 | * negative errno if a local failure occurred. |
| 7111 | */ |
| 7112 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7113 | { |
| 7114 | struct nfs_server *server = NFS_SERVER(inode); |
| 7115 | struct nfs_client *clp = server->nfs_client; |
| 7116 | const struct nfs4_mig_recovery_ops *ops = |
| 7117 | clp->cl_mvops->mig_recovery_ops; |
| 7118 | struct nfs4_exception exception = { }; |
| 7119 | int status; |
| 7120 | |
| 7121 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7122 | (unsigned long long)server->fsid.major, |
| 7123 | (unsigned long long)server->fsid.minor, |
| 7124 | clp->cl_hostname); |
| 7125 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7126 | |
| 7127 | do { |
| 7128 | status = ops->fsid_present(inode, cred); |
| 7129 | if (status != -NFS4ERR_DELAY) |
| 7130 | break; |
| 7131 | nfs4_handle_exception(server, status, &exception); |
| 7132 | } while (exception.retry); |
| 7133 | return status; |
| 7134 | } |
| 7135 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7136 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7137 | * If 'use_integrity' is true and the state managment nfs_client |
| 7138 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7139 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7140 | * Considerations sections. Otherwise, just use the user cred with the |
| 7141 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7142 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7143 | 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] | 7144 | { |
| 7145 | int status; |
| 7146 | struct nfs4_secinfo_arg args = { |
| 7147 | .dir_fh = NFS_FH(dir), |
| 7148 | .name = name, |
| 7149 | }; |
| 7150 | struct nfs4_secinfo_res res = { |
| 7151 | .flavors = flavors, |
| 7152 | }; |
| 7153 | struct rpc_message msg = { |
| 7154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7155 | .rpc_argp = &args, |
| 7156 | .rpc_resp = &res, |
| 7157 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7158 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7159 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7160 | |
| 7161 | if (use_integrity) { |
| 7162 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7163 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7164 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7165 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7166 | |
| 7167 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7168 | |
| 7169 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7170 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7171 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7172 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7173 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7174 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7175 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7176 | if (cred) |
| 7177 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7178 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7179 | return status; |
| 7180 | } |
| 7181 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7182 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7183 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7184 | { |
| 7185 | struct nfs4_exception exception = { }; |
| 7186 | int err; |
| 7187 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7188 | err = -NFS4ERR_WRONGSEC; |
| 7189 | |
| 7190 | /* try to use integrity protection with machine cred */ |
| 7191 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7192 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7193 | |
| 7194 | /* |
| 7195 | * if unable to use integrity protection, or SECINFO with |
| 7196 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7197 | * disallowed by spec, but exists in deployed servers) use |
| 7198 | * the current filesystem's rpc_client and the user cred. |
| 7199 | */ |
| 7200 | if (err == -NFS4ERR_WRONGSEC) |
| 7201 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7202 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7203 | trace_nfs4_secinfo(dir, name, err); |
| 7204 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7205 | &exception); |
| 7206 | } while (exception.retry); |
| 7207 | return err; |
| 7208 | } |
| 7209 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7210 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7211 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7212 | * Check the exchange flags returned by the server for invalid flags, having |
| 7213 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7214 | * DS flags set. |
| 7215 | */ |
| 7216 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7217 | { |
| 7218 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7219 | goto out_inval; |
| 7220 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7221 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7222 | goto out_inval; |
| 7223 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7224 | goto out_inval; |
| 7225 | return NFS_OK; |
| 7226 | out_inval: |
| 7227 | return -NFS4ERR_INVAL; |
| 7228 | } |
| 7229 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7230 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7231 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7232 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7233 | { |
| 7234 | if (a->server_scope_sz == b->server_scope_sz && |
| 7235 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7236 | return true; |
| 7237 | |
| 7238 | return false; |
| 7239 | } |
| 7240 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7241 | static void |
| 7242 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7243 | { |
| 7244 | } |
| 7245 | |
| 7246 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7247 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7248 | }; |
| 7249 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7250 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7251 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7252 | * |
| 7253 | * The 4.1 client currently uses the same TCP connection for the |
| 7254 | * fore and backchannel. |
| 7255 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7256 | static |
| 7257 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7258 | struct rpc_xprt *xprt, |
| 7259 | struct nfs_client *clp, |
| 7260 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7261 | { |
| 7262 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7263 | struct nfs41_bind_conn_to_session_args args = { |
| 7264 | .client = clp, |
| 7265 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7266 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7267 | struct nfs41_bind_conn_to_session_res res; |
| 7268 | struct rpc_message msg = { |
| 7269 | .rpc_proc = |
| 7270 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7271 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7272 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7273 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7274 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7275 | struct rpc_task_setup task_setup_data = { |
| 7276 | .rpc_client = clnt, |
| 7277 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7278 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7279 | .rpc_message = &msg, |
| 7280 | .flags = RPC_TASK_TIMEOUT, |
| 7281 | }; |
| 7282 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7283 | |
| 7284 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7285 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7286 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7287 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7288 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7289 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7290 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7291 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7292 | args.dir = NFS4_CDFC4_FORE; |
| 7293 | |
| 7294 | task = rpc_run_task(&task_setup_data); |
| 7295 | if (!IS_ERR(task)) { |
| 7296 | status = task->tk_status; |
| 7297 | rpc_put_task(task); |
| 7298 | } else |
| 7299 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7300 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7301 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7302 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7303 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7304 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7305 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7306 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7307 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7308 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7309 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7310 | __func__); |
| 7311 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7312 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7313 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7314 | 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] | 7315 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7316 | __func__); |
| 7317 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7318 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7319 | } |
| 7320 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7321 | out: |
| 7322 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7323 | return status; |
| 7324 | } |
| 7325 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7326 | struct rpc_bind_conn_calldata { |
| 7327 | struct nfs_client *clp; |
| 7328 | struct rpc_cred *cred; |
| 7329 | }; |
| 7330 | |
| 7331 | static int |
| 7332 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7333 | struct rpc_xprt *xprt, |
| 7334 | void *calldata) |
| 7335 | { |
| 7336 | struct rpc_bind_conn_calldata *p = calldata; |
| 7337 | |
| 7338 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7339 | } |
| 7340 | |
| 7341 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7342 | { |
| 7343 | struct rpc_bind_conn_calldata data = { |
| 7344 | .clp = clp, |
| 7345 | .cred = cred, |
| 7346 | }; |
| 7347 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7348 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7349 | } |
| 7350 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7351 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7352 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7353 | * 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] | 7354 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7355 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7356 | .how = SP4_MACH_CRED, |
| 7357 | .enforce.u.words = { |
| 7358 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7359 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7360 | 1 << (OP_CREATE_SESSION - 32) | |
| 7361 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7362 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7363 | }, |
| 7364 | .allow.u.words = { |
| 7365 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7366 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7367 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7368 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7369 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7370 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7371 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7372 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7373 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7374 | 1 << (OP_FREE_STATEID - 32) | |
| 7375 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7376 | } |
| 7377 | }; |
| 7378 | |
| 7379 | /* |
| 7380 | * Select the state protection mode for client `clp' given the server results |
| 7381 | * from exchange_id in `sp'. |
| 7382 | * |
| 7383 | * Returns 0 on success, negative errno otherwise. |
| 7384 | */ |
| 7385 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7386 | struct nfs41_state_protection *sp) |
| 7387 | { |
| 7388 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7389 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7390 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7391 | 1 << (OP_CREATE_SESSION - 32) | |
| 7392 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7393 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7394 | }; |
| 7395 | unsigned int i; |
| 7396 | |
| 7397 | if (sp->how == SP4_MACH_CRED) { |
| 7398 | /* Print state protect result */ |
| 7399 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7400 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7401 | if (test_bit(i, sp->enforce.u.longs)) |
| 7402 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7403 | if (test_bit(i, sp->allow.u.longs)) |
| 7404 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7405 | } |
| 7406 | |
| 7407 | /* make sure nothing is on enforce list that isn't supported */ |
| 7408 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7409 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7410 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7411 | return -EINVAL; |
| 7412 | } |
| 7413 | } |
| 7414 | |
| 7415 | /* |
| 7416 | * Minimal mode - state operations are allowed to use machine |
| 7417 | * credential. Note this already happens by default, so the |
| 7418 | * client doesn't have to do anything more than the negotiation. |
| 7419 | * |
| 7420 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7421 | * we're already using the machine cred for exchange_id |
| 7422 | * and will never use a different cred. |
| 7423 | */ |
| 7424 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7425 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7426 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7427 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7428 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7429 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7430 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7431 | } else { |
| 7432 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7433 | return -EINVAL; |
| 7434 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7435 | |
| 7436 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7437 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7438 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7439 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7440 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7441 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7442 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7443 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7444 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7445 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7446 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7447 | &clp->cl_sp4_flags); |
| 7448 | } |
| 7449 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7450 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7451 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7452 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7453 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7454 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7455 | |
| 7456 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7457 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7458 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7459 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7460 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7461 | |
| 7462 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7463 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7464 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7465 | } |
| 7466 | |
| 7467 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7468 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7469 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7470 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7471 | } |
| 7472 | |
| 7473 | return 0; |
| 7474 | } |
| 7475 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7476 | struct nfs41_exchange_id_data { |
| 7477 | struct nfs41_exchange_id_res res; |
| 7478 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7479 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7480 | int rpc_status; |
| 7481 | }; |
| 7482 | |
| 7483 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7484 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7485 | struct nfs41_exchange_id_data *cdata = |
| 7486 | (struct nfs41_exchange_id_data *)data; |
| 7487 | struct nfs_client *clp = cdata->args.client; |
| 7488 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7489 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7490 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7491 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7492 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7493 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7494 | |
| 7495 | if (cdata->xprt && status == 0) { |
| 7496 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7497 | cdata->xprt); |
| 7498 | goto out; |
| 7499 | } |
| 7500 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7501 | if (status == 0) |
| 7502 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7503 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7504 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7505 | clp->cl_clientid = cdata->res.clientid; |
| 7506 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7507 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7508 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7509 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7510 | &clp->cl_session->session_state); |
| 7511 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7512 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7513 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7514 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7515 | clp->cl_serverowner = cdata->res.server_owner; |
| 7516 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7517 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7518 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7519 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7520 | clp->cl_implid = cdata->res.impl_id; |
| 7521 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7522 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7523 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7524 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7525 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7526 | dprintk("%s: server_scope mismatch detected\n", |
| 7527 | __func__); |
| 7528 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7529 | kfree(clp->cl_serverscope); |
| 7530 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7531 | } |
| 7532 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7533 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7534 | clp->cl_serverscope = cdata->res.server_scope; |
| 7535 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7536 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7537 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7538 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7539 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7540 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7541 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7542 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7543 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7544 | } |
| 7545 | |
| 7546 | static void nfs4_exchange_id_release(void *data) |
| 7547 | { |
| 7548 | struct nfs41_exchange_id_data *cdata = |
| 7549 | (struct nfs41_exchange_id_data *)data; |
| 7550 | |
| 7551 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7552 | if (cdata->xprt) { |
| 7553 | xprt_put(cdata->xprt); |
| 7554 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7555 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7556 | kfree(cdata->res.impl_id); |
| 7557 | kfree(cdata->res.server_scope); |
| 7558 | kfree(cdata->res.server_owner); |
| 7559 | kfree(cdata); |
| 7560 | } |
| 7561 | |
| 7562 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7563 | .rpc_call_done = nfs4_exchange_id_done, |
| 7564 | .rpc_release = nfs4_exchange_id_release, |
| 7565 | }; |
| 7566 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7567 | /* |
| 7568 | * _nfs4_proc_exchange_id() |
| 7569 | * |
| 7570 | * Wrapper for EXCHANGE_ID operation. |
| 7571 | */ |
| 7572 | 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] | 7573 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7574 | { |
| 7575 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7576 | struct rpc_message msg = { |
| 7577 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7578 | .rpc_cred = cred, |
| 7579 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7580 | struct rpc_task_setup task_setup_data = { |
| 7581 | .rpc_client = clp->cl_rpcclient, |
| 7582 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7583 | .rpc_message = &msg, |
| 7584 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7585 | }; |
| 7586 | struct nfs41_exchange_id_data *calldata; |
| 7587 | struct rpc_task *task; |
| 7588 | int status = -EIO; |
| 7589 | |
| 7590 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7591 | goto out; |
| 7592 | |
| 7593 | status = -ENOMEM; |
| 7594 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7595 | if (!calldata) |
| 7596 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7597 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7598 | if (!xprt) |
| 7599 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7600 | |
| 7601 | status = nfs4_init_uniform_client_string(clp); |
| 7602 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7603 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7604 | |
| 7605 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7606 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7607 | clp->cl_owner_id); |
| 7608 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7609 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7610 | GFP_NOFS); |
| 7611 | status = -ENOMEM; |
| 7612 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7613 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7614 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7615 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7616 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7617 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7618 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7619 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7620 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7621 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7622 | goto out_server_scope; |
| 7623 | |
| 7624 | switch (sp4_how) { |
| 7625 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7626 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7627 | break; |
| 7628 | |
| 7629 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7630 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7631 | break; |
| 7632 | |
| 7633 | default: |
| 7634 | /* unsupported! */ |
| 7635 | WARN_ON_ONCE(1); |
| 7636 | status = -EINVAL; |
| 7637 | goto out_impl_id; |
| 7638 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7639 | if (xprt) { |
| 7640 | calldata->xprt = xprt; |
| 7641 | task_setup_data.rpc_xprt = xprt; |
| 7642 | task_setup_data.flags = |
| 7643 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7644 | calldata->args.verifier = &clp->cl_confirm; |
| 7645 | } else { |
| 7646 | calldata->args.verifier = &verifier; |
| 7647 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7648 | calldata->args.client = clp; |
| 7649 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7650 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7651 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7652 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7653 | #else |
| 7654 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7655 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7656 | #endif |
| 7657 | msg.rpc_argp = &calldata->args; |
| 7658 | msg.rpc_resp = &calldata->res; |
| 7659 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7660 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7661 | task = rpc_run_task(&task_setup_data); |
| 7662 | if (IS_ERR(task)) { |
| 7663 | status = PTR_ERR(task); |
| 7664 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7665 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7666 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7667 | if (!xprt) { |
| 7668 | status = rpc_wait_for_completion_task(task); |
| 7669 | if (!status) |
| 7670 | status = calldata->rpc_status; |
| 7671 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7672 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7673 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7674 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7675 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7676 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7677 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7678 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7679 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7680 | clp->cl_implid->date.seconds, |
| 7681 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7682 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7683 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7684 | |
| 7685 | out_impl_id: |
| 7686 | kfree(calldata->res.impl_id); |
| 7687 | out_server_scope: |
| 7688 | kfree(calldata->res.server_scope); |
| 7689 | out_server_owner: |
| 7690 | kfree(calldata->res.server_owner); |
| 7691 | out_calldata: |
| 7692 | kfree(calldata); |
| 7693 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7694 | } |
| 7695 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7696 | /* |
| 7697 | * nfs4_proc_exchange_id() |
| 7698 | * |
| 7699 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7700 | * |
| 7701 | * Since the clientid has expired, all compounds using sessions |
| 7702 | * associated with the stale clientid will be returning |
| 7703 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7704 | * be in some phase of session reset. |
| 7705 | * |
| 7706 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7707 | */ |
| 7708 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7709 | { |
| 7710 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7711 | int status; |
| 7712 | |
| 7713 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7714 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7715 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7716 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7717 | if (!status) |
| 7718 | return 0; |
| 7719 | } |
| 7720 | |
| 7721 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7722 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7723 | } |
| 7724 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7725 | /** |
| 7726 | * nfs4_test_session_trunk |
| 7727 | * |
| 7728 | * This is an add_xprt_test() test function called from |
| 7729 | * rpc_clnt_setup_test_and_add_xprt. |
| 7730 | * |
| 7731 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7732 | * and is dereferrenced in nfs4_exchange_id_release |
| 7733 | * |
| 7734 | * Upon success, add the new transport to the rpc_clnt |
| 7735 | * |
| 7736 | * @clnt: struct rpc_clnt to get new transport |
| 7737 | * @xprt: the rpc_xprt to test |
| 7738 | * @data: call data for _nfs4_proc_exchange_id. |
| 7739 | */ |
| 7740 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7741 | void *data) |
| 7742 | { |
| 7743 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7744 | u32 sp4_how; |
| 7745 | |
| 7746 | dprintk("--> %s try %s\n", __func__, |
| 7747 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7748 | |
| 7749 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7750 | |
| 7751 | /* Test connection for session trunking. Async exchange_id call */ |
| 7752 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7753 | } |
| 7754 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7755 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7756 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7757 | struct rpc_cred *cred) |
| 7758 | { |
| 7759 | struct rpc_message msg = { |
| 7760 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7761 | .rpc_argp = clp, |
| 7762 | .rpc_cred = cred, |
| 7763 | }; |
| 7764 | int status; |
| 7765 | |
| 7766 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7767 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7768 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7769 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7770 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7771 | return status; |
| 7772 | } |
| 7773 | |
| 7774 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7775 | struct rpc_cred *cred) |
| 7776 | { |
| 7777 | unsigned int loop; |
| 7778 | int ret; |
| 7779 | |
| 7780 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7781 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7782 | switch (ret) { |
| 7783 | case -NFS4ERR_DELAY: |
| 7784 | case -NFS4ERR_CLIENTID_BUSY: |
| 7785 | ssleep(1); |
| 7786 | break; |
| 7787 | default: |
| 7788 | return ret; |
| 7789 | } |
| 7790 | } |
| 7791 | return 0; |
| 7792 | } |
| 7793 | |
| 7794 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7795 | { |
| 7796 | struct rpc_cred *cred; |
| 7797 | int ret = 0; |
| 7798 | |
| 7799 | if (clp->cl_mvops->minor_version < 1) |
| 7800 | goto out; |
| 7801 | if (clp->cl_exchange_flags == 0) |
| 7802 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7803 | if (clp->cl_preserve_clid) |
| 7804 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7805 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7806 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7807 | if (cred) |
| 7808 | put_rpccred(cred); |
| 7809 | switch (ret) { |
| 7810 | case 0: |
| 7811 | case -NFS4ERR_STALE_CLIENTID: |
| 7812 | clp->cl_exchange_flags = 0; |
| 7813 | } |
| 7814 | out: |
| 7815 | return ret; |
| 7816 | } |
| 7817 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7818 | struct nfs4_get_lease_time_data { |
| 7819 | struct nfs4_get_lease_time_args *args; |
| 7820 | struct nfs4_get_lease_time_res *res; |
| 7821 | struct nfs_client *clp; |
| 7822 | }; |
| 7823 | |
| 7824 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7825 | void *calldata) |
| 7826 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7827 | struct nfs4_get_lease_time_data *data = |
| 7828 | (struct nfs4_get_lease_time_data *)calldata; |
| 7829 | |
| 7830 | dprintk("--> %s\n", __func__); |
| 7831 | /* just setup sequence, do not trigger session recovery |
| 7832 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7833 | nfs41_setup_sequence(data->clp->cl_session, |
| 7834 | &data->args->la_seq_args, |
| 7835 | &data->res->lr_seq_res, |
| 7836 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7837 | dprintk("<-- %s\n", __func__); |
| 7838 | } |
| 7839 | |
| 7840 | /* |
| 7841 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7842 | * from sequence operation or clientid errors. |
| 7843 | */ |
| 7844 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7845 | { |
| 7846 | struct nfs4_get_lease_time_data *data = |
| 7847 | (struct nfs4_get_lease_time_data *)calldata; |
| 7848 | |
| 7849 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7850 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7851 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7852 | switch (task->tk_status) { |
| 7853 | case -NFS4ERR_DELAY: |
| 7854 | case -NFS4ERR_GRACE: |
| 7855 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7856 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7857 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7858 | /* fall through */ |
| 7859 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7860 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7861 | return; |
| 7862 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7863 | dprintk("<-- %s\n", __func__); |
| 7864 | } |
| 7865 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7866 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7867 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7868 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7869 | }; |
| 7870 | |
| 7871 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7872 | { |
| 7873 | struct rpc_task *task; |
| 7874 | struct nfs4_get_lease_time_args args; |
| 7875 | struct nfs4_get_lease_time_res res = { |
| 7876 | .lr_fsinfo = fsinfo, |
| 7877 | }; |
| 7878 | struct nfs4_get_lease_time_data data = { |
| 7879 | .args = &args, |
| 7880 | .res = &res, |
| 7881 | .clp = clp, |
| 7882 | }; |
| 7883 | struct rpc_message msg = { |
| 7884 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7885 | .rpc_argp = &args, |
| 7886 | .rpc_resp = &res, |
| 7887 | }; |
| 7888 | struct rpc_task_setup task_setup = { |
| 7889 | .rpc_client = clp->cl_rpcclient, |
| 7890 | .rpc_message = &msg, |
| 7891 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7892 | .callback_data = &data, |
| 7893 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7894 | }; |
| 7895 | int status; |
| 7896 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7897 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7898 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7899 | dprintk("--> %s\n", __func__); |
| 7900 | task = rpc_run_task(&task_setup); |
| 7901 | |
| 7902 | if (IS_ERR(task)) |
| 7903 | status = PTR_ERR(task); |
| 7904 | else { |
| 7905 | status = task->tk_status; |
| 7906 | rpc_put_task(task); |
| 7907 | } |
| 7908 | dprintk("<-- %s return %d\n", __func__, status); |
| 7909 | |
| 7910 | return status; |
| 7911 | } |
| 7912 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7913 | /* |
| 7914 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7915 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7916 | * use them. |
| 7917 | * |
| 7918 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7919 | * always set csa_cachethis to FALSE because the current implementation |
| 7920 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7921 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7922 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7923 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7924 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7925 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7926 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7927 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7928 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7929 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7930 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7931 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7932 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7933 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7934 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7935 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7936 | |
| 7937 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7938 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7939 | __func__, |
| 7940 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7941 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7942 | |
| 7943 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7944 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7945 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7946 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7947 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7948 | 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] | 7949 | |
| 7950 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7951 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7952 | __func__, |
| 7953 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7954 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7955 | args->bc_attrs.max_reqs); |
| 7956 | } |
| 7957 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7958 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7959 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7960 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7961 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7962 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7963 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7964 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7965 | return -EINVAL; |
| 7966 | /* |
| 7967 | * Our requested max_ops is the minimum we need; we're not |
| 7968 | * prepared to break up compounds into smaller pieces than that. |
| 7969 | * So, no point even trying to continue if the server won't |
| 7970 | * cooperate: |
| 7971 | */ |
| 7972 | if (rcvd->max_ops < sent->max_ops) |
| 7973 | return -EINVAL; |
| 7974 | if (rcvd->max_reqs == 0) |
| 7975 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7976 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7977 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7978 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7979 | } |
| 7980 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7981 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7982 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7983 | { |
| 7984 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7985 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7986 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7987 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7988 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7989 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7990 | return -EINVAL; |
| 7991 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7992 | return -EINVAL; |
| 7993 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7994 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7995 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7996 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7997 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7998 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7999 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8000 | return 0; |
| 8001 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8002 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8003 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8004 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8005 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8006 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8007 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8008 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8009 | if (ret) |
| 8010 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8011 | return nfs4_verify_back_channel_attrs(args, res); |
| 8012 | } |
| 8013 | |
| 8014 | static void nfs4_update_session(struct nfs4_session *session, |
| 8015 | struct nfs41_create_session_res *res) |
| 8016 | { |
| 8017 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8018 | /* Mark client id and session as being confirmed */ |
| 8019 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8020 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8021 | session->flags = res->flags; |
| 8022 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8023 | if (res->flags & SESSION4_BACK_CHAN) |
| 8024 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8025 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8026 | } |
| 8027 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8028 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8029 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8030 | { |
| 8031 | struct nfs4_session *session = clp->cl_session; |
| 8032 | struct nfs41_create_session_args args = { |
| 8033 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8034 | .clientid = clp->cl_clientid, |
| 8035 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8036 | .cb_program = NFS4_CALLBACK, |
| 8037 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8038 | struct nfs41_create_session_res res; |
| 8039 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8040 | struct rpc_message msg = { |
| 8041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8042 | .rpc_argp = &args, |
| 8043 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8044 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8045 | }; |
| 8046 | int status; |
| 8047 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8048 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8049 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8050 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8051 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8052 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8053 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8054 | switch (status) { |
| 8055 | case -NFS4ERR_STALE_CLIENTID: |
| 8056 | case -NFS4ERR_DELAY: |
| 8057 | case -ETIMEDOUT: |
| 8058 | case -EACCES: |
| 8059 | case -EAGAIN: |
| 8060 | goto out; |
| 8061 | }; |
| 8062 | |
| 8063 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8064 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8065 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8066 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8067 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8068 | if (status) |
| 8069 | goto out; |
| 8070 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8071 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8072 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8073 | return status; |
| 8074 | } |
| 8075 | |
| 8076 | /* |
| 8077 | * Issues a CREATE_SESSION operation to the server. |
| 8078 | * It is the responsibility of the caller to verify the session is |
| 8079 | * expired before calling this routine. |
| 8080 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8081 | 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] | 8082 | { |
| 8083 | int status; |
| 8084 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8085 | struct nfs4_session *session = clp->cl_session; |
| 8086 | |
| 8087 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8088 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8089 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8090 | if (status) |
| 8091 | goto out; |
| 8092 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8093 | /* Init or reset the session slot tables */ |
| 8094 | status = nfs4_setup_session_slot_tables(session); |
| 8095 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8096 | if (status) |
| 8097 | goto out; |
| 8098 | |
| 8099 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8100 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8101 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8102 | out: |
| 8103 | dprintk("<-- %s\n", __func__); |
| 8104 | return status; |
| 8105 | } |
| 8106 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8107 | /* |
| 8108 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8109 | * The caller must serialize access to this routine. |
| 8110 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8111 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8112 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8113 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8114 | struct rpc_message msg = { |
| 8115 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8116 | .rpc_argp = session, |
| 8117 | .rpc_cred = cred, |
| 8118 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8119 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8120 | |
| 8121 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8122 | |
| 8123 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8124 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8125 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8126 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8127 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8128 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8129 | |
| 8130 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8131 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8132 | "Session has been destroyed regardless...\n", status); |
| 8133 | |
| 8134 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8135 | return status; |
| 8136 | } |
| 8137 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8138 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8139 | * Renew the cl_session lease. |
| 8140 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8141 | struct nfs4_sequence_data { |
| 8142 | struct nfs_client *clp; |
| 8143 | struct nfs4_sequence_args args; |
| 8144 | struct nfs4_sequence_res res; |
| 8145 | }; |
| 8146 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8147 | static void nfs41_sequence_release(void *data) |
| 8148 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8149 | struct nfs4_sequence_data *calldata = data; |
| 8150 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8151 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8152 | if (atomic_read(&clp->cl_count) > 1) |
| 8153 | nfs4_schedule_state_renewal(clp); |
| 8154 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8155 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8156 | } |
| 8157 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8158 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8159 | { |
| 8160 | switch(task->tk_status) { |
| 8161 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8162 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8163 | return -EAGAIN; |
| 8164 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8165 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8166 | } |
| 8167 | return 0; |
| 8168 | } |
| 8169 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8170 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8171 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8172 | struct nfs4_sequence_data *calldata = data; |
| 8173 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8174 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8175 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8176 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8177 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8178 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8179 | if (task->tk_status < 0) { |
| 8180 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8181 | if (atomic_read(&clp->cl_count) == 1) |
| 8182 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8183 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8184 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8185 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8186 | return; |
| 8187 | } |
| 8188 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8189 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8190 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8191 | dprintk("<-- %s\n", __func__); |
| 8192 | } |
| 8193 | |
| 8194 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8195 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8196 | struct nfs4_sequence_data *calldata = data; |
| 8197 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8198 | struct nfs4_sequence_args *args; |
| 8199 | struct nfs4_sequence_res *res; |
| 8200 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8201 | args = task->tk_msg.rpc_argp; |
| 8202 | res = task->tk_msg.rpc_resp; |
| 8203 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8204 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8208 | .rpc_call_done = nfs41_sequence_call_done, |
| 8209 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8210 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8211 | }; |
| 8212 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8213 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8214 | struct rpc_cred *cred, |
| 8215 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8216 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8217 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8218 | struct rpc_message msg = { |
| 8219 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8220 | .rpc_cred = cred, |
| 8221 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8222 | struct rpc_task_setup task_setup_data = { |
| 8223 | .rpc_client = clp->cl_rpcclient, |
| 8224 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8225 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8226 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8227 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8228 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8229 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8230 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8231 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8232 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8233 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8234 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8235 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8236 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8237 | if (is_privileged) |
| 8238 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8239 | msg.rpc_argp = &calldata->args; |
| 8240 | msg.rpc_resp = &calldata->res; |
| 8241 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8242 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8243 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8244 | return rpc_run_task(&task_setup_data); |
| 8245 | } |
| 8246 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8247 | 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] | 8248 | { |
| 8249 | struct rpc_task *task; |
| 8250 | int ret = 0; |
| 8251 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8252 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8253 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8254 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8255 | if (IS_ERR(task)) |
| 8256 | ret = PTR_ERR(task); |
| 8257 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8258 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8259 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8260 | return ret; |
| 8261 | } |
| 8262 | |
| 8263 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8264 | { |
| 8265 | struct rpc_task *task; |
| 8266 | int ret; |
| 8267 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8268 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8269 | if (IS_ERR(task)) { |
| 8270 | ret = PTR_ERR(task); |
| 8271 | goto out; |
| 8272 | } |
| 8273 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8274 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8275 | ret = task->tk_status; |
| 8276 | rpc_put_task(task); |
| 8277 | out: |
| 8278 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8279 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8280 | } |
| 8281 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8282 | struct nfs4_reclaim_complete_data { |
| 8283 | struct nfs_client *clp; |
| 8284 | struct nfs41_reclaim_complete_args arg; |
| 8285 | struct nfs41_reclaim_complete_res res; |
| 8286 | }; |
| 8287 | |
| 8288 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8289 | { |
| 8290 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8291 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8292 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8293 | &calldata->arg.seq_args, |
| 8294 | &calldata->res.seq_res, |
| 8295 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8296 | } |
| 8297 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8298 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8299 | { |
| 8300 | switch(task->tk_status) { |
| 8301 | case 0: |
| 8302 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8303 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8304 | break; |
| 8305 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8306 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8307 | /* fall through */ |
| 8308 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8309 | return -EAGAIN; |
| 8310 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8311 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8312 | } |
| 8313 | return 0; |
| 8314 | } |
| 8315 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8316 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8317 | { |
| 8318 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8319 | struct nfs_client *clp = calldata->clp; |
| 8320 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8321 | |
| 8322 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8323 | if (!nfs41_sequence_done(task, res)) |
| 8324 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8325 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8326 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8327 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8328 | rpc_restart_call_prepare(task); |
| 8329 | return; |
| 8330 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8331 | dprintk("<-- %s\n", __func__); |
| 8332 | } |
| 8333 | |
| 8334 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8335 | { |
| 8336 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8337 | |
| 8338 | kfree(calldata); |
| 8339 | } |
| 8340 | |
| 8341 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8342 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8343 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8344 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8345 | }; |
| 8346 | |
| 8347 | /* |
| 8348 | * Issue a global reclaim complete. |
| 8349 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8350 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8351 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8352 | { |
| 8353 | struct nfs4_reclaim_complete_data *calldata; |
| 8354 | struct rpc_task *task; |
| 8355 | struct rpc_message msg = { |
| 8356 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8357 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8358 | }; |
| 8359 | struct rpc_task_setup task_setup_data = { |
| 8360 | .rpc_client = clp->cl_rpcclient, |
| 8361 | .rpc_message = &msg, |
| 8362 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8363 | .flags = RPC_TASK_ASYNC, |
| 8364 | }; |
| 8365 | int status = -ENOMEM; |
| 8366 | |
| 8367 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8368 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8369 | if (calldata == NULL) |
| 8370 | goto out; |
| 8371 | calldata->clp = clp; |
| 8372 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8373 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8374 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8375 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8376 | msg.rpc_argp = &calldata->arg; |
| 8377 | msg.rpc_resp = &calldata->res; |
| 8378 | task_setup_data.callback_data = calldata; |
| 8379 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8380 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8381 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8382 | goto out; |
| 8383 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8384 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8385 | if (status == 0) |
| 8386 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8387 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8388 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8389 | out: |
| 8390 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8391 | return status; |
| 8392 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8393 | |
| 8394 | static void |
| 8395 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8396 | { |
| 8397 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8398 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Anna Schumaker | 172d9de | 2015-05-14 10:56:10 -0400 | [diff] [blame] | 8399 | struct nfs4_session *session = nfs4_get_session(server->nfs_client); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8400 | |
| 8401 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8402 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8403 | &lgp->res.seq_res, task); |
| 8404 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8405 | } |
| 8406 | |
| 8407 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8408 | { |
| 8409 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8410 | |
| 8411 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8412 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8413 | dprintk("<-- %s\n", __func__); |
| 8414 | } |
| 8415 | |
| 8416 | static int |
| 8417 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8418 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8419 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8420 | struct inode *inode = lgp->args.inode; |
| 8421 | struct nfs_server *server = NFS_SERVER(inode); |
| 8422 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8423 | int nfs4err = task->tk_status; |
| 8424 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8425 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8426 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8427 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8428 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8429 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8430 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8431 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8432 | |
| 8433 | /* |
| 8434 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8435 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8436 | * retry go inband. |
| 8437 | */ |
| 8438 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8439 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8440 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8441 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8442 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8443 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8444 | */ |
| 8445 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8446 | status = -EOVERFLOW; |
| 8447 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8448 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8449 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8450 | * (or clients) writing to the same RAID stripe except when |
| 8451 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8452 | * |
| 8453 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8454 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8455 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8456 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8457 | if (lgp->args.minlength == 0) { |
| 8458 | status = -EOVERFLOW; |
| 8459 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8460 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8461 | status = -EBUSY; |
| 8462 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8463 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8464 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8465 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8466 | case -NFS4ERR_DELEG_REVOKED: |
| 8467 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8468 | case -NFS4ERR_EXPIRED: |
| 8469 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8470 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8471 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8472 | lo = NFS_I(inode)->layout; |
| 8473 | /* If the open stateid was bad, then recover it. */ |
| 8474 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8475 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8476 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8477 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8478 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8479 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8480 | break; |
| 8481 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8482 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8483 | /* |
| 8484 | * Mark the bad layout state as invalid, then retry |
| 8485 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8486 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8487 | spin_unlock(&inode->i_lock); |
| 8488 | pnfs_free_lseg_list(&head); |
| 8489 | status = -EAGAIN; |
| 8490 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8491 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8492 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8493 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8494 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8495 | if (!status) { |
| 8496 | if (exception->retry) |
| 8497 | status = -EAGAIN; |
| 8498 | else |
| 8499 | status = err; |
| 8500 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8501 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8502 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8503 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8504 | } |
| 8505 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8506 | static size_t max_response_pages(struct nfs_server *server) |
| 8507 | { |
| 8508 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8509 | return nfs_page_array_len(0, max_resp_sz); |
| 8510 | } |
| 8511 | |
| 8512 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8513 | { |
| 8514 | int i; |
| 8515 | |
| 8516 | if (!pages) |
| 8517 | return; |
| 8518 | |
| 8519 | for (i = 0; i < size; i++) { |
| 8520 | if (!pages[i]) |
| 8521 | break; |
| 8522 | __free_page(pages[i]); |
| 8523 | } |
| 8524 | kfree(pages); |
| 8525 | } |
| 8526 | |
| 8527 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8528 | { |
| 8529 | struct page **pages; |
| 8530 | int i; |
| 8531 | |
| 8532 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8533 | if (!pages) { |
| 8534 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8535 | return NULL; |
| 8536 | } |
| 8537 | |
| 8538 | for (i = 0; i < size; i++) { |
| 8539 | pages[i] = alloc_page(gfp_flags); |
| 8540 | if (!pages[i]) { |
| 8541 | dprintk("%s: failed to allocate page\n", __func__); |
| 8542 | nfs4_free_pages(pages, size); |
| 8543 | return NULL; |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | return pages; |
| 8548 | } |
| 8549 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8550 | static void nfs4_layoutget_release(void *calldata) |
| 8551 | { |
| 8552 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8553 | struct inode *inode = lgp->args.inode; |
| 8554 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8555 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8556 | |
| 8557 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8558 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8559 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8560 | put_nfs_open_context(lgp->args.ctx); |
| 8561 | kfree(calldata); |
| 8562 | dprintk("<-- %s\n", __func__); |
| 8563 | } |
| 8564 | |
| 8565 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8566 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8567 | .rpc_call_done = nfs4_layoutget_done, |
| 8568 | .rpc_release = nfs4_layoutget_release, |
| 8569 | }; |
| 8570 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8571 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8572 | 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] | 8573 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8574 | struct inode *inode = lgp->args.inode; |
| 8575 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8576 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8577 | struct rpc_task *task; |
| 8578 | struct rpc_message msg = { |
| 8579 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8580 | .rpc_argp = &lgp->args, |
| 8581 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8582 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8583 | }; |
| 8584 | struct rpc_task_setup task_setup_data = { |
| 8585 | .rpc_client = server->client, |
| 8586 | .rpc_message = &msg, |
| 8587 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8588 | .callback_data = lgp, |
| 8589 | .flags = RPC_TASK_ASYNC, |
| 8590 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8591 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8592 | struct nfs4_exception exception = { |
| 8593 | .inode = inode, |
| 8594 | .timeout = *timeout, |
| 8595 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8596 | int status = 0; |
| 8597 | |
| 8598 | dprintk("--> %s\n", __func__); |
| 8599 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8600 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8601 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8602 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8603 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8604 | if (!lgp->args.layout.pages) { |
| 8605 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8606 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8607 | } |
| 8608 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8609 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8610 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8611 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8612 | 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] | 8613 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8614 | task = rpc_run_task(&task_setup_data); |
| 8615 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8616 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8617 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8618 | if (status == 0) { |
| 8619 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8620 | *timeout = exception.timeout; |
| 8621 | } |
| 8622 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8623 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8624 | &lgp->args.range, |
| 8625 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8626 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8627 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8628 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8629 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8630 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8631 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8632 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8633 | rpc_put_task(task); |
| 8634 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8635 | if (status) |
| 8636 | return ERR_PTR(status); |
| 8637 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8638 | } |
| 8639 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8640 | static void |
| 8641 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8642 | { |
| 8643 | struct nfs4_layoutreturn *lrp = calldata; |
| 8644 | |
| 8645 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8646 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8647 | &lrp->args.seq_args, |
| 8648 | &lrp->res.seq_res, |
| 8649 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8650 | } |
| 8651 | |
| 8652 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8653 | { |
| 8654 | struct nfs4_layoutreturn *lrp = calldata; |
| 8655 | struct nfs_server *server; |
| 8656 | |
| 8657 | dprintk("--> %s\n", __func__); |
| 8658 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8659 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8660 | return; |
| 8661 | |
| 8662 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8663 | switch (task->tk_status) { |
| 8664 | default: |
| 8665 | task->tk_status = 0; |
| 8666 | case 0: |
| 8667 | break; |
| 8668 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8669 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8670 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8671 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8672 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8673 | return; |
| 8674 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8675 | dprintk("<-- %s\n", __func__); |
| 8676 | } |
| 8677 | |
| 8678 | static void nfs4_layoutreturn_release(void *calldata) |
| 8679 | { |
| 8680 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8681 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8682 | |
| 8683 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8684 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8685 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8686 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8687 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8688 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8689 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8690 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8691 | kfree(calldata); |
| 8692 | dprintk("<-- %s\n", __func__); |
| 8693 | } |
| 8694 | |
| 8695 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8696 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8697 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8698 | .rpc_release = nfs4_layoutreturn_release, |
| 8699 | }; |
| 8700 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8701 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8702 | { |
| 8703 | struct rpc_task *task; |
| 8704 | struct rpc_message msg = { |
| 8705 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8706 | .rpc_argp = &lrp->args, |
| 8707 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8708 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8709 | }; |
| 8710 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8711 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8712 | .rpc_message = &msg, |
| 8713 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8714 | .callback_data = lrp, |
| 8715 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8716 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8717 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8718 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8719 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8720 | &task_setup_data.rpc_client, &msg); |
| 8721 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8722 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8723 | if (!sync) { |
| 8724 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8725 | if (!lrp->inode) { |
| 8726 | nfs4_layoutreturn_release(lrp); |
| 8727 | return -EAGAIN; |
| 8728 | } |
| 8729 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8730 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8731 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8732 | task = rpc_run_task(&task_setup_data); |
| 8733 | if (IS_ERR(task)) |
| 8734 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8735 | if (sync) |
| 8736 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8737 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8738 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8739 | rpc_put_task(task); |
| 8740 | return status; |
| 8741 | } |
| 8742 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8743 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8744 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8745 | struct pnfs_device *pdev, |
| 8746 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8747 | { |
| 8748 | struct nfs4_getdeviceinfo_args args = { |
| 8749 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8750 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8751 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8752 | }; |
| 8753 | struct nfs4_getdeviceinfo_res res = { |
| 8754 | .pdev = pdev, |
| 8755 | }; |
| 8756 | struct rpc_message msg = { |
| 8757 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8758 | .rpc_argp = &args, |
| 8759 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8760 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8761 | }; |
| 8762 | int status; |
| 8763 | |
| 8764 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8765 | 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] | 8766 | if (res.notification & ~args.notify_types) |
| 8767 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8768 | if (res.notification != args.notify_types) |
| 8769 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8770 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8771 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8772 | |
| 8773 | return status; |
| 8774 | } |
| 8775 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8776 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8777 | struct pnfs_device *pdev, |
| 8778 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8779 | { |
| 8780 | struct nfs4_exception exception = { }; |
| 8781 | int err; |
| 8782 | |
| 8783 | do { |
| 8784 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8785 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8786 | &exception); |
| 8787 | } while (exception.retry); |
| 8788 | return err; |
| 8789 | } |
| 8790 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8791 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8792 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8793 | { |
| 8794 | struct nfs4_layoutcommit_data *data = calldata; |
| 8795 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Anna Schumaker | 172d9de | 2015-05-14 10:56:10 -0400 | [diff] [blame] | 8796 | struct nfs4_session *session = nfs4_get_session(server->nfs_client); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8797 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8798 | nfs41_setup_sequence(session, |
| 8799 | &data->args.seq_args, |
| 8800 | &data->res.seq_res, |
| 8801 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8802 | } |
| 8803 | |
| 8804 | static void |
| 8805 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8806 | { |
| 8807 | struct nfs4_layoutcommit_data *data = calldata; |
| 8808 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8809 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8810 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8811 | return; |
| 8812 | |
| 8813 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8814 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8815 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8816 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8817 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8818 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8819 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8820 | break; |
| 8821 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8822 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8823 | rpc_restart_call_prepare(task); |
| 8824 | return; |
| 8825 | } |
| 8826 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8827 | } |
| 8828 | |
| 8829 | static void nfs4_layoutcommit_release(void *calldata) |
| 8830 | { |
| 8831 | struct nfs4_layoutcommit_data *data = calldata; |
| 8832 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8833 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8834 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8835 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8836 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8837 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8838 | kfree(data); |
| 8839 | } |
| 8840 | |
| 8841 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8842 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8843 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8844 | .rpc_release = nfs4_layoutcommit_release, |
| 8845 | }; |
| 8846 | |
| 8847 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8848 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8849 | { |
| 8850 | struct rpc_message msg = { |
| 8851 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8852 | .rpc_argp = &data->args, |
| 8853 | .rpc_resp = &data->res, |
| 8854 | .rpc_cred = data->cred, |
| 8855 | }; |
| 8856 | struct rpc_task_setup task_setup_data = { |
| 8857 | .task = &data->task, |
| 8858 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8859 | .rpc_message = &msg, |
| 8860 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8861 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8862 | }; |
| 8863 | struct rpc_task *task; |
| 8864 | int status = 0; |
| 8865 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8866 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8867 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8868 | data->args.lastbytewritten, |
| 8869 | data->args.inode->i_ino); |
| 8870 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8871 | if (!sync) { |
| 8872 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8873 | if (data->inode == NULL) { |
| 8874 | nfs4_layoutcommit_release(data); |
| 8875 | return -EAGAIN; |
| 8876 | } |
| 8877 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8878 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8879 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8880 | task = rpc_run_task(&task_setup_data); |
| 8881 | if (IS_ERR(task)) |
| 8882 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8883 | if (sync) |
| 8884 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8885 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8886 | dprintk("%s: status %d\n", __func__, status); |
| 8887 | rpc_put_task(task); |
| 8888 | return status; |
| 8889 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8890 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8891 | /** |
| 8892 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8893 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8894 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8895 | static int |
| 8896 | _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] | 8897 | struct nfs_fsinfo *info, |
| 8898 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8899 | { |
| 8900 | struct nfs41_secinfo_no_name_args args = { |
| 8901 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8902 | }; |
| 8903 | struct nfs4_secinfo_res res = { |
| 8904 | .flavors = flavors, |
| 8905 | }; |
| 8906 | struct rpc_message msg = { |
| 8907 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8908 | .rpc_argp = &args, |
| 8909 | .rpc_resp = &res, |
| 8910 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8911 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8912 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8913 | int status; |
| 8914 | |
| 8915 | if (use_integrity) { |
| 8916 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8917 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8918 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8919 | } |
| 8920 | |
| 8921 | dprintk("--> %s\n", __func__); |
| 8922 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8923 | &res.seq_res, 0); |
| 8924 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8925 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8926 | if (cred) |
| 8927 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8928 | |
| 8929 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8930 | } |
| 8931 | |
| 8932 | static int |
| 8933 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8934 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8935 | { |
| 8936 | struct nfs4_exception exception = { }; |
| 8937 | int err; |
| 8938 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8939 | /* first try using integrity protection */ |
| 8940 | err = -NFS4ERR_WRONGSEC; |
| 8941 | |
| 8942 | /* try to use integrity protection with machine cred */ |
| 8943 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8944 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8945 | flavors, true); |
| 8946 | |
| 8947 | /* |
| 8948 | * if unable to use integrity protection, or SECINFO with |
| 8949 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8950 | * disallowed by spec, but exists in deployed servers) use |
| 8951 | * the current filesystem's rpc_client and the user cred. |
| 8952 | */ |
| 8953 | if (err == -NFS4ERR_WRONGSEC) |
| 8954 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8955 | flavors, false); |
| 8956 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8957 | switch (err) { |
| 8958 | case 0: |
| 8959 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8960 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8961 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8962 | default: |
| 8963 | err = nfs4_handle_exception(server, err, &exception); |
| 8964 | } |
| 8965 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8966 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8967 | return err; |
| 8968 | } |
| 8969 | |
| 8970 | static int |
| 8971 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8972 | struct nfs_fsinfo *info) |
| 8973 | { |
| 8974 | int err; |
| 8975 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8976 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8977 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8978 | struct nfs4_secinfo4 *secinfo; |
| 8979 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8980 | |
| 8981 | page = alloc_page(GFP_KERNEL); |
| 8982 | if (!page) { |
| 8983 | err = -ENOMEM; |
| 8984 | goto out; |
| 8985 | } |
| 8986 | |
| 8987 | flavors = page_address(page); |
| 8988 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8989 | |
| 8990 | /* |
| 8991 | * Fall back on "guess and check" method if |
| 8992 | * the server doesn't support SECINFO_NO_NAME |
| 8993 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8994 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8995 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8996 | goto out_freepage; |
| 8997 | } |
| 8998 | if (err) |
| 8999 | goto out_freepage; |
| 9000 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9001 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9002 | secinfo = &flavors->flavors[i]; |
| 9003 | |
| 9004 | switch (secinfo->flavor) { |
| 9005 | case RPC_AUTH_NULL: |
| 9006 | case RPC_AUTH_UNIX: |
| 9007 | case RPC_AUTH_GSS: |
| 9008 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9009 | &secinfo->flavor_info); |
| 9010 | break; |
| 9011 | default: |
| 9012 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9013 | break; |
| 9014 | } |
| 9015 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9016 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9017 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9018 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9019 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9020 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9021 | info, flavor); |
| 9022 | if (!err) |
| 9023 | break; |
| 9024 | } |
| 9025 | } |
| 9026 | |
| 9027 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9028 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9029 | |
| 9030 | out_freepage: |
| 9031 | put_page(page); |
| 9032 | if (err == -EACCES) |
| 9033 | return -EPERM; |
| 9034 | out: |
| 9035 | return err; |
| 9036 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9037 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9038 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9039 | nfs4_stateid *stateid, |
| 9040 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9041 | { |
| 9042 | int status; |
| 9043 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9044 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9045 | }; |
| 9046 | struct nfs41_test_stateid_res res; |
| 9047 | struct rpc_message msg = { |
| 9048 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9049 | .rpc_argp = &args, |
| 9050 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9051 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9052 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9053 | struct rpc_clnt *rpc_client = server->client; |
| 9054 | |
| 9055 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9056 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9057 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9058 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9059 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9060 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9061 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9062 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9063 | if (status != NFS_OK) { |
| 9064 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9065 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9066 | } |
| 9067 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9068 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9069 | } |
| 9070 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9071 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9072 | int err, struct nfs4_exception *exception) |
| 9073 | { |
| 9074 | exception->retry = 0; |
| 9075 | switch(err) { |
| 9076 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9077 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9078 | nfs4_handle_exception(server, err, exception); |
| 9079 | break; |
| 9080 | case -NFS4ERR_BADSESSION: |
| 9081 | case -NFS4ERR_BADSLOT: |
| 9082 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9083 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9084 | case -NFS4ERR_DEADSESSION: |
| 9085 | nfs4_do_handle_exception(server, err, exception); |
| 9086 | } |
| 9087 | } |
| 9088 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9089 | /** |
| 9090 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9091 | * |
| 9092 | * @server: server / transport on which to perform the operation |
| 9093 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9094 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9095 | * |
| 9096 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9097 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9098 | * failed or the state ID is not currently valid. |
| 9099 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9100 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9101 | nfs4_stateid *stateid, |
| 9102 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9103 | { |
| 9104 | struct nfs4_exception exception = { }; |
| 9105 | int err; |
| 9106 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9107 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9108 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9109 | } while (exception.retry); |
| 9110 | return err; |
| 9111 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9112 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9113 | struct nfs_free_stateid_data { |
| 9114 | struct nfs_server *server; |
| 9115 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9116 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9117 | }; |
| 9118 | |
| 9119 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9120 | { |
| 9121 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 172d9de | 2015-05-14 10:56:10 -0400 | [diff] [blame] | 9122 | nfs41_setup_sequence(nfs4_get_session(data->server->nfs_client), |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9123 | &data->args.seq_args, |
| 9124 | &data->res.seq_res, |
| 9125 | task); |
| 9126 | } |
| 9127 | |
| 9128 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9129 | { |
| 9130 | struct nfs_free_stateid_data *data = calldata; |
| 9131 | |
| 9132 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9133 | |
| 9134 | switch (task->tk_status) { |
| 9135 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9136 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9137 | rpc_restart_call_prepare(task); |
| 9138 | } |
| 9139 | } |
| 9140 | |
| 9141 | static void nfs41_free_stateid_release(void *calldata) |
| 9142 | { |
| 9143 | kfree(calldata); |
| 9144 | } |
| 9145 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9146 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9147 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9148 | .rpc_call_done = nfs41_free_stateid_done, |
| 9149 | .rpc_release = nfs41_free_stateid_release, |
| 9150 | }; |
| 9151 | |
| 9152 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9153 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9154 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9155 | bool privileged) |
| 9156 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9157 | struct rpc_message msg = { |
| 9158 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9159 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9160 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9161 | struct rpc_task_setup task_setup = { |
| 9162 | .rpc_client = server->client, |
| 9163 | .rpc_message = &msg, |
| 9164 | .callback_ops = &nfs41_free_stateid_ops, |
| 9165 | .flags = RPC_TASK_ASYNC, |
| 9166 | }; |
| 9167 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9168 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9169 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9170 | &task_setup.rpc_client, &msg); |
| 9171 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9172 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9173 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9174 | if (!data) |
| 9175 | return ERR_PTR(-ENOMEM); |
| 9176 | data->server = server; |
| 9177 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9178 | |
| 9179 | task_setup.callback_data = data; |
| 9180 | |
| 9181 | msg.rpc_argp = &data->args; |
| 9182 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9183 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9184 | if (privileged) |
| 9185 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9186 | |
| 9187 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9188 | } |
| 9189 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9190 | /** |
| 9191 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9192 | * |
| 9193 | * @server: server / transport on which to perform the operation |
| 9194 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9195 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9196 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9197 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9198 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9199 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9200 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9201 | const nfs4_stateid *stateid, |
| 9202 | struct rpc_cred *cred, |
| 9203 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9204 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9205 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9206 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9207 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9208 | if (IS_ERR(task)) |
| 9209 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9210 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9211 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9212 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9213 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9214 | static void |
| 9215 | 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] | 9216 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9217 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9218 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9219 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9220 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9221 | } |
| 9222 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9223 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9224 | const nfs4_stateid *s2) |
| 9225 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9226 | if (s1->type != s2->type) |
| 9227 | return false; |
| 9228 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9229 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9230 | return false; |
| 9231 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9232 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9233 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9234 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9235 | return true; |
| 9236 | |
| 9237 | return false; |
| 9238 | } |
| 9239 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9240 | #endif /* CONFIG_NFS_V4_1 */ |
| 9241 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9242 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9243 | const nfs4_stateid *s2) |
| 9244 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9245 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9246 | } |
| 9247 | |
| 9248 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9249 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9250 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9251 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9252 | .recover_open = nfs4_open_reclaim, |
| 9253 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9254 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9255 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9256 | }; |
| 9257 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9258 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9259 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9260 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9261 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9262 | .recover_open = nfs4_open_reclaim, |
| 9263 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9264 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9265 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9266 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9267 | }; |
| 9268 | #endif /* CONFIG_NFS_V4_1 */ |
| 9269 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9270 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9271 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9272 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9273 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9274 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9275 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9276 | }; |
| 9277 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9278 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9279 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9280 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9281 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9282 | .recover_open = nfs41_open_expired, |
| 9283 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9284 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9285 | }; |
| 9286 | #endif /* CONFIG_NFS_V4_1 */ |
| 9287 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9288 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9289 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9290 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9291 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9292 | }; |
| 9293 | |
| 9294 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9295 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9296 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9297 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9298 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9299 | }; |
| 9300 | #endif |
| 9301 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9302 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9303 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9304 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9305 | }; |
| 9306 | |
| 9307 | #if defined(CONFIG_NFS_V4_1) |
| 9308 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9309 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9310 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9311 | }; |
| 9312 | #endif /* CONFIG_NFS_V4_1 */ |
| 9313 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9314 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9315 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9316 | .init_caps = NFS_CAP_READDIRPLUS |
| 9317 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9318 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9319 | .init_client = nfs40_init_client, |
| 9320 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9321 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9322 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9323 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9324 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9325 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9326 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9327 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9328 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9329 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9330 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9331 | }; |
| 9332 | |
| 9333 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9334 | static struct nfs_seqid * |
| 9335 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9336 | { |
| 9337 | return NULL; |
| 9338 | } |
| 9339 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9340 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9341 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9342 | .init_caps = NFS_CAP_READDIRPLUS |
| 9343 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9344 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9345 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9346 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9347 | .init_client = nfs41_init_client, |
| 9348 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9349 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9350 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9351 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9352 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9353 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9354 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9355 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9356 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9357 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9358 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9359 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9360 | }; |
| 9361 | #endif |
| 9362 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9363 | #if defined(CONFIG_NFS_V4_2) |
| 9364 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9365 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9366 | .init_caps = NFS_CAP_READDIRPLUS |
| 9367 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9368 | | NFS_CAP_POSIX_LOCK |
| 9369 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9370 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9371 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9372 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9373 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9374 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9375 | | NFS_CAP_LAYOUTSTATS |
| 9376 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9377 | .init_client = nfs41_init_client, |
| 9378 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9379 | .match_stateid = nfs41_match_stateid, |
| 9380 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9381 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9382 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9383 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9384 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9385 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9386 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9387 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9388 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9389 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9390 | }; |
| 9391 | #endif |
| 9392 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9393 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9394 | [0] = &nfs_v4_0_minor_ops, |
| 9395 | #if defined(CONFIG_NFS_V4_1) |
| 9396 | [1] = &nfs_v4_1_minor_ops, |
| 9397 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9398 | #if defined(CONFIG_NFS_V4_2) |
| 9399 | [2] = &nfs_v4_2_minor_ops, |
| 9400 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9401 | }; |
| 9402 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9403 | 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] | 9404 | { |
| 9405 | ssize_t error, error2; |
| 9406 | |
| 9407 | error = generic_listxattr(dentry, list, size); |
| 9408 | if (error < 0) |
| 9409 | return error; |
| 9410 | if (list) { |
| 9411 | list += error; |
| 9412 | size -= error; |
| 9413 | } |
| 9414 | |
| 9415 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9416 | if (error2 < 0) |
| 9417 | return error2; |
| 9418 | return error + error2; |
| 9419 | } |
| 9420 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9421 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9422 | .create = nfs_create, |
| 9423 | .lookup = nfs_lookup, |
| 9424 | .atomic_open = nfs_atomic_open, |
| 9425 | .link = nfs_link, |
| 9426 | .unlink = nfs_unlink, |
| 9427 | .symlink = nfs_symlink, |
| 9428 | .mkdir = nfs_mkdir, |
| 9429 | .rmdir = nfs_rmdir, |
| 9430 | .mknod = nfs_mknod, |
| 9431 | .rename = nfs_rename, |
| 9432 | .permission = nfs_permission, |
| 9433 | .getattr = nfs_getattr, |
| 9434 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9435 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9436 | }; |
| 9437 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9438 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9439 | .permission = nfs_permission, |
| 9440 | .getattr = nfs_getattr, |
| 9441 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9442 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9443 | }; |
| 9444 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9445 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9446 | .version = 4, /* protocol version */ |
| 9447 | .dentry_ops = &nfs4_dentry_operations, |
| 9448 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9449 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9450 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9451 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9452 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9453 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9454 | .getattr = nfs4_proc_getattr, |
| 9455 | .setattr = nfs4_proc_setattr, |
| 9456 | .lookup = nfs4_proc_lookup, |
| 9457 | .access = nfs4_proc_access, |
| 9458 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9459 | .create = nfs4_proc_create, |
| 9460 | .remove = nfs4_proc_remove, |
| 9461 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9462 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9463 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9464 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9465 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9466 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9467 | .link = nfs4_proc_link, |
| 9468 | .symlink = nfs4_proc_symlink, |
| 9469 | .mkdir = nfs4_proc_mkdir, |
| 9470 | .rmdir = nfs4_proc_remove, |
| 9471 | .readdir = nfs4_proc_readdir, |
| 9472 | .mknod = nfs4_proc_mknod, |
| 9473 | .statfs = nfs4_proc_statfs, |
| 9474 | .fsinfo = nfs4_proc_fsinfo, |
| 9475 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9476 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9477 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9478 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9479 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9480 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9481 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9482 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9483 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9484 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9485 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9486 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9487 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9488 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9489 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9490 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9491 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9492 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9493 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9494 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9495 | .create_server = nfs4_create_server, |
| 9496 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9497 | }; |
| 9498 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9499 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9500 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9501 | .list = nfs4_xattr_list_nfs4_acl, |
| 9502 | .get = nfs4_xattr_get_nfs4_acl, |
| 9503 | .set = nfs4_xattr_set_nfs4_acl, |
| 9504 | }; |
| 9505 | |
| 9506 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9507 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9508 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9509 | &nfs4_xattr_nfs4_label_handler, |
| 9510 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9511 | NULL |
| 9512 | }; |
| 9513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9514 | /* |
| 9515 | * Local variables: |
| 9516 | * c-basic-offset: 8 |
| 9517 | * End: |
| 9518 | */ |